Contains the main execution of the clock uses headers to import functions

Dependencies:   RTC-DS1307 SPI_TFT_ILI9341 TFT_fonts mbed tsi_sensor

Fork of TFT_Mikroelectronika_IL9341_sketchpad by Oxford CWM Team

Committer:
Owenmatthewmcgowan
Date:
Fri May 26 09:37:06 2017 +0000
Revision:
49:243b5e826228
Parent:
48:76ac309a2bd9
merge;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mlin 38:3fe3bafbf0c7 1 int ana_clock_press(){
mlin 38:3fe3bafbf0c7 2 int x = readX();
mlin 38:3fe3bafbf0c7 3 int y = readY();
Owenmatthewmcgowan 42:5d9ccb16c8ef 4 //setting x,y variables from TFT input
mlin 38:3fe3bafbf0c7 5 if (touching == 1) {
mlin 38:3fe3bafbf0c7 6
Owenmatthewmcgowan 42:5d9ccb16c8ef 7
mlin 38:3fe3bafbf0c7 8 if (x > 0 && x < 50 && y > 0 & y < 50) // side button 1 (clock state)
mlin 38:3fe3bafbf0c7 9 {
mlin 38:3fe3bafbf0c7 10 //set desired state to 1
mlin 38:3fe3bafbf0c7 11 return 1;
mlin 38:3fe3bafbf0c7 12 }
mlin 38:3fe3bafbf0c7 13 else if (x > 0 && x < 50 && y > 50 & y < 100) //side button 2 (change time)
mlin 38:3fe3bafbf0c7 14 {
mlin 38:3fe3bafbf0c7 15 //set desired state to 2
mlin 38:3fe3bafbf0c7 16 return 2;
mlin 38:3fe3bafbf0c7 17 }
mlin 38:3fe3bafbf0c7 18 else if (x > 0 && x < 50 && y > 100 && y < 150) // side button 3
mlin 38:3fe3bafbf0c7 19 {
mlin 38:3fe3bafbf0c7 20 //set desired state to 3
mlin 38:3fe3bafbf0c7 21 return 3;
mlin 38:3fe3bafbf0c7 22 }
mlin 38:3fe3bafbf0c7 23 else if (x > 0 && x < 50 && y > 150 && y < 200) // side button 4
mlin 38:3fe3bafbf0c7 24 {
mlin 38:3fe3bafbf0c7 25 //set desired state to 4
Owenmatthewmcgowan 48:76ac309a2bd9 26 f_cycle = !f_cycle;
Owenmatthewmcgowan 48:76ac309a2bd9 27 f_cycle_secs = tm_c.sec;
Owenmatthewmcgowan 48:76ac309a2bd9 28 // return 4;
mlin 40:05798eeadd02 29
mlin 38:3fe3bafbf0c7 30 }else if (x > 0 && x < 50 && y > 200 && y < 240) // button home
mlin 38:3fe3bafbf0c7 31 {
mlin 38:3fe3bafbf0c7 32 //set desired state to 0
mlin 38:3fe3bafbf0c7 33 return 0;
mlin 38:3fe3bafbf0c7 34 }
mlin 38:3fe3bafbf0c7 35 else if (x > 250 && x < 320 && y > 0 && y < 200) // alarm button on or off
mlin 38:3fe3bafbf0c7 36 {
mlin 38:3fe3bafbf0c7 37 //set desired state to 5
mlin 38:3fe3bafbf0c7 38 f_alarm = !(f_alarm);
mlin 38:3fe3bafbf0c7 39 f_alarm_sound = false;
mlin 38:3fe3bafbf0c7 40 return -1;
mlin 38:3fe3bafbf0c7 41 }
mlin 38:3fe3bafbf0c7 42 }
mlin 38:3fe3bafbf0c7 43 return -1;
mlin 38:3fe3bafbf0c7 44 }
Owenmatthewmcgowan 42:5d9ccb16c8ef 45 //Testing where screen has been pushed using TFT input and setting state accordingly
mlin 38:3fe3bafbf0c7 46
mlin 38:3fe3bafbf0c7 47
mlin 38:3fe3bafbf0c7 48
mlin 38:3fe3bafbf0c7 49 void runanaclock()
mlin 38:3fe3bafbf0c7 50 {
mlin 38:3fe3bafbf0c7 51 DigitalOut gnd(PTA4) ;
mlin 38:3fe3bafbf0c7 52 PwmOut buzzer(PTA5);
Owenmatthewmcgowan 42:5d9ccb16c8ef 53 //setting low/high pins across buzzer at PWM output
mlin 38:3fe3bafbf0c7 54 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};
mlin 38:3fe3bafbf0c7 55 //frequency array
mlin 38:3fe3bafbf0c7 56 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};
Owenmatthewmcgowan 42:5d9ccb16c8ef 57 //pulse duration array
mlin 38:3fe3bafbf0c7 58 int i =0;
mlin 38:3fe3bafbf0c7 59 int last_h = 0;
mlin 38:3fe3bafbf0c7 60 int last_m = 0;
mlin 38:3fe3bafbf0c7 61 draw_state(2);
mlin 38:3fe3bafbf0c7 62 while (f_state == 2){
mlin 38:3fe3bafbf0c7 63 read_time();
mlin 38:3fe3bafbf0c7 64 TFT.set_font((unsigned char*) Arial24x23); //coverup
mlin 38:3fe3bafbf0c7 65
mlin 38:3fe3bafbf0c7 66 if(f_alarm && tm_c.hour == tm_a_hr && tm_c.min == tm_a_min && tm_c.sec < 3){
mlin 38:3fe3bafbf0c7 67 f_alarm_sound = true;
mlin 38:3fe3bafbf0c7 68 }
Owenmatthewmcgowan 42:5d9ccb16c8ef 69 //if testing for both alarm flag and checking current time against alarm to flag the alarm sound
mlin 38:3fe3bafbf0c7 70
mlin 38:3fe3bafbf0c7 71 if (last_h != tm_c.hour && last_m != tm_c.min){
mlin 38:3fe3bafbf0c7 72 draw_hands( 150, 100 , 90 , last_m , last_h ,Black) ;
mlin 38:3fe3bafbf0c7 73 draw_hands( 150, 100 , 90 , tm_c.min, tm_c.hour ,White) ;
mlin 38:3fe3bafbf0c7 74 last_h = tm_c.hour;
mlin 38:3fe3bafbf0c7 75 last_m = tm_c.min;
mlin 38:3fe3bafbf0c7 76 }
mlin 38:3fe3bafbf0c7 77
mlin 38:3fe3bafbf0c7 78
mlin 38:3fe3bafbf0c7 79 if (f_alarm_sound)
mlin 38:3fe3bafbf0c7 80 {
mlin 38:3fe3bafbf0c7 81 i = i % 26;
mlin 38:3fe3bafbf0c7 82 i++ ;
mlin 38:3fe3bafbf0c7 83 buzzer.period(1/(frequency[i])); // set PWM period
mlin 38:3fe3bafbf0c7 84 buzzer=0.5;
mlin 38:3fe3bafbf0c7 85 wait(0.1*beat[i]);
Owenmatthewmcgowan 42:5d9ccb16c8ef 86 //hold for 0.1*beat period
mlin 38:3fe3bafbf0c7 87 } else buzzer = 0;
mlin 38:3fe3bafbf0c7 88 TFT.set_orientation(0);
mlin 38:3fe3bafbf0c7 89 TFT.set_font((unsigned char*) Arial24x23);
mlin 38:3fe3bafbf0c7 90 if (f_alarm) {
mlin 38:3fe3bafbf0c7 91
mlin 38:3fe3bafbf0c7 92 TFT.locate(65,290);
mlin 38:3fe3bafbf0c7 93 TFT.printf("%d",tm_a_hr);
mlin 38:3fe3bafbf0c7 94 TFT.locate(155,290);
mlin 38:3fe3bafbf0c7 95 TFT.printf("%d",tm_a_min);
mlin 38:3fe3bafbf0c7 96 }
mlin 38:3fe3bafbf0c7 97 else
mlin 38:3fe3bafbf0c7 98 {
mlin 38:3fe3bafbf0c7 99 TFT.locate(65,290);
mlin 38:3fe3bafbf0c7 100 TFT.printf(" ");
mlin 38:3fe3bafbf0c7 101 TFT.locate(155,290);
mlin 38:3fe3bafbf0c7 102 TFT.printf(" ");
mlin 38:3fe3bafbf0c7 103 }
mlin 38:3fe3bafbf0c7 104 TFT.set_orientation(1);
mlin 38:3fe3bafbf0c7 105 TFT.locate(70,210);
mlin 38:3fe3bafbf0c7 106 TFT.printf("%d / %d / %d ", tm_c.date, tm_c.mon, tm_c.year);
mlin 38:3fe3bafbf0c7 107 wait(0.2);
mlin 38:3fe3bafbf0c7 108 /* TFT.locate(160,210);
mlin 38:3fe3bafbf0c7 109 TFT.printf("%d",tm_c.mon);
mlin 38:3fe3bafbf0c7 110 TFT.locate(220,210);
mlin 38:3fe3bafbf0c7 111 TFT.printf("%d",tm_c.year); */
mlin 40:05798eeadd02 112 if (f_cycle){
Owenmatthewmcgowan 48:76ac309a2bd9 113 if ((f_cycle_secs + f_cycle_wait) == tm_c.sec){
mlin 40:05798eeadd02 114 f_state = 1;
Owenmatthewmcgowan 48:76ac309a2bd9 115 f_cycle_secs = tm_c.sec;
Owenmatthewmcgowan 48:76ac309a2bd9 116 }
mlin 40:05798eeadd02 117 }
mlin 40:05798eeadd02 118 switch (ana_clock_press()){
mlin 38:3fe3bafbf0c7 119 case (-1): break;
mlin 38:3fe3bafbf0c7 120 case (0): f_state = 1; break;
mlin 38:3fe3bafbf0c7 121 case (1): f_state = 1; break;
mlin 38:3fe3bafbf0c7 122 case (2): f_state = 3; break;
mlin 38:3fe3bafbf0c7 123 case (3): f_state = 4; break;
mlin 40:05798eeadd02 124 case (4): f_state = 5; break;
mlin 38:3fe3bafbf0c7 125 }
mlin 40:05798eeadd02 126
mlin 38:3fe3bafbf0c7 127 }
mlin 38:3fe3bafbf0c7 128 }