martedì 9 dicembre 2014

Fronte di discesa



      # 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 == 0) 
                 { if( ledState==0 )
                       ledState=1;
                   else ledState=0;   }
             lastButtonState = buttonState;}
      digitalWrite(LED1, ledState);
        delay(20);
      }

Nessun commento:

Posta un commento