// Ejemplo de pulsador PullDown que al activar sea 01
//
// Button not pressed: signal is LOW
// Button pressed : signal is HIGH
//
// Pulsador no presionado: la señal es LOW
// Pulsador presionado: La señal es HIGH
// The resistor is a pulldown resistor.
//
// Button Example One: https://wokwi.com/projects/397990618860958721
// Button Example Two: https://wokwi.com/projects/397990611031240705
//
const int buttonPin = 8;
int oldValue = LOW; // Poer defecto el pin 8 de entrada es LOW.
void setup()
{
Serial.begin(115200);
Serial.println("Presione el Botón.");
// inicializa la Lectura del pulsador
pinMode(buttonPin, INPUT);
}
void loop()
{
// Lee el valor del pin 8
int newValue = digitalRead(buttonPin);
// Verifica si el valor cambió
// comparándolo con el valor anterior
if(newValue != oldValue)
{
if(newValue == HIGH)
{
Serial.println("El Pulsador está presionado, y el valor es:");
Serial.println(newValue);
}
else
{
Serial.println("El Pulsador no está presionado, y el valor es:");
Serial.println(newValue);
}
// Recuerda el valor para la próxima vez.
oldValue = newValue;
}
// Espera el sketch.
// para evitar rebote del pulsador (ruido)
delay(100);
}