Hello and sorry if this is drawn out, but I'm trying to change a couple if{} statements that both run the same operations when either is met (which is currently working perfectly), into an if{} / else if{} so when one is met and true, a set of operations runs, then if the other is met and tru, it runs a separate set of operations.
Right now its set so if a long button press is met for 5 seconds, or the 5 minutes time elapses, the same set of operations happen (again, this runs great with no issues). I would like to change it so when the long button press occurs, it runs a set of operations, then if the 5 minutes time elapses, it runs a different set of operations.
Ive tried editing using the if{} / else if{} statements, but when I do, the long button press no longer waits the set time of 5 seconds, as soon as the button is pressed, it runs the if{} functions, but when the time elapses, it doesnt run all the else if{} functions, just clears the lcd and back to the main loop menu, with the called outputs still active and high and not shutting them off.
Any help is appreciated ![]()
Here is the current code not using the if{} / else if{} statements that both process the same operations when either or are met, its not the entire sketch, just the section that refers to the issue...
void menuItem50() { //Function executes when you select from the list
//Clearing Tiny85 and LCD
int activeButton = 0;
menu_clear();
//UART to Tiny85
//Tell it to play file 50 by sending it a '50' or pin to read it in with
byte msg[3]; //Creates message to send
msg[0] = 0x35; //Send a 5 for the receiver to decode and use it in the case\switch statement
msg[1] = 0x30; //Send a 0 for the receiver to decode and use it in the case\switch statement
msg[2] = 0x0A; //New line character
mySerial.write(msg, 3); //Sends message to Tiny85
//Change lcd display
lcd.setCursor(0, 0); //LCD column 1 row 0
lcd.print("HEADACHE"); //Line 1 display
lcd.setCursor(0, 1); //LCD column 1 row 1
lcd.print("RUNNING"); //Line 2 display
//----------------------------------------MINUTE TIMER----------------------------------------
startTime = millis(); //Start the timer before it goes into loop. and set it 0 after it exits
counter = 0; //Start with fresh counter when it gets in the function.
}
//While loop keeps the menu jammed and the attiny85 are independent to continu running
while ((millis() - startTime < FIVE_MINUTES)) //While it is less than, it will hold the loop
{
bool val = digitalRead(LCD_ADC); //Pin with 3 functions attached to it. Interrupt pin, menu control and forced sleep
if (val == 0)
counter++;
Serial.print("Counter for forced sleep: ");
Serial.println(counter);
// NOW here if it goes greater than - minutes\seconds or the Forced Sleep counter; it stops the attiny85 from playing
if (millis() - startTime > FIVE_MINUTES || counter > 500) //Here if '>' it will execute function, if not, it will print 'its ticking in loop fashion
{
// - AFTER - MINUTES-: Send the three Attiny85 the reset signal to stop generatinng frequencies, and go to sleep.
digitalWrite(reset_tiny, LOW); //Resets Tiny85
Serial.println("Tiny are now in Reset");
lcd.clear(); //Clears LCD
beep(); //Executes buzzer function
delay(100); //100ms delay
Going_To_Sleep(); //Executes sleep mode
break;
}
} //It exits the while loop
}
while (activeButton == 0) {
int button;
readKey = analogRead(0);
if (readKey < 790) {
delay(10);
}
button = 4;
switch (button) {
case 4:
button = 0;
activeButton = 1;
break;
}
}
}
Here is the code with the if{} / else if{} statements...
void menuItem50() { //Function executes when you select from the list
//Clearing Tiny85 and LCD
int activeButton = 0;
menu_clear();
//UART to Tiny85
//Tell it to play file 50 by sending it a '50' or pin to read it in with
byte msg[3]; //Creates message to send
msg[0] = 0x35; //Send a 5 for the receiver to decode and use it in the case\switch statement
msg[1] = 0x30; //Send a 0 for the receiver to decode and use it in the case\switch statement
msg[2] = 0x0A; //New line character
mySerial.write(msg, 3); //Sends message to Tiny85
//Change lcd display
lcd.setCursor(0, 0); //LCD column 1 row 0
lcd.print("HEADACHE"); //Line 1 display
lcd.setCursor(0, 1); //LCD column 1 row 1
lcd.print("RUNNING"); //Line 2 display
//----------------------------------------MINUTE TIMER----------------------------------------
startTime = millis(); // start the timer before it goes into loop. and set it 0 after it exits
counter = 0; // start with fresh counter when it gets in the function.
}
//----------------------------------------MENU 2----------------------------------------
void menu_2() {
//----------------------------------------TIMING FUNCTION----------------------------------------
//While loop keeps the menu jammed and the attiny85 are independent to continu running
while ((millis() - startTime < FIVE_MINUTES)) //While it is less than, it will hold the loop
{
bool val = digitalRead(LCD_ADC); //Pin with 3 functions attached to it. Interrupt pin, menu control and forced sleep
if (val == 0){
counter++;
Serial.print("Counter for forced sleep: ");
Serial.println(counter);
digitalWrite(reset_tiny, LOW); //Resets Tiny85
Serial.println("Tiny are now in Reset");
lcd.clear(); //Clears LCD
beep(); //Executes buzzer function
delay(100); //100ms delay
Going_To_Sleep(); //Executes sleep mode
break;
}
// NOW here if it goes greater than - minutes\seconds or the Forced Sleep counter; it stops the attiny85 from playing
else if (millis() - startTime > FIVE_MINUTES || counter > 500) //Here if '>' it will execute function, if not, it will print 'its ticking in loop fashion
{
// - AFTER - MINUTES-: Send the three Attiny85 the reset signal to stop generatinng frequencies, and go to sleep.
digitalWrite(reset_tiny, LOW); //Resets Tiny85
Serial.println("Tiny are now in Reset");
digitalWrite(power_pin, LOW); //Tiny85 powered off
delay(100); //100ms delay
lcd.clear(); //Clears LCD
delay(100); //100ms delay
loop(); //Back to main loop
break;
}
} //It exits the while loop
}
while (activeButton == 0) {
int button;
readKey = analogRead(0);
if (readKey < 790) {
delay(10);
}
button = 4;
switch (button) {
case 4:
button = 0;
activeButton = 1;
break;
}
}
}