Debounce_Library
antirrebote.cpp@1:8db2c2a203d9, 2018-05-23 (annotated)
- Committer:
- Tom_87
- Date:
- Wed May 23 00:01:12 2018 +0000
- Revision:
- 1:8db2c2a203d9
- Parent:
- 0:16d62113f1d5
_
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Tom_87 | 1:8db2c2a203d9 | 1 | #include "antirrebote.h" //Librería creada para la función del antirrebote en un pulsador |
Tom_87 | 0:16d62113f1d5 | 2 | |
Tom_87 | 1:8db2c2a203d9 | 3 | //Declaración de los nombres de estados |
Tom_87 | 0:16d62113f1d5 | 4 | enum{PULS_NA, PULS_FLC1, PULS_A, PULS_FLC2}; |
Tom_87 | 0:16d62113f1d5 | 5 | |
Tom_87 | 1:8db2c2a203d9 | 6 | AntReb::~AntReb(){ //Destrucción del objeto |
Tom_87 | 0:16d62113f1d5 | 7 | } |
Tom_87 | 1:8db2c2a203d9 | 8 | AntReb::AntReb(){ //Construcción de objeto |
Tom_87 | 1:8db2c2a203d9 | 9 | e_PULS = PULS_NA; //Valor inical de la variable encargada de memorizar el estado anterior |
Tom_87 | 0:16d62113f1d5 | 10 | } |
Tom_87 | 0:16d62113f1d5 | 11 | |
Tom_87 | 1:8db2c2a203d9 | 12 | void AntReb::setPin(DigitalIn pin){ //Función del objeto "AntReb" para setear el pin del pulsador |
Tom_87 | 1:8db2c2a203d9 | 13 | P_PULS = pin.read(); //Se le asigna el valor leído en la entrada seleccionada a una variable "P_PULS" (Pin Pulsador) |
Tom_87 | 0:16d62113f1d5 | 14 | } |
Tom_87 | 0:16d62113f1d5 | 15 | |
Tom_87 | 1:8db2c2a203d9 | 16 | pinEstado_t AntReb::antiRebote(){ //Máquina de estados del objeto "AntReb" para crear el antirrebote |
Tom_87 | 1:8db2c2a203d9 | 17 | pinEstado_t StateOut; //Variable creada que será el valor de salida de la librería |
Tom_87 | 0:16d62113f1d5 | 18 | switch(e_PULS){ |
Tom_87 | 0:16d62113f1d5 | 19 | default: |
Tom_87 | 0:16d62113f1d5 | 20 | case PULS_NA: |
Tom_87 | 0:16d62113f1d5 | 21 | StateOut = APAGADO; |
Tom_87 | 1:8db2c2a203d9 | 22 | //Se toma el "0" como valor del pulsador presionado porque se lo estipula a una conexión PULL-UP |
Tom_87 | 0:16d62113f1d5 | 23 | if(P_PULS == 0) { |
Tom_87 | 1:8db2c2a203d9 | 24 | e_PULS = PULS_FLC1; //Cambio de estado |
Tom_87 | 0:16d62113f1d5 | 25 | } |
Tom_87 | 0:16d62113f1d5 | 26 | break; |
Tom_87 | 0:16d62113f1d5 | 27 | case PULS_FLC1: |
Tom_87 | 0:16d62113f1d5 | 28 | StateOut = APAGADO; |
Tom_87 | 0:16d62113f1d5 | 29 | if(P_PULS == 0) { |
Tom_87 | 1:8db2c2a203d9 | 30 | e_PULS = PULS_A; //Cambio de estado |
Tom_87 | 1:8db2c2a203d9 | 31 | StateOut = ENCENDIDO; |
Tom_87 | 0:16d62113f1d5 | 32 | }else if(P_PULS == 1) { |
Tom_87 | 1:8db2c2a203d9 | 33 | e_PULS = PULS_NA; //Cambio de estado |
Tom_87 | 0:16d62113f1d5 | 34 | } |
Tom_87 | 0:16d62113f1d5 | 35 | break; |
Tom_87 | 0:16d62113f1d5 | 36 | case PULS_A: |
Tom_87 | 1:8db2c2a203d9 | 37 | StateOut = APAGADO; |
Tom_87 | 0:16d62113f1d5 | 38 | if(P_PULS == 1) { |
Tom_87 | 1:8db2c2a203d9 | 39 | e_PULS = PULS_FLC2; //Cambio de estado |
Tom_87 | 0:16d62113f1d5 | 40 | } |
Tom_87 | 0:16d62113f1d5 | 41 | break; |
Tom_87 | 0:16d62113f1d5 | 42 | case PULS_FLC2: |
Tom_87 | 0:16d62113f1d5 | 43 | StateOut = APAGADO; |
Tom_87 | 0:16d62113f1d5 | 44 | if(P_PULS == 0) { |
Tom_87 | 1:8db2c2a203d9 | 45 | e_PULS = PULS_A; //Cambio de estado |
Tom_87 | 0:16d62113f1d5 | 46 | }else if(P_PULS == 1) { |
Tom_87 | 1:8db2c2a203d9 | 47 | e_PULS = PULS_NA; //Cambio de estado |
Tom_87 | 0:16d62113f1d5 | 48 | |
Tom_87 | 0:16d62113f1d5 | 49 | } |
Tom_87 | 0:16d62113f1d5 | 50 | break; |
Tom_87 | 0:16d62113f1d5 | 51 | } |
Tom_87 | 1:8db2c2a203d9 | 52 | return StateOut; //La función devuelve el valor de salida |
Tom_87 | 1:8db2c2a203d9 | 53 | } |