arduino                
            Ingressi digitali
        
        
            
    Ricerca…
Sintassi
-  
pinMode(pin, pinMode)// Imposta il pin sulla modalità definita. -  
digitalRead(pin);// Legge il valore da un pin digitale specificato, 
Parametri
| paramter | Dettagli | 
|---|---|
| pinMode |  Dovrebbe essere impostato su INPUT o INPUT_PULLUP  | 
Osservazioni
Se il pin di input non viene premuto LOW o HIGH, il valore galleggerà. Cioè, non sarà chiaramente un 1 o uno 0, ma da qualche parte nel mezzo. Per l'ingresso digitale, è necessario un pull-up o un resistore pulldown.
Lettura dei pulsanti
Questo è un esempio di base su come cablare e accendere / spegnere un LED quando si preme il pulsante.

/* Basic Digital Read
 * ------------------ 
 *
 * turns on and off a light emitting diode(LED) connected to digital  
 * pin 13, when pressing a pushbutton attached to pin 7. It illustrates the
 * concept of Active-Low, which consists in connecting buttons using a
 * 1K to 10K pull-up resistor.
 *
 * Created 1 December 2005
 * copyleft 2005 DojoDave <http://www.0j0.org>
 * http://arduino.berlios.de
 *
 */
int ledPin = 13; // choose the pin for the LED
int inPin = 7;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status
void setup() {
  pinMode(ledPin, OUTPUT);  // declare LED as output
  pinMode(inPin, INPUT);    // declare pushbutton as input
}
void loop(){
  val = digitalRead(inPin);  // read input value
  if (val == HIGH) {         // check if the input is HIGH (button released)
    digitalWrite(ledPin, LOW);  // turn LED OFF
  } else {
    digitalWrite(ledPin, HIGH);  // turn LED ON
  }
}
 Esempio preso da Arduino.cc .
Modified text is an extract of the original Stack Overflow Documentation
        Autorizzato sotto CC BY-SA 3.0
        Non affiliato con Stack Overflow