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:
Thu May 25 10:58:02 2017 +0000
Revision:
19:4c30c3182e04
Parent:
17:356a299d3224
Child:
29:684e2a3e17b5
working demo of clock

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Owenmatthewmcgowan 19:4c30c3182e04 1 int digital_clock_press(){
mlin 16:3cb9b1fbc039 2 int x = readX();
mlin 16:3cb9b1fbc039 3 int y = readY();
mlin 16:3cb9b1fbc039 4 if (touching == 1) {
mlin 16:3cb9b1fbc039 5 if (x > 0 && x < 50 && y > 0 & y < 50) // side button 1
mlin 16:3cb9b1fbc039 6 {
mlin 16:3cb9b1fbc039 7 //set desired state to 1
mlin 16:3cb9b1fbc039 8 return 1;
mlin 16:3cb9b1fbc039 9 }
mlin 16:3cb9b1fbc039 10 else if (x > 0 && x < 50 && y > 50 & y < 100) //side button 2
mlin 16:3cb9b1fbc039 11 {
mlin 16:3cb9b1fbc039 12 //set desired state to 2
mlin 16:3cb9b1fbc039 13 return 2;
mlin 16:3cb9b1fbc039 14 }
mlin 16:3cb9b1fbc039 15 else if (x > 0 && x < 50 && y > 100 && y < 150) // side button 3
mlin 16:3cb9b1fbc039 16 {
mlin 16:3cb9b1fbc039 17 //set desired state to 3
mlin 16:3cb9b1fbc039 18 return 3;
mlin 16:3cb9b1fbc039 19 }
mlin 16:3cb9b1fbc039 20 else if (x > 0 && x < 50 && y > 150 && y < 200) // side button 4
mlin 16:3cb9b1fbc039 21 {
mlin 16:3cb9b1fbc039 22 //set desired state to 4
mlin 16:3cb9b1fbc039 23 return 4;
mlin 17:356a299d3224 24 }else if (x > 0 && x < 50 && y > 200 && y < 240) // button home
mlin 16:3cb9b1fbc039 25 {
mlin 16:3cb9b1fbc039 26 //set desired state to 0
mlin 16:3cb9b1fbc039 27 return 0;
mlin 16:3cb9b1fbc039 28 }
Owenmatthewmcgowan 19:4c30c3182e04 29 else if (x > 140 && x < 320 && y > 100 && y < 200) // alarm button on or off
mlin 16:3cb9b1fbc039 30 {
mlin 16:3cb9b1fbc039 31 //set desired state to 5
mlin 17:356a299d3224 32 f_alarm = !(f_alarm);
mlin 17:356a299d3224 33 return -1;
mlin 16:3cb9b1fbc039 34 }
mlin 16:3cb9b1fbc039 35 }
mlin 16:3cb9b1fbc039 36 return -1;
mlin 16:3cb9b1fbc039 37 }
mlin 16:3cb9b1fbc039 38
mlin 16:3cb9b1fbc039 39
mlin 16:3cb9b1fbc039 40
mlin 16:3cb9b1fbc039 41
Owenmatthewmcgowan 19:4c30c3182e04 42 void runclock()
mlin 16:3cb9b1fbc039 43 {
mlin 16:3cb9b1fbc039 44 draw_state(1);
mlin 16:3cb9b1fbc039 45 while (f_state == 1){
Owenmatthewmcgowan 19:4c30c3182e04 46 read_time();
mlin 17:356a299d3224 47 TFT.set_font((unsigned char*) Arial24x23); //set alarm hour
Owenmatthewmcgowan 19:4c30c3182e04 48 if (tm_c.sec == 0){
Owenmatthewmcgowan 19:4c30c3182e04 49 TFT.locate(250,40);
Owenmatthewmcgowan 19:4c30c3182e04 50 TFT.printf(" ");
Owenmatthewmcgowan 19:4c30c3182e04 51 if (tm_c.min == 0){
Owenmatthewmcgowan 19:4c30c3182e04 52 TFT.locate(160,40);
Owenmatthewmcgowan 19:4c30c3182e04 53 printf("%d",tm_c.min);
Owenmatthewmcgowan 19:4c30c3182e04 54 if (tm_c.hour == 0)
Owenmatthewmcgowan 19:4c30c3182e04 55 {
Owenmatthewmcgowan 19:4c30c3182e04 56 TFT.locate(70,40);
Owenmatthewmcgowan 19:4c30c3182e04 57 printf("%d",tm_c.hour);
Owenmatthewmcgowan 19:4c30c3182e04 58 }
Owenmatthewmcgowan 19:4c30c3182e04 59 }
Owenmatthewmcgowan 19:4c30c3182e04 60 }
Owenmatthewmcgowan 19:4c30c3182e04 61
Owenmatthewmcgowan 19:4c30c3182e04 62
Owenmatthewmcgowan 19:4c30c3182e04 63
mlin 17:356a299d3224 64 TFT.locate(70,40);
mlin 17:356a299d3224 65 TFT.printf("%d",tm_c.hour);
mlin 17:356a299d3224 66 TFT.locate(160,40);
mlin 17:356a299d3224 67 TFT.printf("%d",tm_c.min);
mlin 17:356a299d3224 68 TFT.locate(250,40);
mlin 17:356a299d3224 69 TFT.printf("%d",tm_c.sec);
mlin 17:356a299d3224 70 TFT.locate(60,140);
mlin 17:356a299d3224 71 TFT.set_font((unsigned char*) Arial12x12);
mlin 17:356a299d3224 72 TFT.printf("%s",rtc.weekdayToString(tm_c.wday));
mlin 17:356a299d3224 73 TFT.set_font((unsigned char*) Arial24x23);
mlin 17:356a299d3224 74 if (f_alarm) {
Owenmatthewmcgowan 19:4c30c3182e04 75 TFT.locate(160,140);
Owenmatthewmcgowan 19:4c30c3182e04 76 TFT.printf("%d",tm_a_hr);
Owenmatthewmcgowan 19:4c30c3182e04 77 TFT.locate(250,140);
Owenmatthewmcgowan 19:4c30c3182e04 78 TFT.printf("%d",tm_a_min);
mlin 17:356a299d3224 79 }
mlin 17:356a299d3224 80 else
mlin 17:356a299d3224 81 {
mlin 17:356a299d3224 82 TFT.locate(160,140);
mlin 17:356a299d3224 83 TFT.printf(" ");
Owenmatthewmcgowan 19:4c30c3182e04 84 TFT.locate(250,140);
mlin 17:356a299d3224 85 TFT.printf(" ");
mlin 17:356a299d3224 86 }
Owenmatthewmcgowan 19:4c30c3182e04 87 TFT.locate(70,210);
Owenmatthewmcgowan 19:4c30c3182e04 88 TFT.printf("%d / %d / %d", tm_c.date, tm_c.mon, tm_c.year);
Owenmatthewmcgowan 19:4c30c3182e04 89 wait(0.2);
Owenmatthewmcgowan 19:4c30c3182e04 90 /* TFT.locate(160,210);
mlin 17:356a299d3224 91 TFT.printf("%d",tm_c.mon);
Owenmatthewmcgowan 19:4c30c3182e04 92 TFT.locate(220,210);
Owenmatthewmcgowan 19:4c30c3182e04 93 TFT.printf("%d",tm_c.year); */
Owenmatthewmcgowan 19:4c30c3182e04 94
mlin 17:356a299d3224 95 switch (digital_clock_press()){
mlin 17:356a299d3224 96 case (-1): break;
mlin 17:356a299d3224 97 case (0): f_state = 0; break;
mlin 17:356a299d3224 98 case (1): f_state = 2; break;
mlin 17:356a299d3224 99 case (2): f_state = 3; break;
mlin 17:356a299d3224 100 case (3): f_state = 4; break;
mlin 17:356a299d3224 101 }
mlin 17:356a299d3224 102 }
mlin 17:356a299d3224 103 }