Diferencia entre revisiones de «Digital input pullup»

De ArduWiki
Saltar a: navegación, buscar
(Página creada con « == Placa aplicable == == Código == <pre> </pre> == Comentarios == == Vea también == * Blink without delay * Button * Debounce * State change detection...»)
 
(Vea también)
 
(No se muestran 7 ediciones intermedias del mismo usuario)
Línea 1: Línea 1:
 +
Este ejemplo demuestra el uso de [[pinMode()]] con INPUT_PULLUP. Lee una entrada digital en el pin 2, prende el LED a bordo e imprime los resultados en el monitor de serie.
 +
 +
== Circuito ==
 +
Conecte un pulsador entre el pin digital 2 y GND.
  
 
== Placa aplicable ==
 
== Placa aplicable ==
 +
Todas
  
 
== Código ==
 
== Código ==
<pre>
+
<syntaxhighlight lang="c++">
</pre>
+
const byte pin = 2;
 +
void setup() {
 +
  Serial.begin(115200);
 +
  pinMode(pin, INPUT_PULLUP);
 +
  pinMode(LED_BUILTIN, OUTPUT);
 +
}
 +
void loop() {
 +
  bool pulsador = digitalRead(pin);
 +
  Serial.println(pulsador);
 +
  if (pulsador == HIGH) {
 +
      digitalWrite(LED_BUILTIN, LOW);
 +
      Serial.println(""LED OFF);
 +
  }else{
 +
      digitalWrite(LED_BUILTIN, HIGH);
 +
      Serial.println(""LED ON);
 +
  }
 +
}
 +
</syntaxhighlight>
  
 
== Comentarios ==
 
== Comentarios ==
 +
* Notese que gracias a la configuración del pin digital 2 (INPUT_PULLUP) este pin esta normalmente en HIGH y pasa a LOW cuando presionar pulsador.
 +
* if (pulsador == HIGH) es exactamente lo mismo que if (pulsador) o '''if (ditalRead(pin))'''.
  
 
== Vea también ==
 
== Vea también ==
* [[Blink without delay]]
+
<categorytree mode=all>Ejemplo Digital</categorytree>
* [[Button]]
+
 
* [[Debounce]]
+
== Referencias ==
* [[State change detection]]
+
* [https://www.arduino.cc/en/Tutorial/DigitalInputPullup Ejemplos incluidos]
* [[Tone keyboard]]
 
* [[Tone melody]]
 
* [[Tone múltiple]]
 
* [[Tone pitch follower]]
 
  
[[Category:Digital]]
+
[[Category:Ejemplo Digital]]

Revisión actual del 21:05 6 jul 2019

Este ejemplo demuestra el uso de pinMode() con INPUT_PULLUP. Lee una entrada digital en el pin 2, prende el LED a bordo e imprime los resultados en el monitor de serie.

Circuito

Conecte un pulsador entre el pin digital 2 y GND.

Placa aplicable

Todas

Código

const byte pin = 2;
void setup() {
   Serial.begin(115200);
   pinMode(pin, INPUT_PULLUP);
   pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
   bool pulsador = digitalRead(pin);
   Serial.println(pulsador);
   if (pulsador == HIGH) {
      digitalWrite(LED_BUILTIN, LOW);
      Serial.println(""LED OFF);
   }else{
      digitalWrite(LED_BUILTIN, HIGH);
      Serial.println(""LED ON);
   }
}

Comentarios

  • Notese que gracias a la configuración del pin digital 2 (INPUT_PULLUP) este pin esta normalmente en HIGH y pasa a LOW cuando presionar pulsador.
  • if (pulsador == HIGH) es exactamente lo mismo que if (pulsador) o if (ditalRead(pin)).

Vea también


Referencias