Ejercicio N°1: Parpadeo de un led controlado por un pulsador

Dependencies:   KL25N_TPN1_EJN1 TSI mbed

Committer:
JAgustinOtero
Date:
Tue Jun 05 23:32:50 2018 +0000
Revision:
0:c2ad90d1e461
Ejercicio N?1:; Parpadeo de un led controlado por un pulsador

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JAgustinOtero 0:c2ad90d1e461 1 #include "mbed.h"
JAgustinOtero 0:c2ad90d1e461 2 #include "TSISensor.h"
JAgustinOtero 0:c2ad90d1e461 3 #include "ME_Parpadeo.h"
JAgustinOtero 0:c2ad90d1e461 4 #define apagado 1
JAgustinOtero 0:c2ad90d1e461 5 #define prendido 0
JAgustinOtero 0:c2ad90d1e461 6 #define presionado 1
JAgustinOtero 0:c2ad90d1e461 7 #define no_presionado 0
JAgustinOtero 0:c2ad90d1e461 8 char a=1;
JAgustinOtero 0:c2ad90d1e461 9
JAgustinOtero 0:c2ad90d1e461 10 DigitalIn entrada (PTE1);
JAgustinOtero 0:c2ad90d1e461 11 DigitalOut led(LED3);
JAgustinOtero 0:c2ad90d1e461 12
JAgustinOtero 0:c2ad90d1e461 13 char pulsador=0;
JAgustinOtero 0:c2ad90d1e461 14 char l=0;
JAgustinOtero 0:c2ad90d1e461 15
JAgustinOtero 0:c2ad90d1e461 16 Ticker readP;
JAgustinOtero 0:c2ad90d1e461 17 Ticker parpadeoL;
JAgustinOtero 0:c2ad90d1e461 18
JAgustinOtero 0:c2ad90d1e461 19 void antirebote(void);
JAgustinOtero 0:c2ad90d1e461 20 void parpadeoLED(void);
JAgustinOtero 0:c2ad90d1e461 21
JAgustinOtero 0:c2ad90d1e461 22 int main()
JAgustinOtero 0:c2ad90d1e461 23 {
JAgustinOtero 0:c2ad90d1e461 24 char b=0;
JAgustinOtero 0:c2ad90d1e461 25 led=apagado;
JAgustinOtero 0:c2ad90d1e461 26 TSISensor tsi;
JAgustinOtero 0:c2ad90d1e461 27 readP.attach(&antirebote,0.001);
JAgustinOtero 0:c2ad90d1e461 28 parpadeoL.attach(&parpadeoLED,0.5);
JAgustinOtero 0:c2ad90d1e461 29 while(1) {
JAgustinOtero 0:c2ad90d1e461 30 b=enable(pulsador);//esta funcion se encarga de habilitar o deshabilitar el parpadeo del led cuando se presiona el pulsador
JAgustinOtero 0:c2ad90d1e461 31 parpadeo(b);//esta funcion se encarga de realizar el parpadeo del led
JAgustinOtero 0:c2ad90d1e461 32 if(entrada==1 && l==0 && pulsador!=1) l=10;
JAgustinOtero 0:c2ad90d1e461 33 }
JAgustinOtero 0:c2ad90d1e461 34 }
JAgustinOtero 0:c2ad90d1e461 35
JAgustinOtero 0:c2ad90d1e461 36 void parpadeoLED(void)// esta funcion es el ticker vinculado al parpadeo del led
JAgustinOtero 0:c2ad90d1e461 37 {
JAgustinOtero 0:c2ad90d1e461 38 parpadeo_estado=!parpadeo_estado;
JAgustinOtero 0:c2ad90d1e461 39 }
JAgustinOtero 0:c2ad90d1e461 40
JAgustinOtero 0:c2ad90d1e461 41 void antirebote()// esta funcion se encarga de sacarle el rebote al pulsador
JAgustinOtero 0:c2ad90d1e461 42 {
JAgustinOtero 0:c2ad90d1e461 43 if(entrada==1 && l>0) l--;
JAgustinOtero 0:c2ad90d1e461 44 if(l==0 && entrada==1) pulsador=1;
JAgustinOtero 0:c2ad90d1e461 45 else pulsador=0;
JAgustinOtero 0:c2ad90d1e461 46
JAgustinOtero 0:c2ad90d1e461 47 }