control para un reloj cukoo
Dependencies: mbed DebouncedIn Pulse1
main.cpp@0:ed0fa031f04b, 2019-05-06 (annotated)
- Committer:
- tony63
- Date:
- Mon May 06 06:12:59 2019 +0000
- Revision:
- 0:ed0fa031f04b
control para un reloj cukoo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony63 | 0:ed0fa031f04b | 1 | /* |
tony63 | 0:ed0fa031f04b | 2 | CONTROL DE RELOJ CUCU |
tony63 | 0:ed0fa031f04b | 3 | produce sonidos mp3 almacenados en un moduludo de audio YX5300 |
tony63 | 0:ed0fa031f04b | 4 | usa un modulo FRDMKL25Z |
tony63 | 0:ed0fa031f04b | 5 | los sonidos se reproducen desde una tarjeta micro SD que los almacena y son 3: |
tony63 | 0:ed0fa031f04b | 6 | sonido de cucu |
tony63 | 0:ed0fa031f04b | 7 | sonido de apertura |
tony63 | 0:ed0fa031f04b | 8 | sonido de cierre |
tony63 | 0:ed0fa031f04b | 9 | los sonidos se reproducen enviando el comando respectivo en formato HEX |
tony63 | 0:ed0fa031f04b | 10 | se tomo la señal de audio de sonido de un reloj con pendulo EDMINISTER y se le filtro la componente de alta frecuencia para |
tony63 | 0:ed0fa031f04b | 11 | conformar un pulso Alto que dura lo que dure los campanazos del reloj son un poco mas de 10 segundos. |
tony63 | 0:ed0fa031f04b | 12 | para filtrar las campanazos intermedios que duran menos de diez segundos este programa detecta que la duracion del pulso |
tony63 | 0:ed0fa031f04b | 13 | que marca la hora dedel CUCU y verifica que dura mas de 10 segundos procede a hacer sonar el cucu con todo su acionamiento respectivo |
tony63 | 0:ed0fa031f04b | 14 | el conteo se hace de 1 a 12, se puede incorporar una señal proveniente de una foto resistencia para que el cucu no suene en la oscuridad |
tony63 | 0:ed0fa031f04b | 15 | */ |
tony63 | 0:ed0fa031f04b | 16 | |
tony63 | 0:ed0fa031f04b | 17 | |
tony63 | 0:ed0fa031f04b | 18 | #include "mbed.h" |
tony63 | 0:ed0fa031f04b | 19 | #include "DebouncedIn.h" |
tony63 | 0:ed0fa031f04b | 20 | #include <Pulse1.h> |
tony63 | 0:ed0fa031f04b | 21 | int i=0,j=0,k=0; |
tony63 | 0:ed0fa031f04b | 22 | float T; |
tony63 | 0:ed0fa031f04b | 23 | Timer t; |
tony63 | 0:ed0fa031f04b | 24 | //...............salidas el sistema..................... |
tony63 | 0:ed0fa031f04b | 25 | DigitalOut led2(LED2);// motor casita |
tony63 | 0:ed0fa031f04b | 26 | DigitalOut m1(PTB8);// motor casita |
tony63 | 0:ed0fa031f04b | 27 | DigitalOut m2(PTB9);// motor casita |
tony63 | 0:ed0fa031f04b | 28 | DigitalOut m3(PTB10);// plunger pajaro |
tony63 | 0:ed0fa031f04b | 29 | DigitalOut m4(PTB11);// plunger pajaro |
tony63 | 0:ed0fa031f04b | 30 | //............entradas ........al sistema |
tony63 | 0:ed0fa031f04b | 31 | InterruptIn button(PTA13); |
tony63 | 0:ed0fa031f04b | 32 | Serial pc(USBTX, USBRX); |
tony63 | 0:ed0fa031f04b | 33 | Serial bird(PTE0,PTE1); //Configura puerto UART de la FRDMKL25Z |
tony63 | 0:ed0fa031f04b | 34 | |
tony63 | 0:ed0fa031f04b | 35 | //comandos del modulo YX5300 PARA HACER SONAR EL CUCU y otras cosas |
tony63 | 0:ed0fa031f04b | 36 | const char cucu1[8]={0x7E, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x01, 0xEF};// CUCU |
tony63 | 0:ed0fa031f04b | 37 | const char openP[8]={0x7E, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x02, 0xEF};// ABRIR PUERTA |
tony63 | 0:ed0fa031f04b | 38 | const char closeP[8]={0x7E, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x03, 0xEF};// CERRAR PUERTA |
tony63 | 0:ed0fa031f04b | 39 | const char slep[8]={0x7E, 0xFF, 0x06, 0x0A, 0x00, 0x00, 0x00, 0xEF};// modo sleep |
tony63 | 0:ed0fa031f04b | 40 | const char awake[8]={0x7E, 0xFF, 0x06, 0x0B, 0x00, 0x00, 0x00, 0xEF};// despertar el modulo |
tony63 | 0:ed0fa031f04b | 41 | void up() { //detecta flanco de subida del cucu en el parlanmte |
tony63 | 0:ed0fa031f04b | 42 | t.start(); //flanco de subida dispara la cuen ta del cronometro. |
tony63 | 0:ed0fa031f04b | 43 | |
tony63 | 0:ed0fa031f04b | 44 | } |
tony63 | 0:ed0fa031f04b | 45 | void dw() { //detecta flanco de bajada en el reloj y para lee y borra el cronometro....... |
tony63 | 0:ed0fa031f04b | 46 | t.stop(); |
tony63 | 0:ed0fa031f04b | 47 | T=t.read(); |
tony63 | 0:ed0fa031f04b | 48 | t.reset(); |
tony63 | 0:ed0fa031f04b | 49 | } |
tony63 | 0:ed0fa031f04b | 50 | |
tony63 | 0:ed0fa031f04b | 51 | //...entrar en modo sleep para ahorar bateria........................ |
tony63 | 0:ed0fa031f04b | 52 | //.....................SLEEP......................................... |
tony63 | 0:ed0fa031f04b | 53 | void slp(){ |
tony63 | 0:ed0fa031f04b | 54 | for(i=0;i<8;i++){ |
tony63 | 0:ed0fa031f04b | 55 | bird.printf("%c",slep[i]); |
tony63 | 0:ed0fa031f04b | 56 | } |
tony63 | 0:ed0fa031f04b | 57 | } |
tony63 | 0:ed0fa031f04b | 58 | |
tony63 | 0:ed0fa031f04b | 59 | //.....................AWAKE.........despierta el modulo............... |
tony63 | 0:ed0fa031f04b | 60 | void awak(){ |
tony63 | 0:ed0fa031f04b | 61 | for(i=0;i<8;i++){ |
tony63 | 0:ed0fa031f04b | 62 | bird.printf("%c", awake[i]); |
tony63 | 0:ed0fa031f04b | 63 | } |
tony63 | 0:ed0fa031f04b | 64 | } |
tony63 | 0:ed0fa031f04b | 65 | |
tony63 | 0:ed0fa031f04b | 66 | //.....................CLOSE.......sonido.............................. |
tony63 | 0:ed0fa031f04b | 67 | void closed(){ |
tony63 | 0:ed0fa031f04b | 68 | for(i=0;i<8;i++){ |
tony63 | 0:ed0fa031f04b | 69 | bird.printf("%c", closeP[i]); |
tony63 | 0:ed0fa031f04b | 70 | } |
tony63 | 0:ed0fa031f04b | 71 | } |
tony63 | 0:ed0fa031f04b | 72 | //.....................OPEN........sonido.............................. |
tony63 | 0:ed0fa031f04b | 73 | void open(){ |
tony63 | 0:ed0fa031f04b | 74 | for(i=0;i<8;i++){ |
tony63 | 0:ed0fa031f04b | 75 | bird.printf("%c", openP[i]); |
tony63 | 0:ed0fa031f04b | 76 | } |
tony63 | 0:ed0fa031f04b | 77 | } |
tony63 | 0:ed0fa031f04b | 78 | |
tony63 | 0:ed0fa031f04b | 79 | //.....................SONIDOS DEL CUCU SEGUN LA HORA............... |
tony63 | 0:ed0fa031f04b | 80 | // esta funcion produce el sonido del cucu segun la hora se encarga de accionar todos los mecanismos del cucu |
tony63 | 0:ed0fa031f04b | 81 | // como la puerta y el pajaro, h es el valor de la hora de 1-12 |
tony63 | 0:ed0fa031f04b | 82 | void cucu(int h){ |
tony63 | 0:ed0fa031f04b | 83 | //.....................abrir la puerta.............................. |
tony63 | 0:ed0fa031f04b | 84 | awak(); |
tony63 | 0:ed0fa031f04b | 85 | wait(1); |
tony63 | 0:ed0fa031f04b | 86 | m1=1; |
tony63 | 0:ed0fa031f04b | 87 | m2=0; |
tony63 | 0:ed0fa031f04b | 88 | open();//sonido abrir sonido de puerta chirriando.. |
tony63 | 0:ed0fa031f04b | 89 | wait(1); |
tony63 | 0:ed0fa031f04b | 90 | |
tony63 | 0:ed0fa031f04b | 91 | //.................................................................. |
tony63 | 0:ed0fa031f04b | 92 | m1=0; |
tony63 | 0:ed0fa031f04b | 93 | m2=0; |
tony63 | 0:ed0fa031f04b | 94 | //....termina apertura de puerta |
tony63 | 0:ed0fa031f04b | 95 | for(j=0;j<k;j++){// |
tony63 | 0:ed0fa031f04b | 96 | //.....................acciona plunger pico......................... |
tony63 | 0:ed0fa031f04b | 97 | m3=1; |
tony63 | 0:ed0fa031f04b | 98 | m4=0; |
tony63 | 0:ed0fa031f04b | 99 | for(i=0;i<8;i++){ |
tony63 | 0:ed0fa031f04b | 100 | bird.printf("%c", cucu1[i]); |
tony63 | 0:ed0fa031f04b | 101 | } |
tony63 | 0:ed0fa031f04b | 102 | |
tony63 | 0:ed0fa031f04b | 103 | wait(1); |
tony63 | 0:ed0fa031f04b | 104 | //...............se desenergiza el plunger pico..................... |
tony63 | 0:ed0fa031f04b | 105 | m3=0; |
tony63 | 0:ed0fa031f04b | 106 | m4=0; |
tony63 | 0:ed0fa031f04b | 107 | } |
tony63 | 0:ed0fa031f04b | 108 | //..............se sierra la puerta..termino de sonar el cucu....... |
tony63 | 0:ed0fa031f04b | 109 | m1=0; |
tony63 | 0:ed0fa031f04b | 110 | m2=1; |
tony63 | 0:ed0fa031f04b | 111 | closed();//...sonido de purta cerrada........................... |
tony63 | 0:ed0fa031f04b | 112 | wait(1); |
tony63 | 0:ed0fa031f04b | 113 | m1=0; |
tony63 | 0:ed0fa031f04b | 114 | m2=0; //desenergiza puerta para ahorrar bateria................ |
tony63 | 0:ed0fa031f04b | 115 | slp(); |
tony63 | 0:ed0fa031f04b | 116 | wait(1); |
tony63 | 0:ed0fa031f04b | 117 | |
tony63 | 0:ed0fa031f04b | 118 | } |
tony63 | 0:ed0fa031f04b | 119 | |
tony63 | 0:ed0fa031f04b | 120 | int main( ){ |
tony63 | 0:ed0fa031f04b | 121 | led2=0; |
tony63 | 0:ed0fa031f04b | 122 | wait(1); |
tony63 | 0:ed0fa031f04b | 123 | led2=1; |
tony63 | 0:ed0fa031f04b | 124 | m1=0; |
tony63 | 0:ed0fa031f04b | 125 | m2=0; |
tony63 | 0:ed0fa031f04b | 126 | m3=0; |
tony63 | 0:ed0fa031f04b | 127 | m4=0; |
tony63 | 0:ed0fa031f04b | 128 | button.rise(&up); // enlaza la señal del reloj con una interupcion para el flanco de subida |
tony63 | 0:ed0fa031f04b | 129 | button.fall(&dw); // enlaza la señal del reloj con una interupcion para el flanco de caida |
tony63 | 0:ed0fa031f04b | 130 | while(1) { |
tony63 | 0:ed0fa031f04b | 131 | if(T>10){ |
tony63 | 0:ed0fa031f04b | 132 | ++k; |
tony63 | 0:ed0fa031f04b | 133 | if(k>12){ |
tony63 | 0:ed0fa031f04b | 134 | k=1; |
tony63 | 0:ed0fa031f04b | 135 | } |
tony63 | 0:ed0fa031f04b | 136 | cucu(k); |
tony63 | 0:ed0fa031f04b | 137 | pc.printf("T=%f,",T); |
tony63 | 0:ed0fa031f04b | 138 | pc.printf("k=%d,",k); |
tony63 | 0:ed0fa031f04b | 139 | |
tony63 | 0:ed0fa031f04b | 140 | T=0; |
tony63 | 0:ed0fa031f04b | 141 | |
tony63 | 0:ed0fa031f04b | 142 | |
tony63 | 0:ed0fa031f04b | 143 | } |
tony63 | 0:ed0fa031f04b | 144 | |
tony63 | 0:ed0fa031f04b | 145 | } |
tony63 | 0:ed0fa031f04b | 146 | } |
tony63 | 0:ed0fa031f04b | 147 | |
tony63 | 0:ed0fa031f04b | 148 |