Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: RTC-DS1307 SPI_TFT_ILI9341 TFT_fonts mbed tsi_sensor
Fork of TFT_Mikroelectronika_IL9341_sketchpad by
clocklogic.h
00001 int digital_clock_press(){ 00002 int x = readX(); // read x location 00003 int y = readY(); // read y location 00004 if (touching == 1) { 00005 00006 if (x > 0 && x < 50 && y > 0 & y < 50) // side button 1 (clock state) 00007 { 00008 //set desired state to 1 00009 return 1; 00010 } 00011 else if (x > 0 && x < 50 && y > 50 & y < 100) //side button 2 (change time) 00012 { 00013 //set desired state to 2 00014 return 2; 00015 } 00016 else if (x > 0 && x < 50 && y > 100 && y < 150) // side button 3 00017 { 00018 //set desired state to 3 00019 return 3; 00020 } 00021 else if (x > 0 && x < 50 && y > 150 && y < 200) // side button 4 00022 { 00023 //set desired state to 4 00024 f_cycle = !f_cycle; 00025 f_cycle_secs = tm_c.sec; 00026 //wait(0.5); 00027 // return 4; 00028 00029 }else if (x > 0 && x < 50 && y > 200 && y < 240) // button home 00030 { 00031 //set desired state to 0 00032 return 0; 00033 } 00034 else if (x > 140 && x < 320 && y > 100 && y < 200) // alarm button on or off 00035 { 00036 //set desired state to 5 00037 f_alarm = !(f_alarm); 00038 f_alarm_sound = false; // flag for the alarm sound 00039 return -1; 00040 } 00041 } 00042 return -1; 00043 } 00044 00045 00046 00047 00048 void runclock() // getting time from the clock 00049 { 00050 DigitalOut gnd(PTA4) ; // initiating buzzer 00051 PwmOut buzzer(PTA5); 00052 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}; 00053 //frequency array 00054 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}; 00055 //time intervals 00056 int i =0; 00057 int last = 0; 00058 draw_state(1); 00059 while (f_state == 1){ 00060 read_time(); 00061 TFT.set_font((unsigned char*) Arial24x23); //coverup 00062 if (tm_c.sec == 0){ //getting seconds and printing 00063 TFT.locate(250,40); 00064 TFT.printf(" "); 00065 if (tm_c.min == 0){ //getting minutes and printing 00066 TFT.locate(160,40); 00067 printf(" "); 00068 if (tm_c.hour == 0) //getting hours and printing 00069 { 00070 TFT.locate(70,40); 00071 printf(" "); 00072 } 00073 } 00074 } 00075 00076 if(f_alarm && tm_c.hour == tm_a_hr && tm_c.min == tm_a_min && tm_c.sec < 3){ 00077 f_alarm_sound = true; //alarm buzzes 00078 } 00079 00080 00081 if (f_alarm_sound) 00082 { 00083 i = i % 26; 00084 i++ ; 00085 buzzer.period(1/(frequency[i])); // set PWM period 00086 buzzer=0.5; 00087 wait(0.1*beat[i]); 00088 // 00089 //hold for beat period ; 00090 } else buzzer = 0; 00091 TFT.locate(70,40); 00092 TFT.printf("%d",tm_c.hour); 00093 TFT.locate(160,40); 00094 TFT.printf("%d",tm_c.min); 00095 TFT.locate(250,40); 00096 TFT.printf("%d",tm_c.sec); 00097 TFT.locate(60,140); 00098 TFT.set_font((unsigned char*) Arial12x12); 00099 if (last != tm_c.wday) printf(" "); 00100 last = tm_c.wday; 00101 TFT.locate(60,140); 00102 TFT.printf("%s",rtc.weekdayToString(tm_c.wday + 1)); 00103 TFT.set_font((unsigned char*) Arial24x23); 00104 if (f_alarm) { 00105 TFT.locate(160,140); 00106 TFT.printf("%d",tm_a_hr); 00107 TFT.locate(250,140); 00108 TFT.printf("%d",tm_a_min); 00109 } 00110 else 00111 { 00112 TFT.locate(160,140); 00113 TFT.printf(" "); 00114 TFT.locate(250,140); 00115 TFT.printf(" "); 00116 } 00117 TFT.locate(70,210); 00118 TFT.printf("%d / %d / %d", tm_c.date, tm_c.mon, tm_c.year); 00119 wait(0.2); 00120 /* TFT.locate(160,210); 00121 TFT.printf("%d",tm_c.mon); 00122 TFT.locate(220,210); 00123 TFT.printf("%d",tm_c.year); */ 00124 if (f_cycle){ 00125 if ((f_cycle_secs + f_cycle_wait) == tm_c.sec){ 00126 f_state = 2; 00127 f_cycle_secs = tm_c.sec; 00128 } 00129 } 00130 switch (digital_clock_press()){ 00131 case (-1): break; 00132 case (0): f_state = 1; break; 00133 case (1): f_state = 2; break; 00134 case (2): f_state = 3; break; 00135 case (3): f_state = 4; break; 00136 case (4): f_state = 5; break; 00137 } 00138 } 00139 }
Generated on Thu Jul 14 2022 09:34:11 by
1.7.2
