IoT Ox / Mbed 2 deprecated MainSketch Featured

Dependencies:   RTC-DS1307 SPI_TFT_ILI9341 TFT_fonts mbed tsi_sensor

Fork of TFT_Mikroelectronika_IL9341_sketchpad by Oxford CWM Team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers analoglogic.h Source File

analoglogic.h

00001 int ana_clock_press(){
00002     int x = readX();
00003     int y = readY();
00004         //setting x,y variables from TFT input
00005     if (touching == 1) {
00006        
00007        
00008         if (x > 0 && x < 50 && y > 0 & y < 50) // side button 1 (clock state)
00009         {
00010             //set desired state to 1 
00011             return 1;
00012         }
00013         else if (x > 0 && x < 50 && y > 50 & y < 100) //side button 2 (change time)
00014         {
00015             //set desired state to 2 
00016             return 2;
00017         }
00018         else if (x > 0 && x < 50 && y > 100 && y < 150) // side button 3 
00019         {
00020             //set desired state to 3
00021             return 3;
00022         }
00023         else if (x > 0 && x < 50 && y > 150 && y < 200) // side button 4 
00024         {
00025             //set desired state to 4
00026             f_cycle = !f_cycle;
00027             f_cycle_secs = tm_c.sec;
00028           // return 4;
00029             
00030         }else if (x > 0 && x < 50 && y > 200 && y < 240) // button home
00031         {
00032             //set desired state to 0
00033             return 0;
00034         }
00035         else if (x > 250 && x < 320 && y >  0 && y < 200) // alarm button on or off
00036         {
00037             //set desired state to 5
00038             f_alarm = !(f_alarm);
00039             f_alarm_sound = false;
00040             return -1;
00041         }
00042     }
00043     return -1;
00044 }
00045     //Testing where screen has been pushed using TFT input and setting state accordingly
00046     
00047 
00048 
00049 void runanaclock()
00050 {
00051     DigitalOut gnd(PTA4) ;
00052     PwmOut buzzer(PTA5);
00053     //setting low/high pins across buzzer at PWM output
00054     float frequency[]={758, 758, 758, 955, 758, 638, 1276, 955, 1276, 1517, 1136, 1012, 1073, 1136, 1276, 758, 638, 568, 716, 638, 758, 955, 851, 1012, 955};
00055     //frequency array
00056     float beat[]={0.2, 0.4, 0.4, 0.2, 0.4, 0.8, 0.8, 0.6, 0.6, 0.6, 0.4, 0.4, 0.2, 0.4, 0.26, 0.26, 0.26, 0.4, 0.2, 0.4, 0.4, 0.2, 0.2, 0.2, 0.4};
00057     //pulse duration array
00058     int i =0;
00059     int last_h  = 0;
00060     int last_m = 0;
00061     draw_state(2);
00062     while (f_state == 2){
00063         read_time();
00064         TFT.set_font((unsigned char*) Arial24x23); //coverup
00065                 
00066         if(f_alarm && tm_c.hour == tm_a_hr && tm_c.min == tm_a_min && tm_c.sec < 3){
00067             f_alarm_sound = true;
00068         }
00069         //if testing for both alarm flag and checking current time against alarm to flag the alarm sound
00070                 
00071         if (last_h != tm_c.hour && last_m != tm_c.min){
00072             draw_hands( 150, 100 , 90 , last_m , last_h ,Black) ;
00073             draw_hands( 150, 100 , 90 , tm_c.min, tm_c.hour ,White) ;
00074             last_h = tm_c.hour;
00075             last_m = tm_c.min;
00076         }
00077         
00078       
00079         if (f_alarm_sound)
00080             {
00081                 i = i % 26;
00082                 i++ ;
00083                 buzzer.period(1/(frequency[i])); // set PWM period
00084                 buzzer=0.5;
00085                 wait(0.1*beat[i]);
00086             //hold for 0.1*beat period
00087             } else buzzer = 0;
00088         TFT.set_orientation(0);
00089         TFT.set_font((unsigned char*) Arial24x23);
00090         if (f_alarm) {
00091             
00092             TFT.locate(65,290);
00093             TFT.printf("%d",tm_a_hr);
00094             TFT.locate(155,290);    
00095             TFT.printf("%d",tm_a_min);    
00096         }
00097         else
00098         {
00099             TFT.locate(65,290);
00100             TFT.printf("   ");
00101            TFT.locate(155,290);    
00102            TFT.printf("   ");   
00103         }
00104         TFT.set_orientation(1);
00105         TFT.locate(70,210);
00106         TFT.printf("%d / %d / %d ", tm_c.date, tm_c.mon, tm_c.year);
00107         wait(0.2);
00108        /* TFT.locate(160,210);    
00109         TFT.printf("%d",tm_c.mon);    
00110         TFT.locate(220,210);    
00111         TFT.printf("%d",tm_c.year);     */
00112         if (f_cycle){
00113             if ((f_cycle_secs + f_cycle_wait) == tm_c.sec){
00114             f_state = 1;
00115             f_cycle_secs = tm_c.sec;
00116             }
00117         }
00118         switch (ana_clock_press()){
00119             case (-1): break;
00120             case (0): f_state = 1; break;
00121             case (1): f_state = 1; break;
00122             case (2): f_state = 3; break;
00123             case (3): f_state = 4; break;
00124             case (4): f_state = 5; break;
00125         }
00126         
00127     }
00128 }