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 15:43:31 2017 +0000
Revision:
32:56f59b79720c
Parent:
31:3255668e6b08
Child:
38:3fe3bafbf0c7
alarm implemented

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 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
mlin 16:3cb9b1fbc039 24 return 4;
mlin 17:356a299d3224 25 }else if (x > 0 && x < 50 && y > 200 && y < 240) // button home
mlin 16:3cb9b1fbc039 26 {
mlin 16:3cb9b1fbc039 27 //set desired state to 0
mlin 16:3cb9b1fbc039 28 return 0;
mlin 16:3cb9b1fbc039 29 }
Owenmatthewmcgowan 19:4c30c3182e04 30 else if (x > 140 && x < 320 && y > 100 && y < 200) // alarm button on or off
mlin 16:3cb9b1fbc039 31 {
mlin 16:3cb9b1fbc039 32 //set desired state to 5
mlin 17:356a299d3224 33 f_alarm = !(f_alarm);
Owenmatthewmcgowan 32:56f59b79720c 34 f_alarm_sound = false;
mlin 17:356a299d3224 35 return -1;
mlin 16:3cb9b1fbc039 36 }
mlin 16:3cb9b1fbc039 37 }
mlin 16:3cb9b1fbc039 38 return -1;
mlin 16:3cb9b1fbc039 39 }
mlin 16:3cb9b1fbc039 40
mlin 16:3cb9b1fbc039 41
mlin 16:3cb9b1fbc039 42
mlin 16:3cb9b1fbc039 43
Owenmatthewmcgowan 19:4c30c3182e04 44 void runclock()
mlin 16:3cb9b1fbc039 45 {
Owenmatthewmcgowan 32:56f59b79720c 46 DigitalOut gnd(PTA4) ;
Owenmatthewmcgowan 32:56f59b79720c 47 PwmOut buzzer(PTA5);
Owenmatthewmcgowan 32:56f59b79720c 48 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 49 //frequency array
Owenmatthewmcgowan 32:56f59b79720c 50 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 32:56f59b79720c 51 int i =0
mlin 16:3cb9b1fbc039 52 draw_state(1);
mlin 16:3cb9b1fbc039 53 while (f_state == 1){
Owenmatthewmcgowan 19:4c30c3182e04 54 read_time();
mlin 17:356a299d3224 55 TFT.set_font((unsigned char*) Arial24x23); //set alarm hour
Owenmatthewmcgowan 19:4c30c3182e04 56 if (tm_c.sec == 0){
Owenmatthewmcgowan 19:4c30c3182e04 57 TFT.locate(250,40);
Owenmatthewmcgowan 19:4c30c3182e04 58 TFT.printf(" ");
Owenmatthewmcgowan 19:4c30c3182e04 59 if (tm_c.min == 0){
Owenmatthewmcgowan 19:4c30c3182e04 60 TFT.locate(160,40);
Owenmatthewmcgowan 19:4c30c3182e04 61 printf("%d",tm_c.min);
Owenmatthewmcgowan 19:4c30c3182e04 62 if (tm_c.hour == 0)
Owenmatthewmcgowan 19:4c30c3182e04 63 {
Owenmatthewmcgowan 19:4c30c3182e04 64 TFT.locate(70,40);
Owenmatthewmcgowan 19:4c30c3182e04 65 printf("%d",tm_c.hour);
Owenmatthewmcgowan 19:4c30c3182e04 66 }
Owenmatthewmcgowan 19:4c30c3182e04 67 }
Owenmatthewmcgowan 19:4c30c3182e04 68 }
Owenmatthewmcgowan 19:4c30c3182e04 69
Owenmatthewmcgowan 32:56f59b79720c 70 if(f_alarm && tm_c.hour == tm_a_hr && tm_c.min == tm_a_min && tm_c.sec < 3){
Owenmatthewmcgowan 32:56f59b79720c 71 f_alarm_sound = true;
Owenmatthewmcgowan 32:56f59b79720c 72 }
Owenmatthewmcgowan 32:56f59b79720c 73
Owenmatthewmcgowan 32:56f59b79720c 74 //int gnd = 0 ;
Owenmatthewmcgowan 32:56f59b79720c 75 if (f_alarm_sound)
Owenmatthewmcgowan 32:56f59b79720c 76 {
Owenmatthewmcgowan 32:56f59b79720c 77 i = i % 26;
Owenmatthewmcgowan 32:56f59b79720c 78 i++ ;
Owenmatthewmcgowan 32:56f59b79720c 79 buzzer.period(1/(frequency[i])); // set PWM period
Owenmatthewmcgowan 32:56f59b79720c 80 buzzer=0.5;
Owenmatthewmcgowan 32:56f59b79720c 81 wait(0.1*beat[i]);
Owenmatthewmcgowan 32:56f59b79720c 82 //
Owenmatthewmcgowan 32:56f59b79720c 83 //hold for beat period ;
Owenmatthewmcgowan 32:56f59b79720c 84 }
mlin 17:356a299d3224 85 TFT.locate(70,40);
mlin 17:356a299d3224 86 TFT.printf("%d",tm_c.hour);
mlin 17:356a299d3224 87 TFT.locate(160,40);
mlin 17:356a299d3224 88 TFT.printf("%d",tm_c.min);
mlin 17:356a299d3224 89 TFT.locate(250,40);
mlin 17:356a299d3224 90 TFT.printf("%d",tm_c.sec);
mlin 17:356a299d3224 91 TFT.locate(60,140);
mlin 17:356a299d3224 92 TFT.set_font((unsigned char*) Arial12x12);
mlin 31:3255668e6b08 93 TFT.printf("%s",tm_c.wday);
mlin 17:356a299d3224 94 TFT.set_font((unsigned char*) Arial24x23);
mlin 17:356a299d3224 95 if (f_alarm) {
Owenmatthewmcgowan 19:4c30c3182e04 96 TFT.locate(160,140);
Owenmatthewmcgowan 19:4c30c3182e04 97 TFT.printf("%d",tm_a_hr);
Owenmatthewmcgowan 19:4c30c3182e04 98 TFT.locate(250,140);
Owenmatthewmcgowan 19:4c30c3182e04 99 TFT.printf("%d",tm_a_min);
mlin 17:356a299d3224 100 }
mlin 17:356a299d3224 101 else
mlin 17:356a299d3224 102 {
mlin 17:356a299d3224 103 TFT.locate(160,140);
mlin 17:356a299d3224 104 TFT.printf(" ");
Owenmatthewmcgowan 19:4c30c3182e04 105 TFT.locate(250,140);
mlin 17:356a299d3224 106 TFT.printf(" ");
mlin 17:356a299d3224 107 }
Owenmatthewmcgowan 19:4c30c3182e04 108 TFT.locate(70,210);
Owenmatthewmcgowan 19:4c30c3182e04 109 TFT.printf("%d / %d / %d", tm_c.date, tm_c.mon, tm_c.year);
Owenmatthewmcgowan 19:4c30c3182e04 110 wait(0.2);
Owenmatthewmcgowan 19:4c30c3182e04 111 /* TFT.locate(160,210);
mlin 17:356a299d3224 112 TFT.printf("%d",tm_c.mon);
Owenmatthewmcgowan 19:4c30c3182e04 113 TFT.locate(220,210);
Owenmatthewmcgowan 19:4c30c3182e04 114 TFT.printf("%d",tm_c.year); */
Owenmatthewmcgowan 19:4c30c3182e04 115
mlin 17:356a299d3224 116 switch (digital_clock_press()){
mlin 17:356a299d3224 117 case (-1): break;
mlin 17:356a299d3224 118 case (0): f_state = 0; break;
mlin 17:356a299d3224 119 case (1): f_state = 2; break;
mlin 17:356a299d3224 120 case (2): f_state = 3; break;
mlin 17:356a299d3224 121 case (3): f_state = 4; break;
mlin 17:356a299d3224 122 }
mlin 17:356a299d3224 123 }
mlin 17:356a299d3224 124 }