Post topics, source code that relate to the Arduino Platform

User avatar
By testcs
#37390 Hi,

I recently bought an ESP8266-12E.
I'm trying to build something with a pushbutton between GPIO12 and GND, handled via interrupts.

Found the example sketch from below:

Code: Select all/*

31 mar 2015
This sketch shows the use of interrupts.
A switch is to be connected between GROUND and GPIO0.
The mail loop print the value of the state variable every second.
Every time the switch is pressed the interrupt service routine is executed, inverting the state variable.
*/

volatile int state = LOW;

void setup()
{
  Serial.begin(115200);
  delay(10);
  attachInterrupt(12, isr, FALLING);
}

void loop()
{
  Serial.print("State is now : ");
  Serial.println(state);
  delay(1000);
}

void isr()
{
  state = !state;
}



So if I try it out when I push the button for the first time the variable "state" changes from 0 to 1 as expected.
But nothing happens when pushing the button for the second time.
I would expect state to change back to 0. But this doesn't happen.
Any subsequent button press does nothing either.

Any help would be appreciated. Thanks