Hey Guys, I was under the impression everything goes on from within the loop() function, but i've seen code where a guy is detecting button presses and rotary encoders and i can't see any relation to the functions he's using inside of loop().
if it possible to detect button presses outside of loop()?
oh ok, im only new at this game so I was under the impression it would only run code in loop() over and over again. is there anything i should be reading that shows me otherwise?
I was under the impression it would only run code in loop() over and over again.
The loop function is called over and over. Don't you see examples, though, where calls to digitalRead(), analogRead(), digitalWrite(), analogWrite(), etc. are called?
You can define functions that you call from loop(). Those functions can call other functions, like digitalRead(), analogRead(), digitalWrite(), analogWrite(), etc., or other functions that you define, that call digitalRead(), analogRead(), digitalWrite(), analogWrite(), etc.
is there anything i should be reading that shows me otherwise?
Anything that progresses beyond the "See Spot Run" level of project.
Without seeing the code, all we're doing here is wasting time guessing. So if you'd like a better answer of how it's done, then you need to show us the actual code you saw, wherever it was or is.
I was under the impression everything goes on from within the loop() function, but i've seen code where a guy is detecting button presses and rotary encoders and i can't see any relation to the functions he's using inside of loop().
yeah ive been calling functions ive make up from outside of loop, but for them to run they need to be referenced back into loop() somehow dont they?
KirAsh4 mention about "interrupts".
Yes, this can be done by "interrupts".
There is alot of code there but in the code for the loop, I cannot see any reference to the display menu() function.
here is the loop()
void loop() {
 ledStatus();
 populateData();
 displayData();
 runServer();
 if (!sound && !motionUp && !motionDn) autoBrightness();
 if (sound) ledColor(0,0,b_level);
 log();
 if (motionUp || motionDn) ledColor(r_level,0,0);Â
}
and here is the display menu()
void displayMenu() {
 int selected = 3;
Â
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("Turn the knob to");
 lcd.setCursor(0,1);
 lcd.print("select an option");
 // display options
 while (!buttonR.pressed()) {
  selected += readEncoder();
  if (selected<0) selected=3;
  if (selected>3) selected=0;
  if (moved) {
   lcd.clear();
   lcd.setCursor(0,0);
   switch(selected) {
    case 0:
     lcd.print("Change Units  ");
     break;
    case 1:
     lcd.print("Backlight On/Off");
     break;
    case 2:
     lcd.print("Logging On/Off ");
     break;
    case 3:
     lcd.print("Exit Settings ");
     break;
   }
  }
 }
 // when button is pressed...
 lcd.clear();
 switch(selected) {
  case 0:
   settingsChangeUnits();
   break;
  case 1:
   settingsChangeBacklight();
   break;
  case 2:
   settingsChangeLogging();
 }
}
Theres more but i don't want to clog your screens.