pugliasos newlogoDEF

Orario della segreteria: tutti i martedì, dalle ore 17 alle 19, su appuntamento.

 

Esempio presente nell’IDE in 02.Digital/Botton

 

Comandare un LED con un pulsante esterno html 55a9cef09ca70f08 

 

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);
}
}

   A riposo, i due lati dell’interruttore non sono collegati tra loro, e si dice che il pulsante è normalmente aperto. In tale esempio il LED rimane acceso finché è premuto il pulsante, poi si spegne; negli esempi che seguono il pulsante si comporta da commutatore.

Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Read more
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline