RaspBar icon

mod3_buttonLED.ino

RaspBar | PRO | 10/19/21 06:33:48 PM UTC (Edited) | 0 ⭐ | 1043 👁️ | Never ⏰ | []
C++ |

1.17 KB

|

None

|

0 👍

/

0 👎

/*
 * Name: mod3_buttonLED.ino
 * Date: 2021/10/14
 * Author: fsc
 * Version 1.0
 * URL: https://wokwi.com/arduino/projects/312694073356976705
 */
 
const int PIN_LED1 = 4; // Pin der roten LED
const int PIN_LED2 = 6; // Pin der blauen LED
 
const int PIN_BUTTON1 = 8; // Pin der Taste für rote LED
const int PIN_BUTTON2 = 9; // Pin der Taste für blaue LED
 
int buttonState1 = 0; // Status von PIN_BUTTON1
int buttonState2 = 0; // Status von PIN_BUTTON2
 
void setup()
{
    pinMode(PIN_LED1, OUTPUT);
    pinMode(PIN_LED2, OUTPUT);
    pinMode(PIN_BUTTON1, INPUT_PULLUP); 
    pinMode(PIN_BUTTON2, INPUT_PULLUP); 
}
 
void loop()
{
    // Status von PIN_BUTTON1 lesen
    buttonState1 = digitalRead(PIN_BUTTON1);
    // Status von PIN_BUTTON2 lesen
    buttonState2 = digitalRead(PIN_BUTTON2);
    
    if (buttonState1 == LOW) {
        // rote LED ein
        digitalWrite(PIN_LED1, HIGH);
    } else {
        // rote LED aus
        digitalWrite(PIN_LED1, LOW);
    }
 
    if (buttonState2 == LOW) {
        // blaue LED ein
        digitalWrite(PIN_LED2, HIGH);
    } else {
        // blaue LED aus
        digitalWrite(PIN_LED2, LOW);
    }
}

Comments