INPUT_PULLUP en Arduino
La resistencia interna sostiene el pin en HIGH; apretar lo baja a LOW.
// INPUT_PULLUP holds the pin HIGH; pressing pulls it LOW.
const int DOOR_PIN = 2;
const int LAMP_PIN = 13;
void setup() {
pinMode(DOOR_PIN, INPUT_PULLUP);
pinMode(LAMP_PIN, OUTPUT);
}
void loop() {
// Closed switch reads LOW, so the logic reads inverted.
if (digitalRead(DOOR_PIN) == LOW) {
digitalWrite(LAMP_PIN, HIGH);
} else {
digitalWrite(LAMP_PIN, LOW);
}
}
Cómo funciona
pinMode(DOOR_PIN, INPUT_PULLUP)activa la resistencia integrada.- El switch cerrado lee
LOW— la lógica corre invertida. - Sin resistencia externa: el chip la pone.
Palabras clave y builtins usados aquí
HIGHINPUT_PULLUPLOWOUTPUTconstelseifintloopsetupvoid
El intento, en números
- Líneas
- 17
- Caracteres a escribir
- 365
- Tokens
- 69
- Ritmo de tres estrellas
- 70 tpm
Al ritmo de tres estrellas de 70 tokens por minuto, este intento toma unos 59 segundos.
Paso 1 de 3 en E/S digital; paso 4 de 27 en Fundamentos del lenguaje.