h

Dependencies:   QEI RTC-DS1307 TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
Gambetica
Date:
Wed Nov 29 01:30:37 2017 +0000
Commit message:
h

Changed in this revision

DebouncedIn.cpp Show annotated file Show diff for this revision Revisions of this file
DebouncedIn.h Show annotated file Show diff for this revision Revisions of this file
QEI.lib Show annotated file Show diff for this revision Revisions of this file
RTC-DS1307.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
debug.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DebouncedIn.cpp	Wed Nov 29 01:30:37 2017 +0000
@@ -0,0 +1,93 @@
+#include "DebouncedIn.h"
+#include "mbed.h"
+
+/*
+ * Constructor
+ */
+DebouncedIn::DebouncedIn(PinName in) 
+    : _in(in) {    
+        
+    // reset all the flags and counters    
+    _samples = 0;
+    _output = 0;
+    _output_last = 0;
+    _rising_flag = 0;
+    _falling_flag = 0;
+    _state_counter = 0;
+    
+    // Attach ticker
+    _ticker.attach(this, &DebouncedIn::_sample, 0.005);     
+}
+  
+void DebouncedIn::_sample() {
+
+    // take a sample
+    _samples = _samples >> 1; // shift left
+      
+    if (_in) {
+        _samples |= 0x80;
+    }  
+      
+    // examine the sample window, look for steady state
+    if (_samples == 0x00) {
+        _output = 0;
+    } 
+    else if (_samples == 0xFF) {
+        _output = 1;
+    }
+
+
+    // Rising edge detection
+    if ((_output == 1) && (_output_last == 0)) {
+        _rising_flag++;
+        _state_counter = 0;
+    }
+
+    // Falling edge detection
+    else if ((_output == 0) && (_output_last == 1)) {
+        _falling_flag++;
+        _state_counter = 0;
+    }
+    
+    // steady state
+    else {
+        _state_counter++;
+    }
+    
+   // update the output
+    _output_last = _output;
+    
+}
+
+
+
+// return number of rising edges
+int DebouncedIn::rising(void) {
+    int return_value = _rising_flag; 
+    _rising_flag = 0;
+    return(return_value);
+}
+
+// return number of falling edges
+int DebouncedIn::falling(void) {
+    int return_value = _falling_flag; 
+    _falling_flag = 0;
+    return(return_value);
+}
+
+// return number of ticsk we've bene steady for
+int DebouncedIn::steady(void) {
+return(_state_counter);
+}
+
+// return the debounced status
+int DebouncedIn::read(void) {
+    return(_output);
+}
+
+// shorthand for read()
+DebouncedIn::operator int() {
+    return read();
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DebouncedIn.h	Wed Nov 29 01:30:37 2017 +0000
@@ -0,0 +1,31 @@
+#include "mbed.h"
+
+    class DebouncedIn {
+        public:      
+             DebouncedIn(PinName in);
+
+             int read (void);
+             operator int();
+              
+             int rising(void);
+             int falling(void);
+             int steady(void);
+              
+        private :    
+               // objects
+               DigitalIn _in;    
+               Ticker _ticker;
+
+               // function to take a sample, and update flags
+               void _sample(void);
+
+               // counters and flags
+               int _samples;
+               int _output;
+               int _output_last;
+               int _rising_flag;
+               int _falling_flag;
+               int _state_counter;
+
+    };
+    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Wed Nov 29 01:30:37 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTC-DS1307.lib	Wed Nov 29 01:30:37 2017 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/leihen/code/RTC-DS1307/#5627b407e097
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Nov 29 01:30:37 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/javiernegrette/code/TextLCD/#419979c1e228
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debug.h	Wed Nov 29 01:30:37 2017 +0000
@@ -0,0 +1,16 @@
+#ifndef __DEBUG_H__
+#define __DEBUG_H__
+
+
+#ifdef DEBUG
+#define INFO(x, ...) std::printf("[INFO: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
+#define WARN(x, ...) std::printf("[WARN: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
+#define ERR(x, ...) std::printf("[ERR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
+#else
+#define INFO(x, ...)
+#define WARN(x, ...)
+#define ERR(x, ...)
+#endif
+
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 29 01:30:37 2017 +0000
@@ -0,0 +1,299 @@
+// A continuación definimos las librerias necesarias para la ejecución de este programa
+#include "mbed.h"
+#include "Rtc_Ds1307.h"                 //Libreria para rtc
+#include "TextLCD.h"
+#include "DebouncedIn.h"
+#include "QEI.h"
+#include "debug.h"
+
+//Pines para el rtc
+Rtc_Ds1307 rtc (PTE0,PTE1);             //Definimos el DS1307
+
+//PINES DEL ENCODER Y LCD
+TextLCD lcd(PTB8, PTB9,PTB10,PTB11,PTE2, PTE3); //Puertos LCD rs, e, d4, d5, d6, d7
+QEI Encoder (PTA1, PTA2, NC, 624);               //Puertos de la tarjeta asignados para el Encoder
+
+//Definicion del puerto serial
+//Serial pc(USBTX, USBRX, "pc");          //Definimos la cominucacion serial
+
+DigitalOut led1(LED1);      //led de cambio de posición
+DigitalOut led2(LED2);      //led incremento de parámetros
+DigitalOut led3(LED3);      //led decremento de parámetros
+
+//BOTON DEL ENCODER
+DebouncedIn bot1(PTC17);    //cambiar la posición 
+
+DebouncedIn P2(PTC13);    //SET
+ 
+char buffer[128];
+char buffer2[128];
+int readptr = 0;
+int readptr2 = 0;
+char c,c2;
+int Config;
+int dia1=0,hora1=0,minuto1=0,on1=0;
+int dia2=0,hora2=0,minuto2=0,on2=0;
+int dia3=0,hora3=0,minuto3=0,on3=0;
+int dia4=0,hora4=0,minuto4=0,on4=0;
+int dia5=0,hora5=0,minuto5=0,on5=0;
+int dia6=0,hora6=0,minuto6=0,on6=0;
+int dia7=0,hora7=0,minuto7=0,on7=0;
+int dialarm;
+int bandera=0;
+int C1=0x0E;                // Muestra el cursor
+// 0x18;                // desplazamiento izquierda
+// 0x1A;                // desplazamiento derecha
+int C4=0x0C;
+
+int AT=0;
+int i=0;
+int j=1;
+int M2;
+char Mm[30];
+char Dd[30];
+char Hh[30];
+char MIN[30];
+char SEG[30];
+int valor;
+int val;
+//------------------------------------------------------------------------------
+int a,d,d2,M,min,h,seg,b,k; // indice de la variable
+int YE=2015;
+
+int p=0;
+int main() {
+    Rtc_Ds1307::Time_rtc tm = {};
+    led1=led2=led3=1;
+    lcd.printf("ALARMAS");
+    wait(1.5);
+    lcd.cls();
+    
+    
+   
+     //Inicio del ciclo
+     
+                 while(1) {  if (bot1==0 && d==0 && M==0 && YE==2015 && h==0 && min==0 && seg==0) 
+                             {AT=1;  
+                               }
+                                                
+                             if (AT==1){  
+                                                if(p==1){
+                                                lcd.cls();       //limpio la pantalla  
+                                                lcd.locate(5,1);
+                                                lcd.printf("SET UP");
+                                                wait(0.5);
+                                                lcd.cls();
+                                                  p=2;    
+                                                                                            
+                                                }
+                            
+                            
+                                            if (p==2){
+                                               
+                                                                    if (bot1.falling()) {            //----------------- Aumenta de posición el cursor a la primera línea de menu
+                                                                    led1=0;
+                                                                    wait(.15); 
+                                                                    led1=1;
+                                                                    ++a;
+                                                                    }
+                                                               if (p==2){     
+                                               valor = Encoder.getPulses();  }  //------------- Asigna el valor de los pulsos del encoder a una variable llamada "valor"                                                
+                                                                                                        
+                                                               
+                                                    switch(a) {
+                                                        case 0:
+                                                        lcd.printf("FECHA");
+                                                        wait(0.5);
+                                                        lcd.cls();
+                                                        break;
+                                        //CONFIGURACION DE LA FECHA
+                                                    case 1:
+                                                    
+                                                   //Dia
+                                                    tm.date = tm.date + valor;                //------------- Asigna el valor del encoder al parámetro dia y tiene en cuenta el valor anterior
+                                                    Encoder.reset();                //------------- Resetea el valor del encoder
+                                                    if (tm.date<=0){
+                                                        tm.date=1;                       //------------- No se admite valores negativos
+                                                        }
+                                                    if (tm.date>31){                      //Limito el valor del dia;
+                                                        tm.date=31;
+                                                        }
+                                                    
+                                                    lcd.locate(2,0);                //------------- Ubica e imprime el parámetro dia en la pantalla LCD
+                                                    lcd.printf("D",tm.date);
+                                                    lcd.locate(3,0);
+                                                    lcd.printf(":%d",tm.date);                        
+                                                    wait(0.15);
+                                   
+                                                    if (bot1.falling() && tm.date>0) {       //--------------Aumenta de posición el cursor a la segunda línea de menu
+                                                            a=2;
+                                                            led1=0;
+                                                            wait(.15); 
+                                                            led1=1;
+                                                            Encoder.reset();            //------------- Resetea el valor del encoder
+                                                            }
+                                                        break; 
+                                                    //Mes
+                                                    case 2:
+                                
+                                                    M = M + valor;        //------------- Asigna el valor del encoder al parámetro mes y tiene en cuenta el valor anterior
+                                                    Encoder.reset();        //------------- Resetea el valor del encoder
+                                                    if (M<=0){
+                                                    M=1;                   //------------- No se admite valores negativos
+                                                    }
+                                                    if (M>12){M =12;}  //Limito el valor de mes
+                                                    tm.mon=M;
+                                                    lcd.locate(10,0);       //------------- Ubica e imprime el parámetro "mes" en la pantalla LCD
+                                                    lcd.printf("M",tm.mon);
+                                                    lcd.locate(11,0);
+                                                    lcd.printf(":%d",tm.mon);                        
+                                                    wait(0.15);
+                                   
+                                                    if (bot1.falling()&& M>=1 && tm.date>=1 ) { //--------------Aumenta de posición el cursor a la tercera línea de menu    
+                                                                      
+                                    
+                                                        a=3;
+                                                        led1=0;
+                                                        wait(.15); 
+                                                        led1=1;
+                                                        Encoder.reset();      //------------- Resetea el valor del encoder
+                                                        }
+                                                    break; 
+                                         //AÑO           
+                                        case 3:
+                                        
+                                        YE = YE + valor;  //------------- Asigna el valor del encoder al parámetro año y tiene en cuenta el valor anterior
+                                        Encoder.reset();  //------------- Resetea el valor del encoder
+                                        if (YE<2015){
+                                        YE=2015;             //------------- No se admite valores negativos
+                                        }
+                                        if (YE>2030){ YE=2030;}  //Limito el valor de año
+                                        tm.year=YE;
+                                        lcd.locate(2,1);  //------------- Ubica e imprime el parámetro "año" en la pantalla LCD
+                                        lcd.printf("A",tm.year);
+                                        lcd.locate(3,1);
+                                        lcd.printf(":%d",tm.year);                                            
+                                        wait(0.15);
+                                        
+                                           if (bot1.falling()&& tm.date>0 && M>0 && YE>2015) { //--------------Aumenta de posición el cursor a la cuarta línea de menu         
+                                                                                                                              
+                                            a=4;
+                                            led1=0;
+                                            wait(.15);
+                                            led1=1;
+                                            Encoder.reset();    //------------- Resetea el valor del encoder
+                                            
+                                            }
+                                        break;
+                                           case 4:
+                                           lcd.cls(); 
+                                            lcd.printf("HORA");
+                                             wait(0.5);
+                                            lcd.cls();
+                                           if (bot1.falling()){
+                                           a=5;
+                                           }
+                                                break;
+                                        //Configuracion de la hora         
+                                            //HORA
+                                                case 5:
+                                                
+                                                h = h + valor; //------------- Asigna el valor del encoder al parámetro hora y tiene en cuenta el valor anterior
+                                                Encoder.reset(); //------------- Resetea el valor del encoder
+                                                if (h<0){
+                                                h=0;            //------------- No se admite valores negativos
+                                                }
+                                                if (h>23){ h=23;}   //Limito el valor de hora
+                                                tm.hour=h;
+                                                lcd.locate(2,0);                //------------- Ubica e imprime el parámetro "hora" en la pantalla LCD
+                                                lcd.printf("h=",tm.hour);
+                                                lcd.locate(3,0);
+                                                
+                                                    lcd.printf(":%d",tm.hour);                        
+                                                    wait(0.15);
+                                            
+                                                if (bot1.falling()&& h>0 ) {  //--------------Aumenta de posición el cursor a la cuarta línea de menu    
+                                                    a=6;
+                                                    led1=0;
+                                                    wait(.15); 
+                                                    led1=1;
+                                                    Encoder.reset();       //------------- Resetea el valor del encoder
+                                                    }  
+                                                   break;                                 
+                                                    
+                                            //Minutos
+                                            case 6:
+                                                min = min + valor; //------------- Asigna el valor del encoder al parámetro min y tiene en cuenta el valor anterior
+                                                Encoder.reset(); //------------- Resetea el valor del encoder
+                                                if (min<=0){
+                                                min=0;            //------------- No se admite valores negativos
+                                                }
+                                                if (min>61){
+                                                    min=60;}
+                                                    tm.min=min;
+                                                lcd.locate(10,0);       //------------- Ubica e imprime el parámetro "min" en la pantalla LCD
+                                                lcd.printf("m",&tm.min);
+                                                lcd.locate(11,0);
+                                                lcd.printf(":%d",&tm.min);                        
+                                                wait(0.15);    
+                                                if (bot1.falling()&& h>=0 && min>=0) {  //--------------Aumenta de posición el cursor a la cuarta línea de menu    
+                                                    a=7;
+                                                    led1=0;
+                                                    wait(.15); 
+                                                    led1=1;
+                                                    Encoder.reset();       //------------- Resetea el valor del encoder
+                                                    }  
+                                                   break;      
+                                              //Segundos     
+                                                case 7:
+                                                seg = seg + valor; //------------- Asigna el valor del encoder al parámetro seg y tiene en cuenta el valor anterior
+                                                Encoder.reset(); //------------- Resetea el valor del encoder
+                                                if (seg<=0){
+                                                seg=0;            //------------- No se admite valores negativos
+                                                } 
+                                                 if (seg>61){
+                                                    seg=60;}    
+                                                    tm.sec=seg;
+                                                lcd.locate(2,1);  //------------- Ubica e imprime el parámetro "seg" en la pantalla LCD
+                                                lcd.printf("s",seg);
+                                                lcd.locate(3,1);
+                                                lcd.printf(":%d",&tm.sec);                                            
+                                                wait(0.15);
+                                        
+                                           if (bot1.falling()&& h>=0 && min>=0 && seg>0) { //--------------Aumenta de posición el cursor a la cuarta línea de menu         
+                                                                                                                              
+                                            a=8;
+                                            led1=0;
+                                            wait(.15); 
+                                            led1=1;
+                                            p=3;
+                                            
+                                            Encoder.reset();    //------------- Resetea el valor del encoder
+                                            }
+                                                                                      
+                                            
+                                            if (p==3){    
+                                                                                 
+                                         lcd.cls(); 
+                                        //Fecha:
+                                        lcd.locate(0,0);
+                                      lcd.printf("F=%d/%d/%d",&tm.date,&tm.mon,&tm.year);
+                                        //Hora
+                                      lcd.locate(0,1);
+                                       lcd.printf("H=%d:%d:%d",&tm.hour,&tm.min,&tm.sec); 
+                                                                                                                 
+                                                }
+                                   
+                                                }                            
+                                            
+                                                                                      
+                                            
+                                            
+                                            
+                                              }
+                                                              }
+                                                               }
+                 
+           
+                                         
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Nov 29 01:30:37 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e7ca05fa8600
\ No newline at end of file