Group assignment alarm clock

Dependencies:   mbed TextLCD

Committer:
mmlhein
Date:
Thu May 23 01:09:22 2019 +0000
Revision:
6:167533262100
Parent:
5:fc218b8312eb
Child:
7:b9d3bc940d2c
clean up method position, variable/method name, add concept of how to check the alarm.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mmlhein 4:61d3a7c1b411 1 #include "mbed.h"
mmlhein 4:61d3a7c1b411 2 #include "TextLCD.h"
mmlhein 6:167533262100 3 #include <string>
mmlhein 6:167533262100 4 using namespace std;
mmlhein 4:61d3a7c1b411 5
mmlhein 4:61d3a7c1b411 6 TextLCD lcd(p19, p20, p21, p22, p23, p24);
hafizul_arif 5:fc218b8312eb 7 Ticker blinker_cursor, blinker_numer, blinker_menu, clock_viewer, check_alarm;
mmlhein 4:61d3a7c1b411 8 // Initially we set joystick to intterupt.
mmlhein 4:61d3a7c1b411 9 InterruptIn joycenter(p14);
mmlhein 4:61d3a7c1b411 10 InterruptIn up(p15);
mmlhein 4:61d3a7c1b411 11 InterruptIn down(p12);
mmlhein 4:61d3a7c1b411 12 InterruptIn left(p13);
mmlhein 4:61d3a7c1b411 13 InterruptIn right(p16);
mmlhein 4:61d3a7c1b411 14 Serial pc(USBTX, USBRX); // tx, rx
mmlhein 4:61d3a7c1b411 15
mmlhein 6:167533262100 16 int row, col, r_hour, r_min, r_sec, r_apm, epoch, alarm_hour, alarm_min, alarm_sec, alarm_apm;
hafizul_arif 5:fc218b8312eb 17 bool state_init, state_menu, state_alarm, alarm_up;
mmlhein 6:167533262100 18 string alarm_string, clock_string;
ebrahimatya 0:65f054e83dac 19
ebrahimatya 0:65f054e83dac 20
mmlhein 4:61d3a7c1b411 21 void cursor_left()
ebrahimatya 0:65f054e83dac 22 {
mmlhein 4:61d3a7c1b411 23 if(state_init) {
mmlhein 4:61d3a7c1b411 24 if (col >0 && col <13)
mmlhein 4:61d3a7c1b411 25 if (col == 12)
mmlhein 4:61d3a7c1b411 26 col = 10;
mmlhein 4:61d3a7c1b411 27 else if (col ==10)
mmlhein 4:61d3a7c1b411 28 col = 7;
mmlhein 4:61d3a7c1b411 29 else if (col ==7)
mmlhein 4:61d3a7c1b411 30 col = 4;
mmlhein 4:61d3a7c1b411 31 else if (col == 4) {
mmlhein 4:61d3a7c1b411 32 col =3;
mmlhein 4:61d3a7c1b411 33 row =1;
mmlhein 4:61d3a7c1b411 34 } else if (col ==3 && row == 1) {
mmlhein 4:61d3a7c1b411 35 col = 12;
mmlhein 4:61d3a7c1b411 36 row = 0;
mmlhein 4:61d3a7c1b411 37 } else
mmlhein 4:61d3a7c1b411 38 col = 4;
mmlhein 4:61d3a7c1b411 39 else
mmlhein 4:61d3a7c1b411 40 col = 4;
hafizul_arif 5:fc218b8312eb 41 } else if(state_menu){
hafizul_arif 5:fc218b8312eb 42
hafizul_arif 5:fc218b8312eb 43 if(col == 3){
hafizul_arif 5:fc218b8312eb 44 col = 9;
hafizul_arif 5:fc218b8312eb 45 } else if(col == 9){
hafizul_arif 5:fc218b8312eb 46 col = 3;
hafizul_arif 5:fc218b8312eb 47 }
hafizul_arif 5:fc218b8312eb 48 } else if(state_alarm){
hafizul_arif 5:fc218b8312eb 49 if (col == 12)
hafizul_arif 5:fc218b8312eb 50 col = 10;
hafizul_arif 5:fc218b8312eb 51 else if (col ==10)
hafizul_arif 5:fc218b8312eb 52 col = 7;
hafizul_arif 5:fc218b8312eb 53 else if (col ==7)
hafizul_arif 5:fc218b8312eb 54 col = 4;
hafizul_arif 5:fc218b8312eb 55 else if (col == 4) {
hafizul_arif 5:fc218b8312eb 56 col =3;
hafizul_arif 5:fc218b8312eb 57 row =1;
hafizul_arif 5:fc218b8312eb 58 } else if (col ==3 && row == 1) {
hafizul_arif 5:fc218b8312eb 59 col = 9;
hafizul_arif 5:fc218b8312eb 60 row = 1;
hafizul_arif 5:fc218b8312eb 61 } else if( col == 9 && row ==1) {
hafizul_arif 5:fc218b8312eb 62 col = 12;
hafizul_arif 5:fc218b8312eb 63 row = 0;
hafizul_arif 5:fc218b8312eb 64 } else
hafizul_arif 5:fc218b8312eb 65 col = 4;
hafizul_arif 5:fc218b8312eb 66 }else
hafizul_arif 5:fc218b8312eb 67 col = 4;
hafizul_arif 5:fc218b8312eb 68
mmlhein 4:61d3a7c1b411 69 pc.printf("Cursor left: %i,%i\r\n", col, row);
mmlhein 4:61d3a7c1b411 70
ebrahimatya 0:65f054e83dac 71 }
ebrahimatya 0:65f054e83dac 72
mmlhein 4:61d3a7c1b411 73
mmlhein 4:61d3a7c1b411 74 void cursor_right()
ebrahimatya 0:65f054e83dac 75 {
mmlhein 4:61d3a7c1b411 76 if(state_init) {
mmlhein 4:61d3a7c1b411 77 if (col >0 && col <13)
mmlhein 4:61d3a7c1b411 78 if (col == 12){
mmlhein 4:61d3a7c1b411 79 col =3;
mmlhein 4:61d3a7c1b411 80 row =1;
mmlhein 4:61d3a7c1b411 81 }
mmlhein 4:61d3a7c1b411 82
mmlhein 4:61d3a7c1b411 83 else if (col ==10)
mmlhein 4:61d3a7c1b411 84 col = 12;
mmlhein 4:61d3a7c1b411 85 else if (col ==7)
mmlhein 4:61d3a7c1b411 86 col = 10;
mmlhein 4:61d3a7c1b411 87 else if (col == 4) {
mmlhein 4:61d3a7c1b411 88 col = 7;
mmlhein 4:61d3a7c1b411 89 } else if (col ==3 && row == 1) {
mmlhein 4:61d3a7c1b411 90 col = 4;
mmlhein 4:61d3a7c1b411 91 row = 0;
mmlhein 4:61d3a7c1b411 92 } else
mmlhein 4:61d3a7c1b411 93 col = 4;
mmlhein 4:61d3a7c1b411 94 else
mmlhein 4:61d3a7c1b411 95 col = 4;
hafizul_arif 5:fc218b8312eb 96 }else if(state_menu){
hafizul_arif 5:fc218b8312eb 97
hafizul_arif 5:fc218b8312eb 98 if(col == 3){
hafizul_arif 5:fc218b8312eb 99 col = 9;
hafizul_arif 5:fc218b8312eb 100 } else if(col == 9){
hafizul_arif 5:fc218b8312eb 101 col = 3;
hafizul_arif 5:fc218b8312eb 102 }
hafizul_arif 5:fc218b8312eb 103 }else if(state_alarm){
hafizul_arif 5:fc218b8312eb 104 if (col >0 && col <13)
hafizul_arif 5:fc218b8312eb 105 if (col == 12){
hafizul_arif 5:fc218b8312eb 106 col =9;
hafizul_arif 5:fc218b8312eb 107 row =1;
hafizul_arif 5:fc218b8312eb 108 }
hafizul_arif 5:fc218b8312eb 109
hafizul_arif 5:fc218b8312eb 110 else if (col ==10)
hafizul_arif 5:fc218b8312eb 111 col = 12;
hafizul_arif 5:fc218b8312eb 112 else if (col ==7)
hafizul_arif 5:fc218b8312eb 113 col = 10;
hafizul_arif 5:fc218b8312eb 114 else if (col == 4) {
hafizul_arif 5:fc218b8312eb 115 col = 7;
hafizul_arif 5:fc218b8312eb 116 } else if (col ==3 && row == 1) {
hafizul_arif 5:fc218b8312eb 117 col = 4;
hafizul_arif 5:fc218b8312eb 118 row = 0;
hafizul_arif 5:fc218b8312eb 119 } else if(col == 9 && row == 1){
hafizul_arif 5:fc218b8312eb 120 col = 3;
hafizul_arif 5:fc218b8312eb 121 row = 1;
hafizul_arif 5:fc218b8312eb 122 } else
hafizul_arif 5:fc218b8312eb 123 col = 4;
hafizul_arif 5:fc218b8312eb 124 }else
hafizul_arif 5:fc218b8312eb 125 col = 4;
hafizul_arif 5:fc218b8312eb 126
mmlhein 4:61d3a7c1b411 127 pc.printf("Cursor right: %i,%i\r\n", col, row);
ebrahimatya 0:65f054e83dac 128 }
ebrahimatya 0:65f054e83dac 129
mmlhein 4:61d3a7c1b411 130 void chg_time_up(){
hafizul_arif 5:fc218b8312eb 131 if(state_init){
hafizul_arif 5:fc218b8312eb 132
mmlhein 4:61d3a7c1b411 133 if (col ==10){
mmlhein 4:61d3a7c1b411 134 r_sec = r_sec +1;
mmlhein 4:61d3a7c1b411 135 if (r_sec > 59)
mmlhein 4:61d3a7c1b411 136 r_sec = 0;
mmlhein 4:61d3a7c1b411 137 }
mmlhein 4:61d3a7c1b411 138 else if (col ==7){
mmlhein 4:61d3a7c1b411 139 r_min = r_min + 1;
mmlhein 4:61d3a7c1b411 140 if (r_min > 59)
mmlhein 4:61d3a7c1b411 141 r_min = 0; }
mmlhein 4:61d3a7c1b411 142 else if (col ==4){
mmlhein 4:61d3a7c1b411 143 r_hour = r_hour + 1;
mmlhein 4:61d3a7c1b411 144 if (r_hour > 12)
mmlhein 4:61d3a7c1b411 145 r_hour = 1;}
mmlhein 4:61d3a7c1b411 146 else if (col == 12){
mmlhein 4:61d3a7c1b411 147 if(r_apm==0)
mmlhein 4:61d3a7c1b411 148 r_apm=1;
mmlhein 4:61d3a7c1b411 149 else
mmlhein 4:61d3a7c1b411 150 r_apm=0;
mmlhein 4:61d3a7c1b411 151 }
mmlhein 4:61d3a7c1b411 152 else
mmlhein 4:61d3a7c1b411 153 pc.printf("lmfao");
mmlhein 6:167533262100 154 pc.printf("\nUP: %d:%d:%d %d\r\n", r_hour, r_min, r_sec, r_apm);
hafizul_arif 5:fc218b8312eb 155 } else if(state_alarm) {
mmlhein 6:167533262100 156
hafizul_arif 5:fc218b8312eb 157
hafizul_arif 5:fc218b8312eb 158
hafizul_arif 5:fc218b8312eb 159 if (col ==10){
hafizul_arif 5:fc218b8312eb 160 alarm_sec = alarm_sec +1;
hafizul_arif 5:fc218b8312eb 161 if (alarm_sec > 59)
hafizul_arif 5:fc218b8312eb 162 alarm_sec = 0;
hafizul_arif 5:fc218b8312eb 163 }
hafizul_arif 5:fc218b8312eb 164 else if (col ==7){
hafizul_arif 5:fc218b8312eb 165 alarm_min = alarm_min + 1;
hafizul_arif 5:fc218b8312eb 166 if (alarm_min > 59)
hafizul_arif 5:fc218b8312eb 167 alarm_min = 0; }
hafizul_arif 5:fc218b8312eb 168 else if (col ==4){
hafizul_arif 5:fc218b8312eb 169 alarm_hour = alarm_hour + 1;
hafizul_arif 5:fc218b8312eb 170 if (alarm_hour > 12)
hafizul_arif 5:fc218b8312eb 171 alarm_hour = 1;}
hafizul_arif 5:fc218b8312eb 172 else if (col == 12){
hafizul_arif 5:fc218b8312eb 173 if(alarm_apm==0)
hafizul_arif 5:fc218b8312eb 174 alarm_apm=1;
hafizul_arif 5:fc218b8312eb 175 else
hafizul_arif 5:fc218b8312eb 176 alarm_apm=0;
hafizul_arif 5:fc218b8312eb 177 }
hafizul_arif 5:fc218b8312eb 178 else
hafizul_arif 5:fc218b8312eb 179 pc.printf("lmfao");
mmlhein 6:167533262100 180 pc.printf("\nUP: %d:%d:%d %d\r\n", alarm_hour, alarm_min, alarm_sec, alarm_apm);
hafizul_arif 5:fc218b8312eb 181 }
mmlhein 6:167533262100 182
mmlhein 4:61d3a7c1b411 183 }
mmlhein 4:61d3a7c1b411 184 void chg_time_down()
ebrahimatya 0:65f054e83dac 185 {
hafizul_arif 5:fc218b8312eb 186 if(state_init){
mmlhein 4:61d3a7c1b411 187 if (col ==10){
mmlhein 4:61d3a7c1b411 188 r_sec = r_sec - 1;
mmlhein 4:61d3a7c1b411 189 if (r_sec < 0)
mmlhein 4:61d3a7c1b411 190 r_sec = 59;
mmlhein 4:61d3a7c1b411 191 }
mmlhein 4:61d3a7c1b411 192 else if (col ==7){
mmlhein 4:61d3a7c1b411 193 r_min = r_min - 1;
mmlhein 4:61d3a7c1b411 194 if (r_min < 0)
mmlhein 4:61d3a7c1b411 195 r_min = 59;}
mmlhein 4:61d3a7c1b411 196 else if (col ==4){
mmlhein 4:61d3a7c1b411 197 r_hour = r_hour - 1;
mmlhein 4:61d3a7c1b411 198 if (r_hour < 1)
mmlhein 4:61d3a7c1b411 199 r_hour = 12; }
mmlhein 4:61d3a7c1b411 200 else if (col == 12){
mmlhein 4:61d3a7c1b411 201 if(r_apm==0)
mmlhein 4:61d3a7c1b411 202 r_apm=1;
mmlhein 4:61d3a7c1b411 203 else
mmlhein 4:61d3a7c1b411 204 r_apm=0;
mmlhein 4:61d3a7c1b411 205 }
mmlhein 4:61d3a7c1b411 206 else
mmlhein 4:61d3a7c1b411 207 pc.printf("lmfao");
hafizul_arif 5:fc218b8312eb 208 } else if(state_alarm){
hafizul_arif 5:fc218b8312eb 209 if (col ==10){
hafizul_arif 5:fc218b8312eb 210 alarm_sec = alarm_sec - 1;
hafizul_arif 5:fc218b8312eb 211 if (alarm_sec < 0)
hafizul_arif 5:fc218b8312eb 212 alarm_sec = 59;
hafizul_arif 5:fc218b8312eb 213 }
hafizul_arif 5:fc218b8312eb 214 else if (col ==7){
hafizul_arif 5:fc218b8312eb 215 alarm_min = alarm_min - 1;
hafizul_arif 5:fc218b8312eb 216 if (alarm_min < 0)
hafizul_arif 5:fc218b8312eb 217 alarm_min = 59;}
hafizul_arif 5:fc218b8312eb 218 else if (col ==4){
hafizul_arif 5:fc218b8312eb 219 alarm_hour = alarm_hour - 1;
hafizul_arif 5:fc218b8312eb 220 if (alarm_hour < 1)
hafizul_arif 5:fc218b8312eb 221 alarm_hour = 12; }
hafizul_arif 5:fc218b8312eb 222 else if (col == 12){
hafizul_arif 5:fc218b8312eb 223 if(alarm_apm==0)
hafizul_arif 5:fc218b8312eb 224 alarm_apm=1;
hafizul_arif 5:fc218b8312eb 225 else
hafizul_arif 5:fc218b8312eb 226 alarm_apm=0;
hafizul_arif 5:fc218b8312eb 227 }
hafizul_arif 5:fc218b8312eb 228 else
hafizul_arif 5:fc218b8312eb 229 pc.printf("lmfao");
hafizul_arif 5:fc218b8312eb 230 }
hafizul_arif 5:fc218b8312eb 231
mmlhein 4:61d3a7c1b411 232 pc.printf("\nDOWN: %d:%d:%d\r\n", r_hour, r_min, r_sec);
ebrahimatya 0:65f054e83dac 233 }
ebrahimatya 0:65f054e83dac 234
mmlhein 6:167533262100 235 void show_menu(){
mmlhein 6:167533262100 236 if(alarm_up){
mmlhein 6:167533262100 237 lcd.locate(2,1);
mmlhein 6:167533262100 238 lcd.printf("*");
mmlhein 6:167533262100 239 }else {
mmlhein 6:167533262100 240 lcd.locate(2,1);
mmlhein 6:167533262100 241 lcd.printf(" ");
mmlhein 6:167533262100 242 }
mmlhein 6:167533262100 243 lcd.locate(3,1);
mmlhein 6:167533262100 244 lcd.printf("Alarm");
mmlhein 6:167533262100 245 lcd.locate(9,1);
mmlhein 6:167533262100 246 lcd.printf("Set");
mmlhein 6:167533262100 247
mmlhein 6:167533262100 248
mmlhein 6:167533262100 249 }
hafizul_arif 5:fc218b8312eb 250
mmlhein 6:167533262100 251 //Function alarm_chk is in progress
mmlhein 6:167533262100 252 void alarm_chk(){
mmlhein 6:167533262100 253 // char buffer_hour[32],buffer_min[32],buffer_sec[32],buffer_apm[32];
mmlhein 6:167533262100 254 // char buff_ah[32], buff_am[32],buff_as[32],buff_apm[32];
mmlhein 6:167533262100 255 // time_t seconds = time(NULL);
mmlhein 6:167533262100 256 // strftime(buffer_hour, 32, "%I", localtime(&seconds));
mmlhein 6:167533262100 257 // strftime(buffer_min, 32, "%M", localtime(&seconds));
mmlhein 6:167533262100 258 // strftime(buffer_sec, 32, "%S", localtime(&seconds));
mmlhein 6:167533262100 259 // strftime(buffer_apm, 32, "%p", localtime(&seconds));
mmlhein 6:167533262100 260 // sprintf(buff_ah, "%d", alarm_hour);
mmlhein 6:167533262100 261 // if (buff_ah == buffer_hour){
mmlhein 6:167533262100 262 // pc.printf("same lol");
mmlhein 6:167533262100 263 // }
mmlhein 6:167533262100 264 if(clock_string == alarm_string)
mmlhein 6:167533262100 265 pc.printf("%s %s : same\r\n", alarm_string, clock_string);
mmlhein 6:167533262100 266 else
mmlhein 6:167533262100 267 pc.printf("%s %s : not same\r\n", alarm_string, clock_string);
mmlhein 6:167533262100 268
mmlhein 6:167533262100 269 //if(int(buffer_hour) == alarm_hour && int (buffer_min) == alarm_min && int (buffer_sec) == alarm_sec && int(buffer_apm) == alarm_apm){
mmlhein 6:167533262100 270 // pc.printf("Alarm ring");
mmlhein 6:167533262100 271 // }
mmlhein 6:167533262100 272
mmlhein 6:167533262100 273
mmlhein 6:167533262100 274 // pc.printf("%s,%d ,%d,%d,%d,%d,%d,%d", int(buffer_hour),alarm_hour,int (buffer_min),alarm_min,int (buffer_sec),alarm_sec,int(buffer_apm),alarm_apm);
hafizul_arif 5:fc218b8312eb 275
mmlhein 6:167533262100 276 }
mmlhein 6:167533262100 277
mmlhein 6:167533262100 278 void blink_cursor(){
mmlhein 6:167533262100 279 lcd.locate(col, row);
mmlhein 6:167533262100 280 lcd.printf("_");
mmlhein 6:167533262100 281 }
mmlhein 6:167533262100 282 void blink_num()
mmlhein 6:167533262100 283 {
mmlhein 6:167533262100 284
mmlhein 6:167533262100 285 if (r_hour > 9){
mmlhein 6:167533262100 286 lcd.locate(3,0);
mmlhein 6:167533262100 287 lcd.printf("%d:", r_hour);
mmlhein 6:167533262100 288 }
mmlhein 6:167533262100 289 else{
mmlhein 6:167533262100 290 lcd.locate(3,0);
mmlhein 6:167533262100 291 lcd.printf("0%d:", r_hour);
mmlhein 6:167533262100 292 }
mmlhein 6:167533262100 293 if (r_min > 9){
mmlhein 6:167533262100 294 lcd.locate(6,0);
mmlhein 6:167533262100 295 lcd.printf("%d:", r_min);
mmlhein 6:167533262100 296 }
mmlhein 6:167533262100 297 else{
mmlhein 6:167533262100 298 lcd.locate(6,0);
mmlhein 6:167533262100 299 lcd.printf("0%d:", r_min);
mmlhein 6:167533262100 300 }
mmlhein 6:167533262100 301 if (r_sec > 9){
mmlhein 6:167533262100 302 lcd.locate(9,0);
mmlhein 6:167533262100 303 lcd.printf("%d", r_sec);
mmlhein 6:167533262100 304 }
mmlhein 6:167533262100 305 else{
mmlhein 6:167533262100 306 lcd.locate(9,0);
mmlhein 6:167533262100 307 lcd.printf("0%d", r_sec);
mmlhein 6:167533262100 308 }
mmlhein 6:167533262100 309 lcd.locate(12,0);
mmlhein 6:167533262100 310 if (r_apm ==0)
mmlhein 6:167533262100 311 lcd.printf("AM");
mmlhein 6:167533262100 312 else
mmlhein 6:167533262100 313 lcd.printf("PM");
mmlhein 6:167533262100 314 lcd.locate(3,1);
mmlhein 6:167533262100 315 lcd.printf("Done");
mmlhein 6:167533262100 316 return;
mmlhein 6:167533262100 317 }
hafizul_arif 5:fc218b8312eb 318
hafizul_arif 5:fc218b8312eb 319 void alarm_disp(){
hafizul_arif 5:fc218b8312eb 320 lcd.cls();
hafizul_arif 5:fc218b8312eb 321 if (alarm_hour > 9){
hafizul_arif 5:fc218b8312eb 322 lcd.locate(3,0);
hafizul_arif 5:fc218b8312eb 323 lcd.printf("%d:", alarm_hour);
hafizul_arif 5:fc218b8312eb 324 }
hafizul_arif 5:fc218b8312eb 325 else{
hafizul_arif 5:fc218b8312eb 326 lcd.locate(3,0);
hafizul_arif 5:fc218b8312eb 327 lcd.printf("0%d:", alarm_hour);
hafizul_arif 5:fc218b8312eb 328 }
hafizul_arif 5:fc218b8312eb 329 if (alarm_min > 9){
hafizul_arif 5:fc218b8312eb 330 lcd.locate(6,0);
hafizul_arif 5:fc218b8312eb 331 lcd.printf("%d:", alarm_min);
hafizul_arif 5:fc218b8312eb 332 }
hafizul_arif 5:fc218b8312eb 333 else{
hafizul_arif 5:fc218b8312eb 334 lcd.locate(6,0);
hafizul_arif 5:fc218b8312eb 335 lcd.printf("0%d:", alarm_min);
hafizul_arif 5:fc218b8312eb 336 }
hafizul_arif 5:fc218b8312eb 337 if (alarm_sec > 9){
hafizul_arif 5:fc218b8312eb 338 lcd.locate(9,0);
hafizul_arif 5:fc218b8312eb 339 lcd.printf("%d", alarm_sec);
hafizul_arif 5:fc218b8312eb 340 }
hafizul_arif 5:fc218b8312eb 341 else{
hafizul_arif 5:fc218b8312eb 342 lcd.locate(9,0);
hafizul_arif 5:fc218b8312eb 343 lcd.printf("0%d", alarm_sec);
hafizul_arif 5:fc218b8312eb 344 }
hafizul_arif 5:fc218b8312eb 345 lcd.locate(12,0);
hafizul_arif 5:fc218b8312eb 346 if (alarm_apm ==0)
hafizul_arif 5:fc218b8312eb 347 lcd.printf("AM");
hafizul_arif 5:fc218b8312eb 348 else
hafizul_arif 5:fc218b8312eb 349 lcd.printf("PM");
hafizul_arif 5:fc218b8312eb 350 lcd.locate(3,1);
hafizul_arif 5:fc218b8312eb 351 lcd.printf("Off");
hafizul_arif 5:fc218b8312eb 352 lcd.locate(9,1);
hafizul_arif 5:fc218b8312eb 353 lcd.printf("On");
hafizul_arif 5:fc218b8312eb 354 return;
hafizul_arif 5:fc218b8312eb 355 }
hafizul_arif 5:fc218b8312eb 356
mmlhein 6:167533262100 357 void setup_alarm(){
hafizul_arif 5:fc218b8312eb 358 state_alarm = true;
hafizul_arif 5:fc218b8312eb 359 state_menu = false;
hafizul_arif 5:fc218b8312eb 360 blinker_numer.attach(&alarm_disp,0.5);
mmlhein 6:167533262100 361
hafizul_arif 5:fc218b8312eb 362 while(1){
hafizul_arif 5:fc218b8312eb 363 wait(1);
hafizul_arif 5:fc218b8312eb 364 if(col == 3 && row ==1){
hafizul_arif 5:fc218b8312eb 365 if(joycenter){
hafizul_arif 5:fc218b8312eb 366 blinker_numer.detach();
hafizul_arif 5:fc218b8312eb 367 state_alarm = false;
hafizul_arif 5:fc218b8312eb 368 state_menu = true;
hafizul_arif 5:fc218b8312eb 369 alarm_up = false;
hafizul_arif 5:fc218b8312eb 370 check_alarm.detach();
hafizul_arif 5:fc218b8312eb 371 break;
hafizul_arif 5:fc218b8312eb 372
hafizul_arif 5:fc218b8312eb 373 }
hafizul_arif 5:fc218b8312eb 374 } else if(col == 9 && row == 1){
hafizul_arif 5:fc218b8312eb 375 if(joycenter){
hafizul_arif 5:fc218b8312eb 376 alarm_up = true;
hafizul_arif 5:fc218b8312eb 377 blinker_numer.detach();
hafizul_arif 5:fc218b8312eb 378 state_alarm = false;
hafizul_arif 5:fc218b8312eb 379 state_menu = true;
hafizul_arif 5:fc218b8312eb 380 check_alarm.attach(&alarm_chk,1);
hafizul_arif 5:fc218b8312eb 381 break;
hafizul_arif 5:fc218b8312eb 382 }
mmlhein 6:167533262100 383 char buffer_alarm[32];
mmlhein 6:167533262100 384 if(alarm_apm==0){
mmlhein 6:167533262100 385 sprintf (buffer_alarm, "%d:%d:%d AM", alarm_hour, alarm_min, alarm_sec);
mmlhein 6:167533262100 386 }
mmlhein 6:167533262100 387 else if (alarm_apm==1){
mmlhein 6:167533262100 388 sprintf (buffer_alarm, "%d:%d:%d PM", alarm_hour, alarm_min, alarm_sec);
mmlhein 6:167533262100 389 }
mmlhein 6:167533262100 390 alarm_string=buffer_alarm;
hafizul_arif 5:fc218b8312eb 391 }
hafizul_arif 5:fc218b8312eb 392 }
hafizul_arif 5:fc218b8312eb 393 }
hafizul_arif 5:fc218b8312eb 394
hafizul_arif 5:fc218b8312eb 395
mmlhein 4:61d3a7c1b411 396 void setup_init(){
mmlhein 4:61d3a7c1b411 397 state_init = true;
mmlhein 4:61d3a7c1b411 398
mmlhein 6:167533262100 399
mmlhein 4:61d3a7c1b411 400 blinker_cursor.attach(&blink_cursor, 0.1);
mmlhein 4:61d3a7c1b411 401 blinker_numer.attach(&blink_num, 0.5);
mmlhein 4:61d3a7c1b411 402 while (1){
mmlhein 4:61d3a7c1b411 403 // This is where, we select "Done", and we press joycenter to end the initial setup.
mmlhein 4:61d3a7c1b411 404 if(col==3 && row==1){
mmlhein 4:61d3a7c1b411 405 if(joycenter){
mmlhein 4:61d3a7c1b411 406 blinker_cursor.detach();
mmlhein 4:61d3a7c1b411 407 blinker_numer.detach();
mmlhein 4:61d3a7c1b411 408
mmlhein 4:61d3a7c1b411 409 //Calculate the unix timestamp
mmlhein 4:61d3a7c1b411 410 //1h : 3600, 1m: 60, 1s: 1
mmlhein 4:61d3a7c1b411 411 if(r_apm==0){// AM
mmlhein 4:61d3a7c1b411 412 if(r_hour ==12)
mmlhein 4:61d3a7c1b411 413 epoch = (0 *3600) + (r_min *60) +(r_sec);
mmlhein 4:61d3a7c1b411 414 else
mmlhein 4:61d3a7c1b411 415 epoch = (r_hour *3600) + (r_min *60) +(r_sec);
mmlhein 4:61d3a7c1b411 416 }
mmlhein 4:61d3a7c1b411 417 else if (r_apm ==1){//PM
mmlhein 4:61d3a7c1b411 418 if(r_hour ==12)
mmlhein 4:61d3a7c1b411 419 epoch = (r_hour *3600) + (r_min *60) +(r_sec);
mmlhein 4:61d3a7c1b411 420 else
mmlhein 4:61d3a7c1b411 421 epoch = 43200+(r_hour *3600) + (r_min *60) +(r_sec);
mmlhein 4:61d3a7c1b411 422 }
mmlhein 4:61d3a7c1b411 423
mmlhein 4:61d3a7c1b411 424 pc.printf("%d", epoch);
mmlhein 4:61d3a7c1b411 425 state_init = false;
mmlhein 4:61d3a7c1b411 426 break;
mmlhein 4:61d3a7c1b411 427 }
mmlhein 4:61d3a7c1b411 428 }
ebrahimatya 0:65f054e83dac 429 }
ebrahimatya 0:65f054e83dac 430 }
mmlhein 4:61d3a7c1b411 431 void view_clock()
mmlhein 4:61d3a7c1b411 432 {
mmlhein 4:61d3a7c1b411 433 lcd.locate(3,0);
mmlhein 4:61d3a7c1b411 434 time_t seconds = time(NULL);
mmlhein 4:61d3a7c1b411 435 char buffer[32];
mmlhein 4:61d3a7c1b411 436 strftime(buffer, 32, "%I:%M:%S %p", localtime(&seconds));
mmlhein 4:61d3a7c1b411 437 lcd.printf("%s", buffer);
hafizul_arif 5:fc218b8312eb 438 show_menu();
mmlhein 6:167533262100 439 clock_string = buffer;
hafizul_arif 5:fc218b8312eb 440
mmlhein 4:61d3a7c1b411 441 }
ebrahimatya 0:65f054e83dac 442
hafizul_arif 5:fc218b8312eb 443 void main_menu(){
hafizul_arif 5:fc218b8312eb 444 state_menu = true;
mmlhein 6:167533262100 445
hafizul_arif 5:fc218b8312eb 446 blinker_cursor.attach(&blink_cursor, 0.1);
hafizul_arif 5:fc218b8312eb 447
hafizul_arif 5:fc218b8312eb 448 while(1){
hafizul_arif 5:fc218b8312eb 449 wait(1);
hafizul_arif 5:fc218b8312eb 450 if(col == 3 && row == 1){
hafizul_arif 5:fc218b8312eb 451 if(joycenter){
hafizul_arif 5:fc218b8312eb 452 clock_viewer.detach();
mmlhein 6:167533262100 453 setup_alarm();
hafizul_arif 5:fc218b8312eb 454 clock_viewer.attach(&view_clock,1);
hafizul_arif 5:fc218b8312eb 455 }
hafizul_arif 5:fc218b8312eb 456 } else if(col == 9 && row ==1){
hafizul_arif 5:fc218b8312eb 457 if(joycenter){
hafizul_arif 5:fc218b8312eb 458 lcd.cls();
hafizul_arif 5:fc218b8312eb 459 lcd.locate(3,1);
hafizul_arif 5:fc218b8312eb 460 lcd.printf("OK");
hafizul_arif 5:fc218b8312eb 461 }
hafizul_arif 5:fc218b8312eb 462 }
hafizul_arif 5:fc218b8312eb 463 }
hafizul_arif 5:fc218b8312eb 464 }
hafizul_arif 5:fc218b8312eb 465
hafizul_arif 5:fc218b8312eb 466
mmlhein 4:61d3a7c1b411 467 int main(){
ebrahimatya 0:65f054e83dac 468
mmlhein 4:61d3a7c1b411 469
mmlhein 4:61d3a7c1b411 470 // Initial value
mmlhein 4:61d3a7c1b411 471 row =0 ;
mmlhein 4:61d3a7c1b411 472 col=0 ;
mmlhein 6:167533262100 473 alarm_hour=12;
mmlhein 6:167533262100 474 alarm_min=0;
mmlhein 6:167533262100 475 alarm_sec=0;
mmlhein 6:167533262100 476 alarm_apm=0;
mmlhein 4:61d3a7c1b411 477 r_hour=12 ;
mmlhein 4:61d3a7c1b411 478 r_min=0 ;
mmlhein 4:61d3a7c1b411 479 r_sec = 0;
mmlhein 4:61d3a7c1b411 480 r_apm = 0; //0-AM, 1-PM
mmlhein 4:61d3a7c1b411 481 epoch = 0; // 12:00:00 AM
mmlhein 4:61d3a7c1b411 482
mmlhein 6:167533262100 483 // Change the cursor value.
mmlhein 6:167533262100 484 left.rise(&cursor_left);
mmlhein 6:167533262100 485 right.rise(&cursor_right);
mmlhein 6:167533262100 486 up.rise(&chg_time_up);
mmlhein 6:167533262100 487 down.rise(&chg_time_down);
mmlhein 6:167533262100 488
mmlhein 6:167533262100 489
mmlhein 6:167533262100 490 /*Run setup init -> show main menu
mmlhein 6:167533262100 491 |_ setup Alarm
mmlhein 6:167533262100 492 | |_Off alarm
mmlhein 6:167533262100 493 | |_On alarm
mmlhein 6:167533262100 494 |_ Change time
mmlhein 6:167533262100 495 */
mmlhein 4:61d3a7c1b411 496 setup_init();
mmlhein 4:61d3a7c1b411 497 set_time(epoch);
mmlhein 4:61d3a7c1b411 498 clock_viewer.attach(&view_clock,1);
ebrahimatya 0:65f054e83dac 499 lcd.cls();
hafizul_arif 5:fc218b8312eb 500 main_menu();
hafizul_arif 5:fc218b8312eb 501
ebrahimatya 0:65f054e83dac 502
ebrahimatya 0:65f054e83dac 503
ebrahimatya 0:65f054e83dac 504
ebrahimatya 0:65f054e83dac 505 }