Debounce_Library
Diff: antirrebote.cpp
- Revision:
- 1:8db2c2a203d9
- Parent:
- 0:16d62113f1d5
--- a/antirrebote.cpp Thu May 03 23:32:45 2018 +0000 +++ b/antirrebote.cpp Wed May 23 00:01:12 2018 +0000 @@ -1,56 +1,53 @@ -#include "antirrebote.h" +#include "antirrebote.h" //Librería creada para la función del antirrebote en un pulsador + //Declaración de los nombres de estados enum{PULS_NA, PULS_FLC1, PULS_A, PULS_FLC2}; -AntReb::~AntReb(){ +AntReb::~AntReb(){ //Destrucción del objeto } -AntReb::AntReb(){ - e_PULS = PULS_NA; +AntReb::AntReb(){ //Construcción de objeto + e_PULS = PULS_NA; //Valor inical de la variable encargada de memorizar el estado anterior } -void AntReb::setPin(DigitalIn pin) -{ - P_PULS =pin.read(); +void AntReb::setPin(DigitalIn pin){ //Función del objeto "AntReb" para setear el pin del pulsador + P_PULS = pin.read(); //Se le asigna el valor leído en la entrada seleccionada a una variable "P_PULS" (Pin Pulsador) } -pinEstado_t AntReb::antiRebote(){ - pinEstado_t StateOut; - +pinEstado_t AntReb::antiRebote(){ //Máquina de estados del objeto "AntReb" para crear el antirrebote + pinEstado_t StateOut; //Variable creada que será el valor de salida de la librería switch(e_PULS){ default: case PULS_NA: StateOut = APAGADO; + //Se toma el "0" como valor del pulsador presionado porque se lo estipula a una conexión PULL-UP if(P_PULS == 0) { - e_PULS = PULS_FLC1; + e_PULS = PULS_FLC1; //Cambio de estado } break; case PULS_FLC1: StateOut = APAGADO; if(P_PULS == 0) { - e_PULS = PULS_A; - StateOut= ENCENDIDO; + e_PULS = PULS_A; //Cambio de estado + StateOut = ENCENDIDO; }else if(P_PULS == 1) { - e_PULS = PULS_NA; + e_PULS = PULS_NA; //Cambio de estado } break; case PULS_A: - StateOut =APAGADO; + StateOut = APAGADO; if(P_PULS == 1) { - e_PULS = PULS_FLC2; + e_PULS = PULS_FLC2; //Cambio de estado } break; case PULS_FLC2: StateOut = APAGADO; if(P_PULS == 0) { - e_PULS = PULS_A; + e_PULS = PULS_A; //Cambio de estado }else if(P_PULS == 1) { - e_PULS = PULS_NA; + e_PULS = PULS_NA; //Cambio de estado } break; } - return StateOut; -} - - - + return StateOut; //La función devuelve el valor de salida +} \ No newline at end of file