const int LED = 9; // define the pin associated to LED const int BUTTON = 7; // define the pin associated to BUTTON int state_actual,state_old,light; // define some variables // Initialization void setup() { pinMode(LED, OUTPUT); pinMode(BUTTON, INPUT); light=0; } void loop() { state_actual=digitalRead(BUTTON); // if the state rise from 0 to 1 the light variable toggle if ((state_actual-state_old)==1) {light=1-light;} digitalWrite(LED, light); state_old=state_actual; // update the state // delay (100); // uncomment this line to avoid undesired commutation }