#define SERIAL_SPEED 9600
const int buttonPin = 12;
const int ledPin = 25;
int buttonState, prev_buttonState;
int ledState;
unsigned long last_DebounceTime = 0;
unsigned long debounce_delay = 50;
void setup() {
// Configuracion de puertos
pinMode(ledPin, OUTPUT);
Serial.begin(SERIAL_SPEED);
// Inicializacion de variables
buttonState = 0;
ledState = LOW;
digitalWrite(ledPin, ledState);
prev_buttonState = buttonState;
// Iniciacion del puerto serial
Serial.println("Inicio...");
}
void loop() {
buttonState = digitalRead(buttonPin);
delay(debounce_delay);
if (buttonState != prev_buttonState) {
// Transición (positiva o negativa)
// Serial.println("[T]");
if (buttonState == HIGH) {
// Transición positiva
Serial.print("[T+]-> Led:");
Serial.println(ledState);
ledState = !ledState;
digitalWrite(ledPin, ledState);
}
}
prev_buttonState = buttonState;
}