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
settings.h
00001 int setting_press() 00002 { 00003 int x = readX(); 00004 int y = readY(); 00005 if (touching == 1) { 00006 if (x > 0 && x < 50 && y > 0 & y < 100) { // side button 1 (set) 00007 //set desired state to 1 00008 return 1; 00009 } else if (x > 0 && x < 50 && y > 100 & y < 200) { //side button 2 (cancel) 00010 //set desired state to 2 00011 return 2; 00012 } else if (x > 0 && x < 50 && y > 200 && y < 240) { // button home 00013 //set desired state to 0 00014 return 0; 00015 } else if (x > 50 && x < 185 && y > 0 && y < 100) { // Alarm Hour 00016 return 11; 00017 } else if (x > 185 && x < 320 && y > 0 && y < 100) { // Alarm Min 00018 return 12; 00019 } else if (x > 50 && x < 185 && y > 100 && y < 200) { //Time Hour 00020 return 13; 00021 } else if (x > 185 && x < 320 && y > 100 && y < 200) { //Time Min 00022 return 14; 00023 } else if (x > 50 && x < 140 && y > 200 && y < 300) { //Time Date 00024 return 15; 00025 } else if (x > 140 && x < 230 && y > 200 && y < 300) { //Time Month 00026 return 16; 00027 } else if (x > 230 && x < 320 && y > 200 && y < 300) { //Time Year 00028 return 17; 00029 } 00030 } 00031 return -1; 00032 } 00033 00034 void drawsettingback() //Navigation Buttons 00035 { 00036 TFT.cls(); 00037 TFT.fillrect(0,0,50,100,Blue); //set alarm button 00038 TFT.fillrect(0,100,50,200,White); //set time button 00039 00040 00041 TFT.rect(0,0,50,100,Blue); //outlines 00042 TFT.rect(0,100,50,200,White); //outlines 00043 TFT.rect(0,200,50,240,White); //outlines 00044 00045 //alarm/time colons 00046 int tx,ty = 0; 00047 ty = 50; 00048 tx = 185; 00049 TFT.fillcircle(tx, ty - 10, 2, White); 00050 TFT.fillcircle(tx, ty + 10, 2, White); 00051 ty = 150; 00052 TFT.fillcircle(tx, ty - 10, 2, White); 00053 TFT.fillcircle(tx, ty + 10, 2, White); 00054 TFT.rect(50,0,320,100,Blue); //set alarm box 00055 TFT.rect(50,100,320,200,White); //set time box 00056 TFT.rect(50,200,320,240,White); //set date box 00057 00058 TFT.set_font((unsigned char*) Arial12x12); //set alarm title 00059 TFT.locate(157,8); 00060 TFT.printf("Set Alarm"); 00061 TFT.set_font((unsigned char*) Arial12x12); //set time title 00062 TFT.locate(157,108); 00063 TFT.printf("Set Time"); 00064 //Cancel button 00065 TFT.set_font((unsigned char*) Arial12x12); 00066 TFT.locate(62,20); 00067 TFT.set_orientation(0); 00068 TFT.background(White); 00069 TFT.foreground(Black); 00070 TFT.printf("Cancel"); 00071 TFT.background(Black); 00072 TFT.foreground(White); 00073 TFT.set_orientation(1); 00074 00075 //Set New button (used to set new alarm/time/date) 00076 00077 TFT.locate(161,20); 00078 TFT.set_orientation(0); 00079 TFT.background(Blue); 00080 TFT.printf("Set New"); 00081 TFT.background(Black); 00082 TFT.set_orientation(1); 00083 //home button 00084 TFT.locate(5,217); 00085 TFT.foreground(Blue); 00086 TFT.printf("Home"); 00087 TFT.foreground(White); 00088 } 00089 00090 void drawsettinganimate(int a_h, int a_m, int t_h, int t_m, int t_d, int t_mo, int t_y) //draw alarm, time, date 00091 { 00092 00093 00094 00095 TFT.set_font((unsigned char*) Arial28x28); //set alarm hour 00096 00097 TFT.locate(90,40); 00098 TFT.printf("%d",a_h); // print Alarm hour 00099 TFT.locate(230,40); 00100 TFT.printf("%d",a_m);//Alarm_Min 00101 TFT.set_font((unsigned char*) Arial28x28); //set time hour 00102 TFT.locate(90,140); 00103 TFT.printf("%d",t_h); // Time_hour 00104 TFT.locate(230,140); 00105 TFT.printf("%d",t_m);//Time Min 00106 TFT.set_font((unsigned char*) Arial12x12); 00107 TFT.locate(60,215); 00108 TFT.printf("%d",t_d); //print date 00109 TFT.locate(150,215); 00110 TFT.printf("%d",t_mo); //print month 00111 TFT.locate(265,215); 00112 TFT.printf("%d",t_y); //print year 00113 00114 00115 00116 00117 } 00118 void settings() 00119 { 00120 int a_h, a_m, t_h, t_m,t_d,t_mo,t_y = 0; 00121 a_h = tm_a_hr; 00122 a_m = tm_a_min; 00123 t_h = tm_c.hour; 00124 t_m = tm_c.min; 00125 t_d = tm_c.date; 00126 t_mo = tm_c.mon; 00127 t_y = tm_c.year; 00128 int multiplier = 8; 00129 int o_setting = 11; 00130 drawsettingback(); 00131 int option = 0; 00132 float tsi_current, tsi_last; 00133 while (true){ 00134 drawsettinganimate(a_h, a_m,t_h,t_m,t_d,t_mo,t_y); 00135 option = setting_press(); 00136 int newval = 0; 00137 if (option == 0 || option == 2) { 00138 pc.printf("exiting"); 00139 break; 00140 } 00141 switch (option) { 00142 case (11): 00143 o_setting = 11; 00144 break; //Alarm Hour 00145 case (12): 00146 o_setting = 12; 00147 break; //Alarm Min 00148 case (13): 00149 o_setting = 13; 00150 break; // 00151 case (14): 00152 o_setting = 14; 00153 break; // 00154 case (15): 00155 o_setting = 15; 00156 break; // 00157 case (16): 00158 o_setting = 16; 00159 break; // 00160 case (17): 00161 o_setting = 17; 00162 break; // 00163 } 00164 00165 tsi_current = tsi.readPercentage(); 00166 float change = 0; 00167 00168 if (tsi_current != 0 && tsi_last != 0) {change = tsi_current - tsi_last;} 00169 else {change = 0;} 00170 tsi_last = tsi_current; 00171 int delta = change * multiplier; 00172 pc.printf("change in slider:%f, change in total:%f",change,delta); 00173 switch (o_setting) { 00174 case(11): 00175 00176 newval = a_h + delta ; 00177 while (newval < 0) { 00178 newval += 24; 00179 } 00180 a_h = newval % 25; 00181 TFT.fillrect(70, 40, 150, 80, Black); 00182 TFT.set_font((unsigned char*) Arial28x28); //set alarm hour 00183 TFT.locate(90,40); 00184 TFT.foreground(Red); 00185 TFT.printf("%d", a_h);//Alarm_Hour 00186 break; 00187 case(12): 00188 newval = a_m + delta ; 00189 while (newval < 0) { 00190 newval += 60; 00191 } 00192 a_m = newval % 60; 00193 TFT.fillrect(200, 40, 300, 80, Black); 00194 TFT.set_font((unsigned char*) Arial28x28); //set alarm min 00195 TFT.locate(230,40); 00196 TFT.foreground(Red); 00197 TFT.printf("%d", a_m);//Alarm_Min 00198 break; 00199 case(13): //set time hour 00200 newval = t_h + delta ; 00201 if (newval < 0) newval += 24; 00202 t_h = newval % 24; 00203 TFT.fillrect(90, 140, 150, 180, Black); 00204 TFT.set_font((unsigned char*) Arial28x28); 00205 TFT.foreground(Red); 00206 TFT.locate(90,140); 00207 TFT.printf("%d",t_h); // Time_hour 00208 break; 00209 case(14): //set time min 00210 newval = t_m + delta ; 00211 if (newval < 0) newval += 60; 00212 t_m = newval % 60; 00213 TFT.fillrect(200, 140, 300, 180, Black); 00214 TFT.set_font((unsigned char*) Arial28x28); 00215 TFT.foreground(Red); 00216 TFT.locate(230,140); 00217 TFT.printf("%d",t_m);//Time Min 00218 break; 00219 case(15): // set time date 00220 newval = t_d + delta ; 00221 if (newval < 1) newval += 31; 00222 t_d = newval % 32; 00223 TFT.fillrect(55, 202, 148, 238, Black); 00224 TFT.foreground(Red); 00225 TFT.set_font((unsigned char*) Arial12x12); 00226 TFT.locate(60,215); 00227 TFT.printf("%d",t_d); //print date 00228 break; 00229 case(16): // set time month 00230 newval = t_mo + delta ; 00231 if (newval < 1) newval += 12; 00232 t_mo = newval % 13 ; 00233 00234 TFT.fillrect(148, 202, 263, 238, Black); 00235 TFT.foreground(Red); 00236 TFT.set_font((unsigned char*) Arial12x12); 00237 TFT.locate(150,215); 00238 TFT.printf("%d",t_mo); //print month 00239 break; 00240 case(17): //set time year 00241 newval = t_y + delta ; 00242 if (newval > 1970 && newval < 2700) t_y = newval; 00243 TFT.fillrect(263, 202, 310, 238, Black); 00244 TFT.foreground(Red); 00245 TFT.set_font((unsigned char*) Arial12x12); 00246 TFT.locate(265,215); 00247 TFT.printf("%d",t_y); //print year 00248 break; 00249 } 00250 TFT.foreground(White); 00251 if (option == 1) { 00252 tm_a_hr = a_h; 00253 tm_a_min = a_m; 00254 tm_c.min = t_m; 00255 tm_c.hour = t_h; 00256 tm_c.date = t_d; 00257 tm_c.mon = t_mo; 00258 tm_c.year = t_y; 00259 tm_c.wday = date2day(tm_c.date, tm_c.mon, tm_c.year); 00260 while (!rtc.setTime(tm_c, true, false)) { //set the Time in RTC Param : ( Time container, Start Clock, Twelve Hour Clock) 00261 // n++; 00262 } 00263 // pc.printf("Tried to write %d times\n\r",n); 00264 break; 00265 } 00266 } 00267 f_state = 1; 00268 }
Generated on Thu Jul 14 2022 09:34:11 by
1.7.2
