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

Committer:
Owenmatthewmcgowan
Date:
Fri May 26 08:38:04 2017 +0000
Revision:
44:1c516642c34e
Parent:
42:5d9ccb16c8ef
Parent:
40:05798eeadd02
Child:
48:76ac309a2bd9
,.

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