Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. const int buttonPin = 2; // the number of the pushbutton pin
  2. const int ledPin = 13; // the number of the LED pin
  3. // variables will change:
  4. int buttonState = 0;
  5. void setup() {
  6. // initialize the LED pin as an output:
  7. pinMode(ledPin, OUTPUT);
  8. // initialize the pushbutton pin as an input:
  9. pinMode(buttonPin, INPUT);
  10. }
  11. void loop() {
  12. // read the state of the pushbutton value:
  13. buttonState = digitalRead(buttonPin);
  14. // check if the pushbutton is pressed.
  15. // if it is, the buttonState is HIGH:
  16. if (buttonState == HIGH) {
  17. // turn LED on:
  18. digitalWrite(ledPin, HIGH);
  19. } else {
  20. // turn LED off:
  21. digitalWrite(ledPin, LOW);
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement