Rhavecilla

2 Buttons and an LED

Nov 27th, 2021
625
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Program ID: 2 Button and an LED
  3.  * Program by: Rolando Avecilla
  4.  *             www.facebook.com/helpyouonurthesis
  5.  * Date Start: 11/27/2021
  6.  *        End: 11/27/2021
  7.  *        
  8.  *    Modules: Arduino UNO R3
  9.  *             LED
  10.  *             Buttons x2
  11.  *    Version: 1.00
  12.  *  Objective: Demonstration
  13.  */
  14.  
  15.  
  16. // Pin definition.
  17. #define button1   2
  18. #define button2   3
  19. #define LED       4
  20.  
  21. void setup() {
  22.  
  23.   pinMode(button1, INPUT_PULLUP);
  24.   pinMode(button2, INPUT_PULLUP);
  25.   pinMode(LED, OUTPUT);
  26.  
  27. }
  28.  
  29. void loop() {
  30.  
  31.   static bool LEDState = false;
  32.  
  33.   if (digitalRead(button1) == LOW){
  34.     delay(500);
  35.     LEDState = true;
  36.   }
  37.  
  38.   if (digitalRead(button2) == LOW){
  39.     delay(500);
  40.     LEDState = !LEDState;
  41.   }
  42.  
  43.   digitalWrite(LED, LEDState);
  44.  
  45. }
RAW Paste Data