Ebrahim Atya
/
grpass_clock
Group assignment alarm clock
main.cpp@7:b9d3bc940d2c, 2019-05-23 (annotated)
- Committer:
- mmlhein
- Date:
- Thu May 23 01:10:30 2019 +0000
- Revision:
- 7:b9d3bc940d2c
- Parent:
- 6:167533262100
- Child:
- 8:c8421fc56e8f
add comment on function check alarm
Who changed what in which revision?
User | Revision | Line number | New 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 | 7:b9d3bc940d2c | 264 | |
mmlhein | 7:b9d3bc940d2c | 265 | //we basically, comparing 2 strings. alarm string and the clock strings if match we ring it |
mmlhein | 6:167533262100 | 266 | if(clock_string == alarm_string) |
mmlhein | 6:167533262100 | 267 | pc.printf("%s %s : same\r\n", alarm_string, clock_string); |
mmlhein | 6:167533262100 | 268 | else |
mmlhein | 6:167533262100 | 269 | pc.printf("%s %s : not same\r\n", alarm_string, clock_string); |
mmlhein | 6:167533262100 | 270 | |
mmlhein | 6:167533262100 | 271 | //if(int(buffer_hour) == alarm_hour && int (buffer_min) == alarm_min && int (buffer_sec) == alarm_sec && int(buffer_apm) == alarm_apm){ |
mmlhein | 6:167533262100 | 272 | // pc.printf("Alarm ring"); |
mmlhein | 6:167533262100 | 273 | // } |
mmlhein | 6:167533262100 | 274 | |
mmlhein | 6:167533262100 | 275 | |
mmlhein | 6:167533262100 | 276 | // 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 | 277 | |
mmlhein | 6:167533262100 | 278 | } |
mmlhein | 6:167533262100 | 279 | |
mmlhein | 6:167533262100 | 280 | void blink_cursor(){ |
mmlhein | 6:167533262100 | 281 | lcd.locate(col, row); |
mmlhein | 6:167533262100 | 282 | lcd.printf("_"); |
mmlhein | 6:167533262100 | 283 | } |
mmlhein | 6:167533262100 | 284 | void blink_num() |
mmlhein | 6:167533262100 | 285 | { |
mmlhein | 6:167533262100 | 286 | |
mmlhein | 6:167533262100 | 287 | if (r_hour > 9){ |
mmlhein | 6:167533262100 | 288 | lcd.locate(3,0); |
mmlhein | 6:167533262100 | 289 | lcd.printf("%d:", r_hour); |
mmlhein | 6:167533262100 | 290 | } |
mmlhein | 6:167533262100 | 291 | else{ |
mmlhein | 6:167533262100 | 292 | lcd.locate(3,0); |
mmlhein | 6:167533262100 | 293 | lcd.printf("0%d:", r_hour); |
mmlhein | 6:167533262100 | 294 | } |
mmlhein | 6:167533262100 | 295 | if (r_min > 9){ |
mmlhein | 6:167533262100 | 296 | lcd.locate(6,0); |
mmlhein | 6:167533262100 | 297 | lcd.printf("%d:", r_min); |
mmlhein | 6:167533262100 | 298 | } |
mmlhein | 6:167533262100 | 299 | else{ |
mmlhein | 6:167533262100 | 300 | lcd.locate(6,0); |
mmlhein | 6:167533262100 | 301 | lcd.printf("0%d:", r_min); |
mmlhein | 6:167533262100 | 302 | } |
mmlhein | 6:167533262100 | 303 | if (r_sec > 9){ |
mmlhein | 6:167533262100 | 304 | lcd.locate(9,0); |
mmlhein | 6:167533262100 | 305 | lcd.printf("%d", r_sec); |
mmlhein | 6:167533262100 | 306 | } |
mmlhein | 6:167533262100 | 307 | else{ |
mmlhein | 6:167533262100 | 308 | lcd.locate(9,0); |
mmlhein | 6:167533262100 | 309 | lcd.printf("0%d", r_sec); |
mmlhein | 6:167533262100 | 310 | } |
mmlhein | 6:167533262100 | 311 | lcd.locate(12,0); |
mmlhein | 6:167533262100 | 312 | if (r_apm ==0) |
mmlhein | 6:167533262100 | 313 | lcd.printf("AM"); |
mmlhein | 6:167533262100 | 314 | else |
mmlhein | 6:167533262100 | 315 | lcd.printf("PM"); |
mmlhein | 6:167533262100 | 316 | lcd.locate(3,1); |
mmlhein | 6:167533262100 | 317 | lcd.printf("Done"); |
mmlhein | 6:167533262100 | 318 | return; |
mmlhein | 6:167533262100 | 319 | } |
hafizul_arif | 5:fc218b8312eb | 320 | |
hafizul_arif | 5:fc218b8312eb | 321 | void alarm_disp(){ |
hafizul_arif | 5:fc218b8312eb | 322 | lcd.cls(); |
hafizul_arif | 5:fc218b8312eb | 323 | if (alarm_hour > 9){ |
hafizul_arif | 5:fc218b8312eb | 324 | lcd.locate(3,0); |
hafizul_arif | 5:fc218b8312eb | 325 | lcd.printf("%d:", alarm_hour); |
hafizul_arif | 5:fc218b8312eb | 326 | } |
hafizul_arif | 5:fc218b8312eb | 327 | else{ |
hafizul_arif | 5:fc218b8312eb | 328 | lcd.locate(3,0); |
hafizul_arif | 5:fc218b8312eb | 329 | lcd.printf("0%d:", alarm_hour); |
hafizul_arif | 5:fc218b8312eb | 330 | } |
hafizul_arif | 5:fc218b8312eb | 331 | if (alarm_min > 9){ |
hafizul_arif | 5:fc218b8312eb | 332 | lcd.locate(6,0); |
hafizul_arif | 5:fc218b8312eb | 333 | lcd.printf("%d:", alarm_min); |
hafizul_arif | 5:fc218b8312eb | 334 | } |
hafizul_arif | 5:fc218b8312eb | 335 | else{ |
hafizul_arif | 5:fc218b8312eb | 336 | lcd.locate(6,0); |
hafizul_arif | 5:fc218b8312eb | 337 | lcd.printf("0%d:", alarm_min); |
hafizul_arif | 5:fc218b8312eb | 338 | } |
hafizul_arif | 5:fc218b8312eb | 339 | if (alarm_sec > 9){ |
hafizul_arif | 5:fc218b8312eb | 340 | lcd.locate(9,0); |
hafizul_arif | 5:fc218b8312eb | 341 | lcd.printf("%d", alarm_sec); |
hafizul_arif | 5:fc218b8312eb | 342 | } |
hafizul_arif | 5:fc218b8312eb | 343 | else{ |
hafizul_arif | 5:fc218b8312eb | 344 | lcd.locate(9,0); |
hafizul_arif | 5:fc218b8312eb | 345 | lcd.printf("0%d", alarm_sec); |
hafizul_arif | 5:fc218b8312eb | 346 | } |
hafizul_arif | 5:fc218b8312eb | 347 | lcd.locate(12,0); |
hafizul_arif | 5:fc218b8312eb | 348 | if (alarm_apm ==0) |
hafizul_arif | 5:fc218b8312eb | 349 | lcd.printf("AM"); |
hafizul_arif | 5:fc218b8312eb | 350 | else |
hafizul_arif | 5:fc218b8312eb | 351 | lcd.printf("PM"); |
hafizul_arif | 5:fc218b8312eb | 352 | lcd.locate(3,1); |
hafizul_arif | 5:fc218b8312eb | 353 | lcd.printf("Off"); |
hafizul_arif | 5:fc218b8312eb | 354 | lcd.locate(9,1); |
hafizul_arif | 5:fc218b8312eb | 355 | lcd.printf("On"); |
hafizul_arif | 5:fc218b8312eb | 356 | return; |
hafizul_arif | 5:fc218b8312eb | 357 | } |
hafizul_arif | 5:fc218b8312eb | 358 | |
mmlhein | 6:167533262100 | 359 | void setup_alarm(){ |
hafizul_arif | 5:fc218b8312eb | 360 | state_alarm = true; |
hafizul_arif | 5:fc218b8312eb | 361 | state_menu = false; |
hafizul_arif | 5:fc218b8312eb | 362 | blinker_numer.attach(&alarm_disp,0.5); |
mmlhein | 6:167533262100 | 363 | |
hafizul_arif | 5:fc218b8312eb | 364 | while(1){ |
hafizul_arif | 5:fc218b8312eb | 365 | wait(1); |
hafizul_arif | 5:fc218b8312eb | 366 | if(col == 3 && row ==1){ |
hafizul_arif | 5:fc218b8312eb | 367 | if(joycenter){ |
hafizul_arif | 5:fc218b8312eb | 368 | blinker_numer.detach(); |
hafizul_arif | 5:fc218b8312eb | 369 | state_alarm = false; |
hafizul_arif | 5:fc218b8312eb | 370 | state_menu = true; |
hafizul_arif | 5:fc218b8312eb | 371 | alarm_up = false; |
hafizul_arif | 5:fc218b8312eb | 372 | check_alarm.detach(); |
hafizul_arif | 5:fc218b8312eb | 373 | break; |
hafizul_arif | 5:fc218b8312eb | 374 | |
hafizul_arif | 5:fc218b8312eb | 375 | } |
hafizul_arif | 5:fc218b8312eb | 376 | } else if(col == 9 && row == 1){ |
hafizul_arif | 5:fc218b8312eb | 377 | if(joycenter){ |
hafizul_arif | 5:fc218b8312eb | 378 | alarm_up = true; |
hafizul_arif | 5:fc218b8312eb | 379 | blinker_numer.detach(); |
hafizul_arif | 5:fc218b8312eb | 380 | state_alarm = false; |
hafizul_arif | 5:fc218b8312eb | 381 | state_menu = true; |
hafizul_arif | 5:fc218b8312eb | 382 | check_alarm.attach(&alarm_chk,1); |
hafizul_arif | 5:fc218b8312eb | 383 | break; |
hafizul_arif | 5:fc218b8312eb | 384 | } |
mmlhein | 6:167533262100 | 385 | char buffer_alarm[32]; |
mmlhein | 6:167533262100 | 386 | if(alarm_apm==0){ |
mmlhein | 6:167533262100 | 387 | sprintf (buffer_alarm, "%d:%d:%d AM", alarm_hour, alarm_min, alarm_sec); |
mmlhein | 6:167533262100 | 388 | } |
mmlhein | 6:167533262100 | 389 | else if (alarm_apm==1){ |
mmlhein | 6:167533262100 | 390 | sprintf (buffer_alarm, "%d:%d:%d PM", alarm_hour, alarm_min, alarm_sec); |
mmlhein | 6:167533262100 | 391 | } |
mmlhein | 6:167533262100 | 392 | alarm_string=buffer_alarm; |
hafizul_arif | 5:fc218b8312eb | 393 | } |
hafizul_arif | 5:fc218b8312eb | 394 | } |
hafizul_arif | 5:fc218b8312eb | 395 | } |
hafizul_arif | 5:fc218b8312eb | 396 | |
hafizul_arif | 5:fc218b8312eb | 397 | |
mmlhein | 4:61d3a7c1b411 | 398 | void setup_init(){ |
mmlhein | 4:61d3a7c1b411 | 399 | state_init = true; |
mmlhein | 4:61d3a7c1b411 | 400 | |
mmlhein | 6:167533262100 | 401 | |
mmlhein | 4:61d3a7c1b411 | 402 | blinker_cursor.attach(&blink_cursor, 0.1); |
mmlhein | 4:61d3a7c1b411 | 403 | blinker_numer.attach(&blink_num, 0.5); |
mmlhein | 4:61d3a7c1b411 | 404 | while (1){ |
mmlhein | 4:61d3a7c1b411 | 405 | // This is where, we select "Done", and we press joycenter to end the initial setup. |
mmlhein | 4:61d3a7c1b411 | 406 | if(col==3 && row==1){ |
mmlhein | 4:61d3a7c1b411 | 407 | if(joycenter){ |
mmlhein | 4:61d3a7c1b411 | 408 | blinker_cursor.detach(); |
mmlhein | 4:61d3a7c1b411 | 409 | blinker_numer.detach(); |
mmlhein | 4:61d3a7c1b411 | 410 | |
mmlhein | 4:61d3a7c1b411 | 411 | //Calculate the unix timestamp |
mmlhein | 4:61d3a7c1b411 | 412 | //1h : 3600, 1m: 60, 1s: 1 |
mmlhein | 4:61d3a7c1b411 | 413 | if(r_apm==0){// AM |
mmlhein | 4:61d3a7c1b411 | 414 | if(r_hour ==12) |
mmlhein | 4:61d3a7c1b411 | 415 | epoch = (0 *3600) + (r_min *60) +(r_sec); |
mmlhein | 4:61d3a7c1b411 | 416 | else |
mmlhein | 4:61d3a7c1b411 | 417 | epoch = (r_hour *3600) + (r_min *60) +(r_sec); |
mmlhein | 4:61d3a7c1b411 | 418 | } |
mmlhein | 4:61d3a7c1b411 | 419 | else if (r_apm ==1){//PM |
mmlhein | 4:61d3a7c1b411 | 420 | if(r_hour ==12) |
mmlhein | 4:61d3a7c1b411 | 421 | epoch = (r_hour *3600) + (r_min *60) +(r_sec); |
mmlhein | 4:61d3a7c1b411 | 422 | else |
mmlhein | 4:61d3a7c1b411 | 423 | epoch = 43200+(r_hour *3600) + (r_min *60) +(r_sec); |
mmlhein | 4:61d3a7c1b411 | 424 | } |
mmlhein | 4:61d3a7c1b411 | 425 | |
mmlhein | 4:61d3a7c1b411 | 426 | pc.printf("%d", epoch); |
mmlhein | 4:61d3a7c1b411 | 427 | state_init = false; |
mmlhein | 4:61d3a7c1b411 | 428 | break; |
mmlhein | 4:61d3a7c1b411 | 429 | } |
mmlhein | 4:61d3a7c1b411 | 430 | } |
ebrahimatya | 0:65f054e83dac | 431 | } |
ebrahimatya | 0:65f054e83dac | 432 | } |
mmlhein | 4:61d3a7c1b411 | 433 | void view_clock() |
mmlhein | 4:61d3a7c1b411 | 434 | { |
mmlhein | 4:61d3a7c1b411 | 435 | lcd.locate(3,0); |
mmlhein | 4:61d3a7c1b411 | 436 | time_t seconds = time(NULL); |
mmlhein | 4:61d3a7c1b411 | 437 | char buffer[32]; |
mmlhein | 4:61d3a7c1b411 | 438 | strftime(buffer, 32, "%I:%M:%S %p", localtime(&seconds)); |
mmlhein | 4:61d3a7c1b411 | 439 | lcd.printf("%s", buffer); |
hafizul_arif | 5:fc218b8312eb | 440 | show_menu(); |
mmlhein | 6:167533262100 | 441 | clock_string = buffer; |
hafizul_arif | 5:fc218b8312eb | 442 | |
mmlhein | 4:61d3a7c1b411 | 443 | } |
ebrahimatya | 0:65f054e83dac | 444 | |
hafizul_arif | 5:fc218b8312eb | 445 | void main_menu(){ |
hafizul_arif | 5:fc218b8312eb | 446 | state_menu = true; |
mmlhein | 6:167533262100 | 447 | |
hafizul_arif | 5:fc218b8312eb | 448 | blinker_cursor.attach(&blink_cursor, 0.1); |
hafizul_arif | 5:fc218b8312eb | 449 | |
hafizul_arif | 5:fc218b8312eb | 450 | while(1){ |
hafizul_arif | 5:fc218b8312eb | 451 | wait(1); |
hafizul_arif | 5:fc218b8312eb | 452 | if(col == 3 && row == 1){ |
hafizul_arif | 5:fc218b8312eb | 453 | if(joycenter){ |
hafizul_arif | 5:fc218b8312eb | 454 | clock_viewer.detach(); |
mmlhein | 6:167533262100 | 455 | setup_alarm(); |
hafizul_arif | 5:fc218b8312eb | 456 | clock_viewer.attach(&view_clock,1); |
hafizul_arif | 5:fc218b8312eb | 457 | } |
hafizul_arif | 5:fc218b8312eb | 458 | } else if(col == 9 && row ==1){ |
hafizul_arif | 5:fc218b8312eb | 459 | if(joycenter){ |
hafizul_arif | 5:fc218b8312eb | 460 | lcd.cls(); |
hafizul_arif | 5:fc218b8312eb | 461 | lcd.locate(3,1); |
hafizul_arif | 5:fc218b8312eb | 462 | lcd.printf("OK"); |
hafizul_arif | 5:fc218b8312eb | 463 | } |
hafizul_arif | 5:fc218b8312eb | 464 | } |
hafizul_arif | 5:fc218b8312eb | 465 | } |
hafizul_arif | 5:fc218b8312eb | 466 | } |
hafizul_arif | 5:fc218b8312eb | 467 | |
hafizul_arif | 5:fc218b8312eb | 468 | |
mmlhein | 4:61d3a7c1b411 | 469 | int main(){ |
ebrahimatya | 0:65f054e83dac | 470 | |
mmlhein | 4:61d3a7c1b411 | 471 | |
mmlhein | 4:61d3a7c1b411 | 472 | // Initial value |
mmlhein | 4:61d3a7c1b411 | 473 | row =0 ; |
mmlhein | 4:61d3a7c1b411 | 474 | col=0 ; |
mmlhein | 6:167533262100 | 475 | alarm_hour=12; |
mmlhein | 6:167533262100 | 476 | alarm_min=0; |
mmlhein | 6:167533262100 | 477 | alarm_sec=0; |
mmlhein | 6:167533262100 | 478 | alarm_apm=0; |
mmlhein | 4:61d3a7c1b411 | 479 | r_hour=12 ; |
mmlhein | 4:61d3a7c1b411 | 480 | r_min=0 ; |
mmlhein | 4:61d3a7c1b411 | 481 | r_sec = 0; |
mmlhein | 4:61d3a7c1b411 | 482 | r_apm = 0; //0-AM, 1-PM |
mmlhein | 4:61d3a7c1b411 | 483 | epoch = 0; // 12:00:00 AM |
mmlhein | 4:61d3a7c1b411 | 484 | |
mmlhein | 6:167533262100 | 485 | // Change the cursor value. |
mmlhein | 6:167533262100 | 486 | left.rise(&cursor_left); |
mmlhein | 6:167533262100 | 487 | right.rise(&cursor_right); |
mmlhein | 6:167533262100 | 488 | up.rise(&chg_time_up); |
mmlhein | 6:167533262100 | 489 | down.rise(&chg_time_down); |
mmlhein | 6:167533262100 | 490 | |
mmlhein | 6:167533262100 | 491 | |
mmlhein | 6:167533262100 | 492 | /*Run setup init -> show main menu |
mmlhein | 6:167533262100 | 493 | |_ setup Alarm |
mmlhein | 6:167533262100 | 494 | | |_Off alarm |
mmlhein | 6:167533262100 | 495 | | |_On alarm |
mmlhein | 6:167533262100 | 496 | |_ Change time |
mmlhein | 6:167533262100 | 497 | */ |
mmlhein | 4:61d3a7c1b411 | 498 | setup_init(); |
mmlhein | 4:61d3a7c1b411 | 499 | set_time(epoch); |
mmlhein | 4:61d3a7c1b411 | 500 | clock_viewer.attach(&view_clock,1); |
ebrahimatya | 0:65f054e83dac | 501 | lcd.cls(); |
hafizul_arif | 5:fc218b8312eb | 502 | main_menu(); |
hafizul_arif | 5:fc218b8312eb | 503 | |
ebrahimatya | 0:65f054e83dac | 504 | |
ebrahimatya | 0:65f054e83dac | 505 | |
ebrahimatya | 0:65f054e83dac | 506 | |
ebrahimatya | 0:65f054e83dac | 507 | } |