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 12:37:32 2017 +0000
Revision:
27:a895a2c9acb8
Parent:
26:47271cf8d6b2
Child:
28:53a5429976e4
.

Who changed what in which revision?

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