Salve a tutti,
sto cercando di capire nel dettaglio come funzionano i bottoni.
In particolare ho caricato su Arduino UNO Rev3 il seguente sketch:
const int ledPin = 13;
const int buttonPin = 2;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}
int ledState = LOW;
int oldButtonState = LOW;
void loop() {
const int buttonState = digitalRead(buttonPin);
if (buttonState != oldButtonState && buttonState == HIGH) {
ledState = (ledState == LOW) ? HIGH : LOW;
digitalWrite(ledPin, ledState);
delay(50);
}
oldButtonState = buttonState;
}
In pratica il bottone collegato tramite una resistenza pull-down al pin 2 fa da switch al led di cui al pin 13.
Non riesco però a capire questa riga:
ledState = (ledState == LOW) ? HIGH : LOW;
Come funziona?