Guest User

Untitled

a guest
Mar 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. // the number of the pushbutton pin
  2. const int buttonPin = PB0;
  3. // the number of the LED pin
  4. const int ledPin = PB1;
  5.  
  6. int ledState = 0;
  7. int buttonState = 0;
  8.  
  9. void setup() {
  10. pinMode(ledPin, OUTPUT);
  11. pinMode(buttonPin, INPUT);
  12. }
  13.  
  14. void loop() {
  15. // Read the button
  16. int btn = digitalRead(buttonPin);
  17. // when button state has changed and is pressed
  18. if (btn != buttonState && btn == HIGH) {
  19. // toggle the logical LED state
  20. if (ledState == HIGH) {
  21. ledState = LOW;
  22. } else {
  23. ledState = HIGH;
  24. }
  25. // and make the logical real
  26. digitalWrite(ledPin, ledState);
  27. }
  28. buttonState = btn;
  29. }
Add Comment
Please, Sign In to add comment