Advertisement
MC2Studio

Przycisk 1

Dec 16th, 2020
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define LED  7
  2. #define button 4
  3.  
  4. boolean oldSwitchState = HIGH;
  5. boolean newSwitchState = HIGH;
  6. boolean LEDstatus = LOW;
  7.  
  8. void setup()
  9. {
  10.     Serial.begin ( 115200 );
  11.     Serial.print("Sketch:   ");   Serial.println(__FILE__);
  12.     Serial.print("Uploaded: ");   Serial.println(__DATE__);
  13.     Serial.println(" ");
  14.  
  15.     pinMode(LED, OUTPUT);  
  16.     digitalWrite(LED,LOW);
  17.  
  18.     pinMode(button, INPUT);
  19. }
  20.  
  21. void loop()
  22. {
  23.     newSwitchState = digitalRead(button);
  24.  
  25.     if ( newSwitchState != oldSwitchState )
  26.     {
  27.        // has the button switch been closed?
  28.        if ( newSwitchState == HIGH )
  29.        {
  30.            if ( LEDstatus == LOW ) { digitalWrite(LED, HIGH);  LEDstatus = HIGH; }
  31.            else                    { digitalWrite(LED, LOW);   LEDstatus = LOW;  }
  32.        }
  33.        oldSwitchState = newSwitchState;
  34.     }  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement