RaspBar

mod3_buttonLED.ino

Oct 19th, 2021 (edited)
818
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. /*
  2.  * Name: mod3_buttonLED.ino
  3.  * Date: 2021/10/14
  4.  * Author: fsc
  5.  * Version 1.0
  6.  * URL: https://wokwi.com/arduino/projects/312694073356976705
  7.  */
  8.  
  9. const int PIN_LED1 = 4; // Pin der roten LED
  10. const int PIN_LED2 = 6; // Pin der blauen LED
  11.  
  12. const int PIN_BUTTON1 = 8; // Pin der Taste für rote LED
  13. const int PIN_BUTTON2 = 9; // Pin der Taste für blaue LED
  14.  
  15. int buttonState1 = 0; // Status von PIN_BUTTON1
  16. int buttonState2 = 0; // Status von PIN_BUTTON2
  17.  
  18. void setup()
  19. {
  20.     pinMode(PIN_LED1, OUTPUT);
  21.     pinMode(PIN_LED2, OUTPUT);
  22.     pinMode(PIN_BUTTON1, INPUT_PULLUP);
  23.     pinMode(PIN_BUTTON2, INPUT_PULLUP);
  24. }
  25.  
  26. void loop()
  27. {
  28.     // Status von PIN_BUTTON1 lesen
  29.     buttonState1 = digitalRead(PIN_BUTTON1);
  30.     // Status von PIN_BUTTON2 lesen
  31.     buttonState2 = digitalRead(PIN_BUTTON2);
  32.    
  33.     if (buttonState1 == LOW) {
  34.         // rote LED ein
  35.         digitalWrite(PIN_LED1, HIGH);
  36.     } else {
  37.         // rote LED aus
  38.         digitalWrite(PIN_LED1, LOW);
  39.     }
  40.  
  41.     if (buttonState2 == LOW) {
  42.         // blaue LED ein
  43.         digitalWrite(PIN_LED2, HIGH);
  44.     } else {
  45.         // blaue LED aus
  46.         digitalWrite(PIN_LED2, LOW);
  47.     }
  48. }
Add Comment
Please, Sign In to add comment