//Wokwi Serial terminal simulation - Wokwi Arduino Simulator
bool led_status = LOW; // start with LED off, for testing of switch code only
char nav[3][10] = {"ndb1","ndb2","ndb3"};
//volatile bool a0State = false;
bool initialisation_complete =false; // inhibit any interrupts until initialisation is complete
volatile bool interrupt_process_status = false; // start with no switch press pending, ie false
void setup()
{
pinMode(A0, INPUT);
//pinMode(LED, OUTPUT); //set
pinMode(2, INPUT); //set pin 2 as interrupt input
Serial.begin(9600);
Serial.println("Welcome to the Serial Monitor!");
Serial.println("---------------------------------");
attachInterrupt(digitalPinToInterrupt(2), PIN2_ISR, RISING);
initialisation_complete =true; // enable interrupt processing
}
void loop()
{
if (read_button() == true)
{
Serial.println("pressed");
} else
{
//Serial.println("Not pressed");
}
/*while (Serial.available() == 0) {
String str = Serial.readString();
for (int i = 0; i < 3; i++)
{
delay(2000);
Serial.println(nav[i]);
Serial.println(str);
}
} */
}
void PIN2_ISR()
{
if (initialisation_complete == true)
{
if (interrupt_process_status == false)
{
Serial.println("true");
if (digitalRead(2) == HIGH)
{
interrupt_process_status = true;
}
}
}
}
bool read_button()
{
if (interrupt_process_status == true)
{
if (digitalRead(2) ==HIGH)
{
interrupt_process_status == false;
return true;
}
}
return false;
}