const int buttonPin = 27; // the number of the pushbutton pin const int ledPin = 1; // the number of the LED pin bool flag = false; bool pressed = false; // variables will change: int buttonState = 0; // variable for reading the pushbutton status void setup() { Serial.begin(9600);//initalise serial on 9600 baud rate // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); delay(1000); Serial.println("led test"); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. If it is, the buttonState is HIGH: if (buttonState == HIGH) { if (pressed == false) // introduce this boolean variable to cater teh blinking effect { Serial.println(buttonState); Serial.println("button is pressed"); flag = !flag; //flag=!flag pressed = true; } } else{ pressed = false; delay(50); } digitalWrite (ledPin, flag); }