Advertisement
belrey10

Day 2: The Button Chronicles

Nov 2nd, 2024 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int buttonPin = 2;  // the number of the pushbutton pin
  2. const int ledPin = 13;    // the number of the LED pin
  3.  
  4. int buttonState = 0;      // variable for reading the pushbutton status
  5.  
  6. void setup() {
  7.   pinMode(ledPin, OUTPUT);      // initialize the LED pin as an output
  8.   pinMode(buttonPin, INPUT);    // initialize the pushbutton pin as an input
  9. }
  10.  
  11. void loop() {
  12.   buttonState = digitalRead(buttonPin);  // read the state of the pushbutton value
  13.  
  14.   if (buttonState == HIGH) {             // check if the pushbutton is pressed
  15.     digitalWrite(ledPin, HIGH);  // turn LED on
  16.   } else {
  17.     digitalWrite(ledPin, LOW);   // turn LED off
  18.   }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement