How to Repeat a Function until specified Action (Arduino IDE)


in code displaying time on oled via bluetooth app i've created on mit app inventor. while i'm displaying strings of time using code search gesture 'sparkfun apds9660 gesture sensor'. once gesture clear display , show string "camera". stay in 'camera' function (in code) until down gesture return showing 'time' function
code: [select]
void handlegesture() {
  if ( apds.isgestureavailable() ) {
     
      if(dir_up)
      {
        serial.println("up");
        serial.println("camera");
         display.settextsize(1);
  display.settextcolor(white);
  display.setcursor(0,20);
  display.println("camera");
  display.display();
        q = 0;
        while(q == 0)
        {
          if (dir_right)
          {
             digitalwrite(13, high); 
  delay(1000);             
  digitalwrite(13, low);   
  delay(1000);
          }
       
        if (dir_left)
        {
           digitalwrite(12, high); 
  delay(1000);             
  digitalwrite(12, low);   
  delay(1000);
        }
        if (dir_down)
        {
          break;
        }
        }
     
       
     
    }
}
}


i'm trying use 'while loop' repeat code , 'break' exit code. if knows better solutions please comment.

thanks reply's

my suggestion. comments hope enough implement in own program.

code: [select]
void handlegesture() {
  if ( apds.isgestureavailable() ) {

    if (dir_up)
    {
      cameramode = true;  //cameramode declared global
    }

    if (dir_down)
    {
      camermode = false;
    }

    if (dir_right)
    {
      digitalwrite(13, high);
      delay(1000);
      digitalwrite(13, low);
      delay(1000);
    }

    if (dir_left)
    {
      digitalwrite(12, high);
      delay(1000);
      digitalwrite(12, low);
      delay(1000);
    }
  }
}

// following block should somewhere in loop().
// include check if cameramode == false in time routine
if (camermode = true)
{
  serial.println("up");
  serial.println("camera");
  display.settextsize(1);
  display.settextcolor(white);
  display.setcursor(0, 20);
  display.println("camera");
  display.display();
}


Arduino Forum > Using Arduino > Programming Questions > How to Repeat a Function until specified Action (Arduino IDE)


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts