Taster

Eine LED soll so lange leuchten wie der Taster gedrückt wird.button.png

Die LED, welche man in GND und 13 einbauen kann, soll leuchten wenn der Taster gedrückt ist und wenn der Taster nicht gedrückt ist, soll die LED nicht leuchten. 

 

Programm:

const int buttonPin = 2;     
const int ledPin =  13;      
int buttonState = 0;   

void setup() {
   pinMode(ledPin, OUTPUT);      
   pinMode(buttonPin, INPUT);    
}

void loop(){
   buttonState = digitalRead(buttonPin);

    if (buttonState == HIGH) {
      digitalWrite(ledPin, HIGH);  
   }
   else {
     digitalWrite(ledPin, LOW);
   }
}

 

Sercan, Johannes, Konstantin