Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name: mod4_buttonLEDtoggle.ino
- * Date: 2021/10/14
- * Author: fsc
- * Version 1.0
- * URL: https://wokwi.com/arduino/projects/312822322482381377
- */
- #define PIN_LED_RED 4
- #define PIN_LED_BLUE 6
- #define PIN_BUTTON_RED 8
- #define PIN_BUTTON_BLUE 9
- bool isBlueOn = false, isRedOn = false; // bei Programmstart beide LEDs aus
- byte buttonStateBlue, buttonStateRed;
- void setup()
- {
- pinMode(PIN_LED_BLUE, OUTPUT);
- pinMode(PIN_LED_RED, OUTPUT);
- pinMode(PIN_BUTTON_BLUE, INPUT_PULLUP);
- pinMode(PIN_BUTTON_RED, INPUT_PULLUP);
- }
- void loop()
- {
- buttonStateBlue = digitalRead(PIN_BUTTON_BLUE);
- buttonStateRed = digitalRead(PIN_BUTTON_RED);
- if (buttonStateBlue == LOW) {
- isBlueOn = true;
- isRedOn = false;
- } else if (buttonStateRed == LOW) {
- isBlueOn = false;
- isRedOn = true;
- }
- if (isBlueOn) {
- digitalWrite(PIN_LED_BLUE, HIGH);
- digitalWrite(PIN_LED_RED, LOW);
- } else if (isRedOn) {
- digitalWrite(PIN_LED_BLUE, LOW);
- digitalWrite(PIN_LED_RED, HIGH);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement