IoT Ox / Mbed 2 deprecated MainSketch Featured

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 13:24:26 2017 +0000
Revision:
30:af38c80391cb
Parent:
29:684e2a3e17b5
Child:
31:3255668e6b08
.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Owenmatthewmcgowan 28:53a5429976e4 1 int setting_press()
Owenmatthewmcgowan 28:53a5429976e4 2 {
Owenmatthewmcgowan 24:93e1474d6d8b 3 int x = readX();
Owenmatthewmcgowan 24:93e1474d6d8b 4 int y = readY();
Owenmatthewmcgowan 24:93e1474d6d8b 5 if (touching == 1) {
Owenmatthewmcgowan 28:53a5429976e4 6 if (x > 0 && x < 50 && y > 0 & y < 100) { // side button 1 (set)
Owenmatthewmcgowan 28:53a5429976e4 7 //set desired state to 1
Owenmatthewmcgowan 24:93e1474d6d8b 8 return 1;
Owenmatthewmcgowan 28:53a5429976e4 9 } else if (x > 0 && x < 50 && y > 100 & y < 200) { //side button 2 (cancel)
Owenmatthewmcgowan 28:53a5429976e4 10 //set desired state to 2
Owenmatthewmcgowan 24:93e1474d6d8b 11 return 2;
Owenmatthewmcgowan 28:53a5429976e4 12 } else if (x > 0 && x < 50 && y > 200 && y < 240) { // button home
Owenmatthewmcgowan 24:93e1474d6d8b 13 //set desired state to 0
Owenmatthewmcgowan 24:93e1474d6d8b 14 return 0;
Owenmatthewmcgowan 28:53a5429976e4 15 } else if (x > 50 && x < 185 && y > 0 && y < 100) { // Alarm Hour
Owenmatthewmcgowan 24:93e1474d6d8b 16 return 11;
Owenmatthewmcgowan 28:53a5429976e4 17 } else if (x > 185 && x < 320 && y > 0 && y < 100) { // Alarm Min
Owenmatthewmcgowan 24:93e1474d6d8b 18 return 12;
Owenmatthewmcgowan 28:53a5429976e4 19 } else if (x > 50 && x < 185 && y > 100 && y < 200) { //Time Hour
Owenmatthewmcgowan 24:93e1474d6d8b 20 return 13;
Owenmatthewmcgowan 28:53a5429976e4 21 } else if (x > 185 && x < 320 && y > 100 && y < 200) { //Time Min
Owenmatthewmcgowan 28:53a5429976e4 22 return 14;
Owenmatthewmcgowan 28:53a5429976e4 23 } else if (x > 50 && x < 140 && y > 200 && y < 300) { //Time Date
Owenmatthewmcgowan 28:53a5429976e4 24 return 15;
Owenmatthewmcgowan 28:53a5429976e4 25 } else if (x > 140 && x < 230 && y > 200 && y < 300) { //Time Month
Owenmatthewmcgowan 28:53a5429976e4 26 return 16;
Owenmatthewmcgowan 28:53a5429976e4 27 } else if (x > 230 && x < 320 && y > 200 && y < 300) { //Time Year
Owenmatthewmcgowan 28:53a5429976e4 28 return 17;
Owenmatthewmcgowan 24:93e1474d6d8b 29 }
Owenmatthewmcgowan 24:93e1474d6d8b 30 }
Owenmatthewmcgowan 24:93e1474d6d8b 31 return -1;
Owenmatthewmcgowan 24:93e1474d6d8b 32 }
Owenmatthewmcgowan 12:50289d0ac834 33
Owenmatthewmcgowan 15:796e17680825 34 void drawsettingback() //Navigation Buttons
Owenmatthewmcgowan 12:50289d0ac834 35 {
Owenmatthewmcgowan 30:af38c80391cb 36 TFT.cls();
Owenmatthewmcgowan 28:53a5429976e4 37 TFT.fillrect(0,0,50,100,Blue); //set alarm button
Owenmatthewmcgowan 12:50289d0ac834 38 TFT.fillrect(0,100,50,200,White); //set time button
Owenmatthewmcgowan 12:50289d0ac834 39
Owenmatthewmcgowan 28:53a5429976e4 40
Owenmatthewmcgowan 12:50289d0ac834 41 TFT.rect(0,0,50,100,Blue); //outlines
Owenmatthewmcgowan 12:50289d0ac834 42 TFT.rect(0,100,50,200,White); //outlines
Owenmatthewmcgowan 12:50289d0ac834 43 TFT.rect(0,200,50,240,White); //outlines
Owenmatthewmcgowan 28:53a5429976e4 44
Owenmatthewmcgowan 15:796e17680825 45 //alarm/time colons
Owenmatthewmcgowan 28:53a5429976e4 46 int tx,ty = 0;
Owenmatthewmcgowan 28:53a5429976e4 47 ty = 50;
Owenmatthewmcgowan 28:53a5429976e4 48 tx = 185;
Owenmatthewmcgowan 28:53a5429976e4 49 TFT.fillcircle(tx, ty - 10, 2, White);
Owenmatthewmcgowan 28:53a5429976e4 50 TFT.fillcircle(tx, ty + 10, 2, White);
Owenmatthewmcgowan 28:53a5429976e4 51 ty = 150;
Owenmatthewmcgowan 28:53a5429976e4 52 TFT.fillcircle(tx, ty - 10, 2, White);
Owenmatthewmcgowan 28:53a5429976e4 53 TFT.fillcircle(tx, ty + 10, 2, White);
Owenmatthewmcgowan 28:53a5429976e4 54 TFT.rect(50,0,320,100,Blue); //set alarm box
Owenmatthewmcgowan 12:50289d0ac834 55 TFT.rect(50,100,320,200,White); //set time box
Owenmatthewmcgowan 12:50289d0ac834 56 TFT.rect(50,200,320,240,White); //set date box
Owenmatthewmcgowan 13:e74e09de81e4 57
Owenmatthewmcgowan 12:50289d0ac834 58 TFT.set_font((unsigned char*) Arial12x12); //set alarm title
Owenmatthewmcgowan 15:796e17680825 59 TFT.locate(157,8);
Owenmatthewmcgowan 12:50289d0ac834 60 TFT.printf("Set Alarm");
Owenmatthewmcgowan 27:a895a2c9acb8 61 TFT.set_font((unsigned char*) Arial12x12); //set time title
Owenmatthewmcgowan 27:a895a2c9acb8 62 TFT.locate(157,108);
Owenmatthewmcgowan 27:a895a2c9acb8 63 TFT.printf("Set Time");
Owenmatthewmcgowan 28:53a5429976e4 64 //Cancel button
Owenmatthewmcgowan 28:53a5429976e4 65 TFT.set_font((unsigned char*) Arial12x12);
mlin 25:ff73360cd038 66 TFT.locate(62,20);
mlin 25:ff73360cd038 67 TFT.set_orientation(0);
mlin 25:ff73360cd038 68 TFT.background(White);
mlin 25:ff73360cd038 69 TFT.foreground(Black);
mlin 25:ff73360cd038 70 TFT.printf("Cancel");
mlin 25:ff73360cd038 71 TFT.background(Black);
mlin 25:ff73360cd038 72 TFT.foreground(White);
mlin 25:ff73360cd038 73 TFT.set_orientation(1);
mlin 25:ff73360cd038 74
mlin 25:ff73360cd038 75 //Set New button (used to set new alarm/time/date)
Owenmatthewmcgowan 28:53a5429976e4 76
mlin 25:ff73360cd038 77 TFT.locate(161,20);
mlin 25:ff73360cd038 78 TFT.set_orientation(0);
mlin 25:ff73360cd038 79 TFT.background(Blue);
mlin 25:ff73360cd038 80 TFT.printf("Set New");
mlin 25:ff73360cd038 81 TFT.background(Black);
mlin 25:ff73360cd038 82 TFT.set_orientation(1);
Owenmatthewmcgowan 28:53a5429976e4 83 //home button
mlin 25:ff73360cd038 84 TFT.locate(5,217);
mlin 25:ff73360cd038 85 TFT.foreground(Blue);
mlin 25:ff73360cd038 86 TFT.printf("Home");
mlin 25:ff73360cd038 87 TFT.foreground(White);
mlin 25:ff73360cd038 88 }
mlin 25:ff73360cd038 89
Owenmatthewmcgowan 28:53a5429976e4 90 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
mlin 25:ff73360cd038 91 {
Owenmatthewmcgowan 28:53a5429976e4 92
Owenmatthewmcgowan 12:50289d0ac834 93
mlin 18:02667782b06f 94
Owenmatthewmcgowan 12:50289d0ac834 95 TFT.set_font((unsigned char*) Arial28x28); //set alarm hour
mlin 18:02667782b06f 96
Owenmatthewmcgowan 15:796e17680825 97 TFT.locate(90,40);
Owenmatthewmcgowan 28:53a5429976e4 98 TFT.printf("%d",a_h); // print Alarm hour
Owenmatthewmcgowan 15:796e17680825 99 TFT.locate(230,40);
Owenmatthewmcgowan 28:53a5429976e4 100 TFT.printf("%d",a_m);//Alarm_Min
Owenmatthewmcgowan 12:50289d0ac834 101 TFT.set_font((unsigned char*) Arial28x28); //set time hour
Owenmatthewmcgowan 15:796e17680825 102 TFT.locate(90,140);
Owenmatthewmcgowan 28:53a5429976e4 103 TFT.printf("%d",t_h); // Time_hour
Owenmatthewmcgowan 15:796e17680825 104 TFT.locate(230,140);
Owenmatthewmcgowan 28:53a5429976e4 105 TFT.printf("%d",t_m);//Time Min
Owenmatthewmcgowan 15:796e17680825 106 TFT.set_font((unsigned char*) Arial12x12);
Owenmatthewmcgowan 15:796e17680825 107 TFT.locate(60,215);
Owenmatthewmcgowan 28:53a5429976e4 108 TFT.printf("%d",t_d); //print date
Owenmatthewmcgowan 15:796e17680825 109 TFT.locate(150,215);
Owenmatthewmcgowan 28:53a5429976e4 110 TFT.printf("%d",t_mo); //print month
Owenmatthewmcgowan 15:796e17680825 111 TFT.locate(265,215);
Owenmatthewmcgowan 28:53a5429976e4 112 TFT.printf("%d",t_y); //print year
Owenmatthewmcgowan 12:50289d0ac834 113
Owenmatthewmcgowan 28:53a5429976e4 114
Owenmatthewmcgowan 28:53a5429976e4 115
Owenmatthewmcgowan 15:796e17680825 116
mlin 16:3cb9b1fbc039 117 }
Owenmatthewmcgowan 28:53a5429976e4 118 void settings()
Owenmatthewmcgowan 28:53a5429976e4 119 {
mlin 25:ff73360cd038 120 int a_h, a_m, t_h, t_m,t_d,t_mo,t_y = 0;
Owenmatthewmcgowan 28:53a5429976e4 121 a_h = tm_a_hr;
Owenmatthewmcgowan 29:684e2a3e17b5 122 a_m = tm_a_min;
Owenmatthewmcgowan 28:53a5429976e4 123 t_h = tm_c.hour;
Owenmatthewmcgowan 28:53a5429976e4 124 t_m = tm_c.min;
Owenmatthewmcgowan 28:53a5429976e4 125 t_d = tm_c.date;
Owenmatthewmcgowan 29:684e2a3e17b5 126 t_mo = tm_c.mon;
Owenmatthewmcgowan 28:53a5429976e4 127 t_y = tm_c.year;
Owenmatthewmcgowan 29:684e2a3e17b5 128 int multiplier = 8;
Owenmatthewmcgowan 26:47271cf8d6b2 129 int o_setting = 11;
Owenmatthewmcgowan 29:684e2a3e17b5 130 drawsettingback();
Owenmatthewmcgowan 30:af38c80391cb 131 int option = 0;
Owenmatthewmcgowan 28:53a5429976e4 132 while (true){
Owenmatthewmcgowan 29:684e2a3e17b5 133 drawsettinganimate(a_h, a_m,t_h,t_m,t_d,t_mo,t_y);
Owenmatthewmcgowan 30:af38c80391cb 134 option = setting_press();
Owenmatthewmcgowan 29:684e2a3e17b5 135 int newval = 0;
Owenmatthewmcgowan 28:53a5429976e4 136 if (option == 0 || option == 2) break;
Owenmatthewmcgowan 28:53a5429976e4 137 switch (option) {
Owenmatthewmcgowan 28:53a5429976e4 138 case (11):
Owenmatthewmcgowan 28:53a5429976e4 139 o_setting = 11;
Owenmatthewmcgowan 28:53a5429976e4 140 break; //Alarm Hour
Owenmatthewmcgowan 28:53a5429976e4 141 case (12):
Owenmatthewmcgowan 28:53a5429976e4 142 o_setting = 12;
Owenmatthewmcgowan 28:53a5429976e4 143 break; //Alarm Min
Owenmatthewmcgowan 28:53a5429976e4 144 case (13):
Owenmatthewmcgowan 28:53a5429976e4 145 o_setting = 13;
Owenmatthewmcgowan 28:53a5429976e4 146 break; //
Owenmatthewmcgowan 28:53a5429976e4 147 case (14):
Owenmatthewmcgowan 28:53a5429976e4 148 o_setting = 14;
Owenmatthewmcgowan 28:53a5429976e4 149 break; //
Owenmatthewmcgowan 28:53a5429976e4 150 case (15):
Owenmatthewmcgowan 28:53a5429976e4 151 o_setting = 15;
Owenmatthewmcgowan 28:53a5429976e4 152 break; //
Owenmatthewmcgowan 28:53a5429976e4 153 case (16):
Owenmatthewmcgowan 28:53a5429976e4 154 o_setting = 16;
Owenmatthewmcgowan 28:53a5429976e4 155 break; //
Owenmatthewmcgowan 28:53a5429976e4 156 case (17):
Owenmatthewmcgowan 28:53a5429976e4 157 o_setting = 17;
Owenmatthewmcgowan 28:53a5429976e4 158 break; //
Owenmatthewmcgowan 26:47271cf8d6b2 159 }
Owenmatthewmcgowan 28:53a5429976e4 160 switch (o_setting) {
Owenmatthewmcgowan 26:47271cf8d6b2 161 case(11):
Owenmatthewmcgowan 29:684e2a3e17b5 162 newval = a_h + tsi_d() * multiplier;
Owenmatthewmcgowan 28:53a5429976e4 163 while (newval < 0) {
Owenmatthewmcgowan 28:53a5429976e4 164 newval += 24;
Owenmatthewmcgowan 28:53a5429976e4 165 }
Owenmatthewmcgowan 27:a895a2c9acb8 166 a_h = newval % 25;
Owenmatthewmcgowan 27:a895a2c9acb8 167 TFT.fillrect(70, 40, 150, 80, Black);
Owenmatthewmcgowan 27:a895a2c9acb8 168 TFT.set_font((unsigned char*) Arial28x28); //set alarm hour
Owenmatthewmcgowan 27:a895a2c9acb8 169 TFT.locate(90,40);
Owenmatthewmcgowan 27:a895a2c9acb8 170 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 171 TFT.printf("%d", a_h);//Alarm_Hour
Owenmatthewmcgowan 28:53a5429976e4 172 break;
Owenmatthewmcgowan 27:a895a2c9acb8 173 case(12):
Owenmatthewmcgowan 29:684e2a3e17b5 174 newval = a_m + tsi_d() * multiplier;
Owenmatthewmcgowan 28:53a5429976e4 175 while (newval < 0) {
Owenmatthewmcgowan 28:53a5429976e4 176 newval += 60;
Owenmatthewmcgowan 28:53a5429976e4 177 }
Owenmatthewmcgowan 27:a895a2c9acb8 178 a_m = newval % 60;
Owenmatthewmcgowan 27:a895a2c9acb8 179 TFT.fillrect(200, 40, 300, 80, Black);
Owenmatthewmcgowan 27:a895a2c9acb8 180 TFT.set_font((unsigned char*) Arial28x28); //set alarm min
Owenmatthewmcgowan 27:a895a2c9acb8 181 TFT.locate(230,40);
Owenmatthewmcgowan 27:a895a2c9acb8 182 TFT.foreground(Red);
Owenmatthewmcgowan 27:a895a2c9acb8 183 TFT.printf("%d", a_m);//Alarm_Min
Owenmatthewmcgowan 28:53a5429976e4 184 break;
Owenmatthewmcgowan 27:a895a2c9acb8 185 case(13): //set time hour
Owenmatthewmcgowan 29:684e2a3e17b5 186 newval = t_h + tsi_d() * multiplier;
Owenmatthewmcgowan 26:47271cf8d6b2 187 if (newval < 0) newval += 24;
Owenmatthewmcgowan 28:53a5429976e4 188 t_h = newval % 25;
Owenmatthewmcgowan 28:53a5429976e4 189 TFT.fillrect(90, 140, 150, 180, Black);
Owenmatthewmcgowan 28:53a5429976e4 190 TFT.set_font((unsigned char*) Arial28x28);
Owenmatthewmcgowan 27:a895a2c9acb8 191 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 192 TFT.locate(90,140);
Owenmatthewmcgowan 28:53a5429976e4 193 TFT.printf("%d",t_h); // Time_hour
Owenmatthewmcgowan 28:53a5429976e4 194 break;
Owenmatthewmcgowan 27:a895a2c9acb8 195 case(14): //set time min
Owenmatthewmcgowan 29:684e2a3e17b5 196 newval = t_m + tsi_d() * multiplier;
Owenmatthewmcgowan 27:a895a2c9acb8 197 if (newval < 0) newval += 60;
Owenmatthewmcgowan 28:53a5429976e4 198 t_m = newval % 60;
Owenmatthewmcgowan 28:53a5429976e4 199 TFT.fillrect(200, 140, 300, 180, Black);
Owenmatthewmcgowan 27:a895a2c9acb8 200 TFT.set_font((unsigned char*) Arial28x28);
Owenmatthewmcgowan 27:a895a2c9acb8 201 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 202 TFT.locate(230,140);
Owenmatthewmcgowan 28:53a5429976e4 203 TFT.printf("%d",t_m);//Time Min
Owenmatthewmcgowan 28:53a5429976e4 204 break;
Owenmatthewmcgowan 27:a895a2c9acb8 205 case(15): // set time date
Owenmatthewmcgowan 29:684e2a3e17b5 206 newval = t_d + tsi_d() * multiplier;
Owenmatthewmcgowan 27:a895a2c9acb8 207 if (newval < 0) newval += 31;
Owenmatthewmcgowan 28:53a5429976e4 208 t_d = newval % 32;
Owenmatthewmcgowan 28:53a5429976e4 209 TFT.fillrect(55, 202, 148, 238, Black);
Owenmatthewmcgowan 27:a895a2c9acb8 210 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 211 TFT.set_font((unsigned char*) Arial12x12);
Owenmatthewmcgowan 28:53a5429976e4 212 TFT.locate(60,215);
Owenmatthewmcgowan 28:53a5429976e4 213 TFT.printf("%d",t_d); //print date
Owenmatthewmcgowan 28:53a5429976e4 214 break;
Owenmatthewmcgowan 27:a895a2c9acb8 215 case(16): // set time month
Owenmatthewmcgowan 29:684e2a3e17b5 216 newval = a_h + tsi_d() * multiplier;
Owenmatthewmcgowan 27:a895a2c9acb8 217 if (newval < 0) newval += 12;
Owenmatthewmcgowan 27:a895a2c9acb8 218 a_h = newval % 13;
Owenmatthewmcgowan 28:53a5429976e4 219 TFT.fillrect(148, 202, 263, 238, Black);
Owenmatthewmcgowan 27:a895a2c9acb8 220 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 221 TFT.set_font((unsigned char*) Arial12x12);
Owenmatthewmcgowan 28:53a5429976e4 222 TFT.locate(150,215);
Owenmatthewmcgowan 28:53a5429976e4 223 TFT.printf("%d",t_mo); //print month
Owenmatthewmcgowan 28:53a5429976e4 224 break;
Owenmatthewmcgowan 27:a895a2c9acb8 225 case(17): //set time year
Owenmatthewmcgowan 29:684e2a3e17b5 226 newval = a_h + tsi_d() * multiplier;
Owenmatthewmcgowan 27:a895a2c9acb8 227 if (newval > 1970 && newval < 2700) a_h = newval;
Owenmatthewmcgowan 28:53a5429976e4 228 TFT.fillrect(263, 202, 310, 238, Black);
Owenmatthewmcgowan 26:47271cf8d6b2 229 TFT.foreground(Red);
Owenmatthewmcgowan 28:53a5429976e4 230 TFT.set_font((unsigned char*) Arial12x12);
Owenmatthewmcgowan 28:53a5429976e4 231 TFT.locate(265,215);
Owenmatthewmcgowan 28:53a5429976e4 232 TFT.printf("%d",t_y); //print year
Owenmatthewmcgowan 28:53a5429976e4 233 break;
Owenmatthewmcgowan 28:53a5429976e4 234 }
Owenmatthewmcgowan 28:53a5429976e4 235 TFT.foreground(White);
Owenmatthewmcgowan 28:53a5429976e4 236 if (option == 1) {
Owenmatthewmcgowan 28:53a5429976e4 237 tm_a_hr = a_h;
Owenmatthewmcgowan 29:684e2a3e17b5 238 tm_a_min = a_m;
Owenmatthewmcgowan 29:684e2a3e17b5 239 tm_c.min = t_m;
Owenmatthewmcgowan 29:684e2a3e17b5 240 tm_c.hour = t_h;
Owenmatthewmcgowan 29:684e2a3e17b5 241 tm_c.date = t_d;
Owenmatthewmcgowan 29:684e2a3e17b5 242 tm_c.mon = t_mo;
Owenmatthewmcgowan 29:684e2a3e17b5 243 tm_c.year = t_y;
Owenmatthewmcgowan 29:684e2a3e17b5 244 while (!rtc.setTime(tm_c, true, false)) { //set the Time in RTC Param : ( Time container, Start Clock, Twelve Hour Clock)
Owenmatthewmcgowan 29:684e2a3e17b5 245 // n++;
Owenmatthewmcgowan 29:684e2a3e17b5 246 }
Owenmatthewmcgowan 29:684e2a3e17b5 247 // pc.printf("Tried to write %d times\n\r",n);
Owenmatthewmcgowan 28:53a5429976e4 248 break;
Owenmatthewmcgowan 28:53a5429976e4 249 }
Owenmatthewmcgowan 28:53a5429976e4 250 }
Owenmatthewmcgowan 28:53a5429976e4 251 f_state = 1;
mlin 25:ff73360cd038 252 }