In my code I am displaying time on an OLED via bluetooth from an app I've created on MIT app inventor. While I'm displaying the strings of time I am using code to search for an Up Gesture from the 'Sparkfun APDS9660 Gesture Sensor'. Once I do an up gesture I would like to clear the display and show the string "camera". I would like it to stay in the 'camera' function (in code) until I do a down gesture to return to showing 'time' function
My suggestion. Comments that I hope is enough for you to implement it in your own program.
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 be somewhere in loop().
// Include a check for if cameraMode == false in your 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();
}
Daniel_Quintana:
I'm trying to use a 'while loop' to repeat the code and then a 'break' to exit the code.
Don't use WHILE and then you won't need BREAK
Just let loop() look after the iteration and use a simple IF to determine when something needs to happen. Have a look at the demo Several Things at a Time
Thank you for your reply Robin2 however I am still confused on how I would keep the camera function looping until I gesture down. I'm guessing you mean the loop will look a little like this.
How would I keep the camera function repeating(looking for a right or left gesture to control pins 12 and 13) while looking for a down gesture that will go back to time function. Also the interrupt is for the gesture sensor, will the sensor still work if its in camera mode and not the void loop?
Thank your for your reply Delta_G. What you are saying makes sense and works for the simplicity of my code (for now). But later I would like to expand, my train of thought would be like how a smart watch has many apps. If you press one button it goes into Alarms, one button goes into Games and maybe another goes into a Camera, and the last would go to home which would be displaying Time. This is why I was trying to get the code to stay in one function as if they were apps on a smart watch. Maybe I'm still thinking about this wrong? Thank you for your time.
void Time(){
while (BT.available()){ //Check if there is an available byte to read
char c = BT.read(); //Conduct a serial read
state += c;
}
if (state.startsWith(""))
{
display.clearDisplay();
Serial.println(state);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print(state);
display.display();
state = "";
}
}
As you can see have have some serial print commands to help debug but the serial monitor shows--------------------------------
SparkFun APDS-9960 - GestureTest
APDS-9960 initialization complete
Gesture sensor is now running
DownUP
Camera
DownUP
Camera
DownUP
Camera
DownUP
ect.
Im I doing something wrong?
Daniel_Quintana:
So I think the loop(and interrupt routine) would look like this if I do what your saying.
Post the whole program in one piece - it is much easier to make sense of it that way. If it is too long (I hope not) then add the .ino file as an attachment.
What is the ISR supposed to do and why are you detaching it? Normally ISRs are started in setup() and run continuously, though there are exceptions.