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
Owenmatthewmcgowan 19:4c30c3182e04 1 int digital_clock_press(){
tunagonen 39:4b70d28cb273 2 int x = readX(); // read x location
tunagonen 39:4b70d28cb273 3 int y = readY(); // read y location
mlin 16:3cb9b1fbc039 4 if (touching == 1) {
mlin 31:3255668e6b08 5
Owenmatthewmcgowan 29:684e2a3e17b5 6 if (x > 0 && x < 50 && y > 0 & y < 50) // side button 1 (clock state)
mlin 16:3cb9b1fbc039 7 {
mlin 16:3cb9b1fbc039 8 //set desired state to 1
mlin 16:3cb9b1fbc039 9 return 1;
mlin 16:3cb9b1fbc039 10 }
Owenmatthewmcgowan 29:684e2a3e17b5 11 else if (x > 0 && x < 50 && y > 50 & y < 100) //side button 2 (change time)
mlin 16:3cb9b1fbc039 12 {
mlin 16:3cb9b1fbc039 13 //set desired state to 2
mlin 16:3cb9b1fbc039 14 return 2;
mlin 16:3cb9b1fbc039 15 }
mlin 16:3cb9b1fbc039 16 else if (x > 0 && x < 50 && y > 100 && y < 150) // side button 3
mlin 16:3cb9b1fbc039 17 {
mlin 16:3cb9b1fbc039 18 //set desired state to 3
mlin 16:3cb9b1fbc039 19 return 3;
mlin 16:3cb9b1fbc039 20 }
mlin 16:3cb9b1fbc039 21 else if (x > 0 && x < 50 && y > 150 && y < 200) // side button 4
mlin 16:3cb9b1fbc039 22 {
mlin 16:3cb9b1fbc039 23 //set desired state to 4
Owenmatthewmcgowan 48:76ac309a2bd9 24 f_cycle = !f_cycle;
Owenmatthewmcgowan 48:76ac309a2bd9 25 f_cycle_secs = tm_c.sec;
Owenmatthewmcgowan 48:76ac309a2bd9 26 //wait(0.5);
Owenmatthewmcgowan 48:76ac309a2bd9 27 // return 4;
mlin 40:05798eeadd02 28
mlin 17:356a299d3224 29 }else if (x > 0 && x < 50 && y > 200 && y < 240) // button home
mlin 16:3cb9b1fbc039 30 {
mlin 16:3cb9b1fbc039 31 //set desired state to 0
mlin 16:3cb9b1fbc039 32 return 0;
mlin 16:3cb9b1fbc039 33 }
Owenmatthewmcgowan 19:4c30c3182e04 34 else if (x > 140 && x < 320 && y > 100 && y < 200) // alarm button on or off
mlin 16:3cb9b1fbc039 35 {
mlin 16:3cb9b1fbc039 36 //set desired state to 5
mlin 17:356a299d3224 37 f_alarm = !(f_alarm);
tunagonen 39:4b70d28cb273 38 f_alarm_sound = false; // flag for the alarm sound
mlin 17:356a299d3224 39 return -1;
mlin 16:3cb9b1fbc039 40 }
mlin 16:3cb9b1fbc039 41 }
mlin 16:3cb9b1fbc039 42 return -1;
mlin 16:3cb9b1fbc039 43 }
mlin 16:3cb9b1fbc039 44
mlin 16:3cb9b1fbc039 45
mlin 16:3cb9b1fbc039 46
mlin 16:3cb9b1fbc039 47
tunagonen 39:4b70d28cb273 48 void runclock() // getting time from the clock
mlin 16:3cb9b1fbc039 49 {
tunagonen 39:4b70d28cb273 50 DigitalOut gnd(PTA4) ; // initiating buzzer
Owenmatthewmcgowan 32:56f59b79720c 51 PwmOut buzzer(PTA5);
Owenmatthewmcgowan 32:56f59b79720c 52 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};
Owenmatthewmcgowan 32:56f59b79720c 53 //frequency array
Owenmatthewmcgowan 32:56f59b79720c 54 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};
tunagonen 39:4b70d28cb273 55 //time intervals
mlin 38:3fe3bafbf0c7 56 int i =0;
mlin 38:3fe3bafbf0c7 57 int last = 0;
mlin 16:3cb9b1fbc039 58 draw_state(1);
mlin 16:3cb9b1fbc039 59 while (f_state == 1){
Owenmatthewmcgowan 19:4c30c3182e04 60 read_time();
mlin 38:3fe3bafbf0c7 61 TFT.set_font((unsigned char*) Arial24x23); //coverup
tunagonen 39:4b70d28cb273 62 if (tm_c.sec == 0){ //getting seconds and printing
Owenmatthewmcgowan 19:4c30c3182e04 63 TFT.locate(250,40);
Owenmatthewmcgowan 19:4c30c3182e04 64 TFT.printf(" ");
tunagonen 39:4b70d28cb273 65 if (tm_c.min == 0){ //getting minutes and printing
Owenmatthewmcgowan 19:4c30c3182e04 66 TFT.locate(160,40);
mlin 38:3fe3bafbf0c7 67 printf(" ");
tunagonen 39:4b70d28cb273 68 if (tm_c.hour == 0) //getting hours and printing
Owenmatthewmcgowan 19:4c30c3182e04 69 {
Owenmatthewmcgowan 19:4c30c3182e04 70 TFT.locate(70,40);
mlin 38:3fe3bafbf0c7 71 printf(" ");
Owenmatthewmcgowan 19:4c30c3182e04 72 }
Owenmatthewmcgowan 19:4c30c3182e04 73 }
Owenmatthewmcgowan 19:4c30c3182e04 74 }
Owenmatthewmcgowan 19:4c30c3182e04 75
Owenmatthewmcgowan 32:56f59b79720c 76 if(f_alarm && tm_c.hour == tm_a_hr && tm_c.min == tm_a_min && tm_c.sec < 3){
tunagonen 39:4b70d28cb273 77 f_alarm_sound = true; //alarm buzzes
Owenmatthewmcgowan 32:56f59b79720c 78 }
mlin 38:3fe3bafbf0c7 79
Owenmatthewmcgowan 32:56f59b79720c 80
tunagonen 39:4b70d28cb273 81 if (f_alarm_sound)
Owenmatthewmcgowan 32:56f59b79720c 82 {
Owenmatthewmcgowan 32:56f59b79720c 83 i = i % 26;
Owenmatthewmcgowan 32:56f59b79720c 84 i++ ;
Owenmatthewmcgowan 32:56f59b79720c 85 buzzer.period(1/(frequency[i])); // set PWM period
Owenmatthewmcgowan 32:56f59b79720c 86 buzzer=0.5;
Owenmatthewmcgowan 32:56f59b79720c 87 wait(0.1*beat[i]);
Owenmatthewmcgowan 32:56f59b79720c 88 //
Owenmatthewmcgowan 32:56f59b79720c 89 //hold for beat period ;
mlin 38:3fe3bafbf0c7 90 } else buzzer = 0;
mlin 17:356a299d3224 91 TFT.locate(70,40);
mlin 17:356a299d3224 92 TFT.printf("%d",tm_c.hour);
mlin 17:356a299d3224 93 TFT.locate(160,40);
mlin 17:356a299d3224 94 TFT.printf("%d",tm_c.min);
mlin 17:356a299d3224 95 TFT.locate(250,40);
mlin 17:356a299d3224 96 TFT.printf("%d",tm_c.sec);
mlin 17:356a299d3224 97 TFT.locate(60,140);
mlin 17:356a299d3224 98 TFT.set_font((unsigned char*) Arial12x12);
mlin 38:3fe3bafbf0c7 99 if (last != tm_c.wday) printf(" ");
mlin 38:3fe3bafbf0c7 100 last = tm_c.wday;
mlin 38:3fe3bafbf0c7 101 TFT.locate(60,140);
mlin 38:3fe3bafbf0c7 102 TFT.printf("%s",rtc.weekdayToString(tm_c.wday + 1));
mlin 17:356a299d3224 103 TFT.set_font((unsigned char*) Arial24x23);
mlin 17:356a299d3224 104 if (f_alarm) {
Owenmatthewmcgowan 19:4c30c3182e04 105 TFT.locate(160,140);
Owenmatthewmcgowan 19:4c30c3182e04 106 TFT.printf("%d",tm_a_hr);
Owenmatthewmcgowan 19:4c30c3182e04 107 TFT.locate(250,140);
Owenmatthewmcgowan 19:4c30c3182e04 108 TFT.printf("%d",tm_a_min);
mlin 17:356a299d3224 109 }
mlin 17:356a299d3224 110 else
mlin 17:356a299d3224 111 {
mlin 17:356a299d3224 112 TFT.locate(160,140);
mlin 17:356a299d3224 113 TFT.printf(" ");
Owenmatthewmcgowan 19:4c30c3182e04 114 TFT.locate(250,140);
mlin 17:356a299d3224 115 TFT.printf(" ");
mlin 17:356a299d3224 116 }
Owenmatthewmcgowan 19:4c30c3182e04 117 TFT.locate(70,210);
Owenmatthewmcgowan 19:4c30c3182e04 118 TFT.printf("%d / %d / %d", tm_c.date, tm_c.mon, tm_c.year);
Owenmatthewmcgowan 19:4c30c3182e04 119 wait(0.2);
Owenmatthewmcgowan 19:4c30c3182e04 120 /* TFT.locate(160,210);
mlin 17:356a299d3224 121 TFT.printf("%d",tm_c.mon);
Owenmatthewmcgowan 19:4c30c3182e04 122 TFT.locate(220,210);
Owenmatthewmcgowan 19:4c30c3182e04 123 TFT.printf("%d",tm_c.year); */
mlin 40:05798eeadd02 124 if (f_cycle){
Owenmatthewmcgowan 48:76ac309a2bd9 125 if ((f_cycle_secs + f_cycle_wait) == tm_c.sec){
mlin 40:05798eeadd02 126 f_state = 2;
Owenmatthewmcgowan 48:76ac309a2bd9 127 f_cycle_secs = tm_c.sec;
Owenmatthewmcgowan 48:76ac309a2bd9 128 }
mlin 40:05798eeadd02 129 }
mlin 17:356a299d3224 130 switch (digital_clock_press()){
mlin 17:356a299d3224 131 case (-1): break;
mlin 38:3fe3bafbf0c7 132 case (0): f_state = 1; break;
mlin 17:356a299d3224 133 case (1): f_state = 2; break;
mlin 17:356a299d3224 134 case (2): f_state = 3; break;
mlin 17:356a299d3224 135 case (3): f_state = 4; break;
mlin 40:05798eeadd02 136 case (4): f_state = 5; break;
mlin 17:356a299d3224 137 }
mlin 17:356a299d3224 138 }
mlin 17:356a299d3224 139 }