const int buttonPin = 27; // the number of the pushbutton pin const int ledPin = 0; // the number of the LED pin bool flag=false; // boolean operation bool pressed=false; // variables will change: int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); if (buttonState==HIGH){ if (pressed==false){ flag=!flag; //changes to opposite value pressed=true; } }else{ pressed=false; delay(50); } digitalWrite(ledPin, flag); }