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

Revision:
38:3fe3bafbf0c7
Child:
40:05798eeadd02
Child:
42:5d9ccb16c8ef
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/analoglogic.h	Thu May 25 19:54:51 2017 +0000
@@ -0,0 +1,114 @@
+int ana_clock_press(){
+    int x = readX();
+    int y = readY();
+    if (touching == 1) {
+       
+        if (x > 0 && x < 50 && y > 0 & y < 50) // side button 1 (clock state)
+        {
+            //set desired state to 1 
+            return 1;
+        }
+        else if (x > 0 && x < 50 && y > 50 & y < 100) //side button 2 (change time)
+        {
+            //set desired state to 2 
+            return 2;
+        }
+        else if (x > 0 && x < 50 && y > 100 && y < 150) // side button 3 
+        {
+            //set desired state to 3
+            return 3;
+        }
+        else if (x > 0 && x < 50 && y > 150 && y < 200) // side button 4 
+        {
+            //set desired state to 4
+            return 4;
+        }else if (x > 0 && x < 50 && y > 200 && y < 240) // button home
+        {
+            //set desired state to 0
+            return 0;
+        }
+        else if (x > 250 && x < 320 && y >  0 && y < 200) // alarm button on or off
+        {
+            //set desired state to 5
+            f_alarm = !(f_alarm);
+            f_alarm_sound = false;
+            return -1;
+        }
+    }
+    return -1;
+}
+        
+    
+
+
+void runanaclock()
+{
+    DigitalOut gnd(PTA4) ;
+    PwmOut buzzer(PTA5);
+    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};
+    //frequency array
+    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};
+    int i =0;
+    int last_h  = 0;
+    int last_m = 0;
+    draw_state(2);
+    while (f_state == 2){
+        read_time();
+        TFT.set_font((unsigned char*) Arial24x23); //coverup
+                
+        if(f_alarm && tm_c.hour == tm_a_hr && tm_c.min == tm_a_min && tm_c.sec < 3){
+            f_alarm_sound = true;
+        }
+                
+        if (last_h != tm_c.hour && last_m != tm_c.min){
+            draw_hands( 150, 100 , 90 , last_m , last_h ,Black) ;
+            draw_hands( 150, 100 , 90 , tm_c.min, tm_c.hour ,White) ;
+            last_h = tm_c.hour;
+            last_m = tm_c.min;
+        }
+        
+      
+        if (f_alarm_sound)
+            {
+                i = i % 26;
+                i++ ;
+                buzzer.period(1/(frequency[i])); // set PWM period
+                buzzer=0.5;
+                wait(0.1*beat[i]);
+            //
+            //hold for beat period ;
+            } else buzzer = 0;
+        TFT.set_orientation(0);
+        TFT.set_font((unsigned char*) Arial24x23);
+        if (f_alarm) {
+            
+            TFT.locate(65,290);
+            TFT.printf("%d",tm_a_hr);
+            TFT.locate(155,290);    
+            TFT.printf("%d",tm_a_min);    
+        }
+        else
+        {
+            TFT.locate(65,290);
+            TFT.printf("   ");
+           TFT.locate(155,290);    
+           TFT.printf("   ");   
+        }
+        TFT.set_orientation(1);
+        TFT.locate(70,210);
+        TFT.printf("%d / %d / %d ", tm_c.date, tm_c.mon, tm_c.year);
+        wait(0.2);
+       /* TFT.locate(160,210);    
+        TFT.printf("%d",tm_c.mon);    
+        TFT.locate(220,210);    
+        TFT.printf("%d",tm_c.year);     */
+        
+        switch (digital_clock_press()){
+            case (-1): break;
+            case (0): f_state = 1; break;
+            case (1): f_state = 1; break;
+            case (2): f_state = 3; break;
+            case (3): f_state = 4; break;
+        }
+    }
+}
\ No newline at end of file