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:
mlin
Date:
Thu May 25 19:54:51 2017 +0000
Revision:
38:3fe3bafbf0c7
Child:
40:05798eeadd02
Child:
42:5d9ccb16c8ef
Fixed Everythign But Pong

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();
mlin 38:3fe3bafbf0c7 4 if (touching == 1) {
mlin 38:3fe3bafbf0c7 5
mlin 38:3fe3bafbf0c7 6 if (x > 0 && x < 50 && y > 0 & y < 50) // side button 1 (clock state)
mlin 38:3fe3bafbf0c7 7 {
mlin 38:3fe3bafbf0c7 8 //set desired state to 1
mlin 38:3fe3bafbf0c7 9 return 1;
mlin 38:3fe3bafbf0c7 10 }
mlin 38:3fe3bafbf0c7 11 else if (x > 0 && x < 50 && y > 50 & y < 100) //side button 2 (change time)
mlin 38:3fe3bafbf0c7 12 {
mlin 38:3fe3bafbf0c7 13 //set desired state to 2
mlin 38:3fe3bafbf0c7 14 return 2;
mlin 38:3fe3bafbf0c7 15 }
mlin 38:3fe3bafbf0c7 16 else if (x > 0 && x < 50 && y > 100 && y < 150) // side button 3
mlin 38:3fe3bafbf0c7 17 {
mlin 38:3fe3bafbf0c7 18 //set desired state to 3
mlin 38:3fe3bafbf0c7 19 return 3;
mlin 38:3fe3bafbf0c7 20 }
mlin 38:3fe3bafbf0c7 21 else if (x > 0 && x < 50 && y > 150 && y < 200) // side button 4
mlin 38:3fe3bafbf0c7 22 {
mlin 38:3fe3bafbf0c7 23 //set desired state to 4
mlin 38:3fe3bafbf0c7 24 return 4;
mlin 38:3fe3bafbf0c7 25 }else if (x > 0 && x < 50 && y > 200 && y < 240) // button home
mlin 38:3fe3bafbf0c7 26 {
mlin 38:3fe3bafbf0c7 27 //set desired state to 0
mlin 38:3fe3bafbf0c7 28 return 0;
mlin 38:3fe3bafbf0c7 29 }
mlin 38:3fe3bafbf0c7 30 else if (x > 250 && x < 320 && y > 0 && y < 200) // alarm button on or off
mlin 38:3fe3bafbf0c7 31 {
mlin 38:3fe3bafbf0c7 32 //set desired state to 5
mlin 38:3fe3bafbf0c7 33 f_alarm = !(f_alarm);
mlin 38:3fe3bafbf0c7 34 f_alarm_sound = false;
mlin 38:3fe3bafbf0c7 35 return -1;
mlin 38:3fe3bafbf0c7 36 }
mlin 38:3fe3bafbf0c7 37 }
mlin 38:3fe3bafbf0c7 38 return -1;
mlin 38:3fe3bafbf0c7 39 }
mlin 38:3fe3bafbf0c7 40
mlin 38:3fe3bafbf0c7 41
mlin 38:3fe3bafbf0c7 42
mlin 38:3fe3bafbf0c7 43
mlin 38:3fe3bafbf0c7 44 void runanaclock()
mlin 38:3fe3bafbf0c7 45 {
mlin 38:3fe3bafbf0c7 46 DigitalOut gnd(PTA4) ;
mlin 38:3fe3bafbf0c7 47 PwmOut buzzer(PTA5);
mlin 38:3fe3bafbf0c7 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};
mlin 38:3fe3bafbf0c7 49 //frequency array
mlin 38:3fe3bafbf0c7 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};
mlin 38:3fe3bafbf0c7 51 int i =0;
mlin 38:3fe3bafbf0c7 52 int last_h = 0;
mlin 38:3fe3bafbf0c7 53 int last_m = 0;
mlin 38:3fe3bafbf0c7 54 draw_state(2);
mlin 38:3fe3bafbf0c7 55 while (f_state == 2){
mlin 38:3fe3bafbf0c7 56 read_time();
mlin 38:3fe3bafbf0c7 57 TFT.set_font((unsigned char*) Arial24x23); //coverup
mlin 38:3fe3bafbf0c7 58
mlin 38:3fe3bafbf0c7 59 if(f_alarm && tm_c.hour == tm_a_hr && tm_c.min == tm_a_min && tm_c.sec < 3){
mlin 38:3fe3bafbf0c7 60 f_alarm_sound = true;
mlin 38:3fe3bafbf0c7 61 }
mlin 38:3fe3bafbf0c7 62
mlin 38:3fe3bafbf0c7 63 if (last_h != tm_c.hour && last_m != tm_c.min){
mlin 38:3fe3bafbf0c7 64 draw_hands( 150, 100 , 90 , last_m , last_h ,Black) ;
mlin 38:3fe3bafbf0c7 65 draw_hands( 150, 100 , 90 , tm_c.min, tm_c.hour ,White) ;
mlin 38:3fe3bafbf0c7 66 last_h = tm_c.hour;
mlin 38:3fe3bafbf0c7 67 last_m = tm_c.min;
mlin 38:3fe3bafbf0c7 68 }
mlin 38:3fe3bafbf0c7 69
mlin 38:3fe3bafbf0c7 70
mlin 38:3fe3bafbf0c7 71 if (f_alarm_sound)
mlin 38:3fe3bafbf0c7 72 {
mlin 38:3fe3bafbf0c7 73 i = i % 26;
mlin 38:3fe3bafbf0c7 74 i++ ;
mlin 38:3fe3bafbf0c7 75 buzzer.period(1/(frequency[i])); // set PWM period
mlin 38:3fe3bafbf0c7 76 buzzer=0.5;
mlin 38:3fe3bafbf0c7 77 wait(0.1*beat[i]);
mlin 38:3fe3bafbf0c7 78 //
mlin 38:3fe3bafbf0c7 79 //hold for beat period ;
mlin 38:3fe3bafbf0c7 80 } else buzzer = 0;
mlin 38:3fe3bafbf0c7 81 TFT.set_orientation(0);
mlin 38:3fe3bafbf0c7 82 TFT.set_font((unsigned char*) Arial24x23);
mlin 38:3fe3bafbf0c7 83 if (f_alarm) {
mlin 38:3fe3bafbf0c7 84
mlin 38:3fe3bafbf0c7 85 TFT.locate(65,290);
mlin 38:3fe3bafbf0c7 86 TFT.printf("%d",tm_a_hr);
mlin 38:3fe3bafbf0c7 87 TFT.locate(155,290);
mlin 38:3fe3bafbf0c7 88 TFT.printf("%d",tm_a_min);
mlin 38:3fe3bafbf0c7 89 }
mlin 38:3fe3bafbf0c7 90 else
mlin 38:3fe3bafbf0c7 91 {
mlin 38:3fe3bafbf0c7 92 TFT.locate(65,290);
mlin 38:3fe3bafbf0c7 93 TFT.printf(" ");
mlin 38:3fe3bafbf0c7 94 TFT.locate(155,290);
mlin 38:3fe3bafbf0c7 95 TFT.printf(" ");
mlin 38:3fe3bafbf0c7 96 }
mlin 38:3fe3bafbf0c7 97 TFT.set_orientation(1);
mlin 38:3fe3bafbf0c7 98 TFT.locate(70,210);
mlin 38:3fe3bafbf0c7 99 TFT.printf("%d / %d / %d ", tm_c.date, tm_c.mon, tm_c.year);
mlin 38:3fe3bafbf0c7 100 wait(0.2);
mlin 38:3fe3bafbf0c7 101 /* TFT.locate(160,210);
mlin 38:3fe3bafbf0c7 102 TFT.printf("%d",tm_c.mon);
mlin 38:3fe3bafbf0c7 103 TFT.locate(220,210);
mlin 38:3fe3bafbf0c7 104 TFT.printf("%d",tm_c.year); */
mlin 38:3fe3bafbf0c7 105
mlin 38:3fe3bafbf0c7 106 switch (digital_clock_press()){
mlin 38:3fe3bafbf0c7 107 case (-1): break;
mlin 38:3fe3bafbf0c7 108 case (0): f_state = 1; break;
mlin 38:3fe3bafbf0c7 109 case (1): f_state = 1; break;
mlin 38:3fe3bafbf0c7 110 case (2): f_state = 3; break;
mlin 38:3fe3bafbf0c7 111 case (3): f_state = 4; break;
mlin 38:3fe3bafbf0c7 112 }
mlin 38:3fe3bafbf0c7 113 }
mlin 38:3fe3bafbf0c7 114 }