# define SWITCH1 2 # define LED1 8 int buttonPin = 2; int ledPin = 8; int buttonState = 0; int lastButtonState = 0; int ledState = 0; void setup() { pinMode(buttonPin, INPUT); pinMode(ledPin, OUTPUT); } void loop() { buttonState = digitalRead(SWITCH1); if ( buttonState != lastButtonState) { if ( buttonState == 1) { if( ledState==1 ) ledState=0; else ledState=1; } lastButtonState = buttonState;} digitalWrite(LED1, ledState); delay(20); }
rwtgergsrfgsdfdsf
RispondiElimina