Ebrahim Atya
/
grpass_clock
Group assignment alarm clock
main.cpp@10:2a47ac757d14, 2019-05-24 (annotated)
- Committer:
- mmlhein
- Date:
- Fri May 24 01:00:16 2019 +0000
- Revision:
- 10:2a47ac757d14
- Parent:
- 9:b53b3bb0166a
- Child:
- 11:8695cb20e94c
add back button function
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 | 9:b53b3bb0166a | 3 | #include <string> |
mmlhein | 6:167533262100 | 4 | using namespace std; |
mmlhein | 4:61d3a7c1b411 | 5 | |
mmlhein | 8:c8421fc56e8f | 6 | TextLCD lcd(p19, p20, p25, p22, p23, p24); |
mmlhein | 8:c8421fc56e8f | 7 | Ticker blinker_cursor, blinker_numer, blinker_menu, clock_viewer, check_alarm, sound_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 | 9:b53b3bb0166a | 15 | PwmOut buzzer(p26); |
mmlhein | 4:61d3a7c1b411 | 16 | |
mmlhein | 6:167533262100 | 17 | int row, col, r_hour, r_min, r_sec, r_apm, epoch, alarm_hour, alarm_min, alarm_sec, alarm_apm; |
mmlhein | 9:b53b3bb0166a | 18 | bool state_init, state_menu, state_alarm, alarm_up, state_set, alarm_ring; |
mmlhein | 6:167533262100 | 19 | string alarm_string, clock_string; |
ebrahimatya | 0:65f054e83dac | 20 | |
mmlhein | 9:b53b3bb0166a | 21 | /* |
mmlhein | 9:b53b3bb0166a | 22 | cursor {left,right} movement only work in state_init, state_alarm, state_menu, state_set |
mmlhein | 9:b53b3bb0166a | 23 | */ |
mmlhein | 4:61d3a7c1b411 | 24 | void cursor_left() |
ebrahimatya | 0:65f054e83dac | 25 | { |
mmlhein | 4:61d3a7c1b411 | 26 | if(state_init) { |
mmlhein | 9:b53b3bb0166a | 27 | if (col >0 && col <13) { |
mmlhein | 4:61d3a7c1b411 | 28 | if (col == 12) |
mmlhein | 4:61d3a7c1b411 | 29 | col = 10; |
mmlhein | 4:61d3a7c1b411 | 30 | else if (col ==10) |
mmlhein | 4:61d3a7c1b411 | 31 | col = 7; |
mmlhein | 4:61d3a7c1b411 | 32 | else if (col ==7) |
mmlhein | 4:61d3a7c1b411 | 33 | col = 4; |
mmlhein | 4:61d3a7c1b411 | 34 | else if (col == 4) { |
mmlhein | 4:61d3a7c1b411 | 35 | col =3; |
mmlhein | 4:61d3a7c1b411 | 36 | row =1; |
mmlhein | 4:61d3a7c1b411 | 37 | } else if (col ==3 && row == 1) { |
mmlhein | 4:61d3a7c1b411 | 38 | col = 12; |
mmlhein | 4:61d3a7c1b411 | 39 | row = 0; |
mmlhein | 4:61d3a7c1b411 | 40 | } else |
mmlhein | 4:61d3a7c1b411 | 41 | col = 4; |
mmlhein | 9:b53b3bb0166a | 42 | } else |
mmlhein | 4:61d3a7c1b411 | 43 | col = 4; |
mmlhein | 9:b53b3bb0166a | 44 | } else if(state_menu) { |
mmlhein | 9:b53b3bb0166a | 45 | if (col >0 && col <13) { |
mmlhein | 9:b53b3bb0166a | 46 | if(col == 3) { |
hafizul_arif | 5:fc218b8312eb | 47 | col = 9; |
mmlhein | 9:b53b3bb0166a | 48 | } else if(col == 9) { |
mmlhein | 9:b53b3bb0166a | 49 | col = 3; |
mmlhein | 9:b53b3bb0166a | 50 | } else { |
mmlhein | 9:b53b3bb0166a | 51 | col=3; |
mmlhein | 9:b53b3bb0166a | 52 | row=1; |
hafizul_arif | 5:fc218b8312eb | 53 | } |
mmlhein | 9:b53b3bb0166a | 54 | } else { |
hafizul_arif | 5:fc218b8312eb | 55 | col =3; |
hafizul_arif | 5:fc218b8312eb | 56 | row =1; |
mmlhein | 9:b53b3bb0166a | 57 | } |
mmlhein | 9:b53b3bb0166a | 58 | } else if(state_alarm) { |
mmlhein | 9:b53b3bb0166a | 59 | if (col >0 && col <13) { |
mmlhein | 9:b53b3bb0166a | 60 | if (col == 12) |
mmlhein | 9:b53b3bb0166a | 61 | col = 10; |
mmlhein | 9:b53b3bb0166a | 62 | else if (col ==10) |
mmlhein | 9:b53b3bb0166a | 63 | col = 7; |
mmlhein | 9:b53b3bb0166a | 64 | else if (col ==7) |
mmlhein | 9:b53b3bb0166a | 65 | col = 4; |
mmlhein | 9:b53b3bb0166a | 66 | else if (col == 4) { |
mmlhein | 9:b53b3bb0166a | 67 | col =3; |
mmlhein | 9:b53b3bb0166a | 68 | row =1; |
mmlhein | 9:b53b3bb0166a | 69 | } else if (col ==3 && row == 1) { |
mmlhein | 9:b53b3bb0166a | 70 | col = 9; |
mmlhein | 9:b53b3bb0166a | 71 | row = 1; |
mmlhein | 9:b53b3bb0166a | 72 | } else if( col == 9 && row ==1) { |
mmlhein | 9:b53b3bb0166a | 73 | col = 12; |
mmlhein | 9:b53b3bb0166a | 74 | row = 0; |
mmlhein | 9:b53b3bb0166a | 75 | } else |
mmlhein | 9:b53b3bb0166a | 76 | col = 4; |
mmlhein | 9:b53b3bb0166a | 77 | } else { |
mmlhein | 9:b53b3bb0166a | 78 | col=3; |
mmlhein | 9:b53b3bb0166a | 79 | row=1; |
mmlhein | 9:b53b3bb0166a | 80 | } |
mmlhein | 9:b53b3bb0166a | 81 | } else if (state_set) { |
mmlhein | 9:b53b3bb0166a | 82 | if (col >0 && col <13) { |
mmlhein | 9:b53b3bb0166a | 83 | if (col == 12) |
mmlhein | 9:b53b3bb0166a | 84 | col = 10; |
mmlhein | 9:b53b3bb0166a | 85 | else if (col ==10) |
mmlhein | 9:b53b3bb0166a | 86 | col = 7; |
mmlhein | 9:b53b3bb0166a | 87 | else if (col ==7) |
mmlhein | 9:b53b3bb0166a | 88 | col = 4; |
mmlhein | 9:b53b3bb0166a | 89 | else if (col == 4) { |
mmlhein | 9:b53b3bb0166a | 90 | col =3; |
mmlhein | 9:b53b3bb0166a | 91 | row =1; |
mmlhein | 9:b53b3bb0166a | 92 | } else if (col ==3 && row == 1) { |
mmlhein | 9:b53b3bb0166a | 93 | col = 9; |
mmlhein | 9:b53b3bb0166a | 94 | row = 1; |
mmlhein | 9:b53b3bb0166a | 95 | } else if (col ==9 && row==1) { |
mmlhein | 9:b53b3bb0166a | 96 | col = 12; |
mmlhein | 9:b53b3bb0166a | 97 | row = 0; |
mmlhein | 9:b53b3bb0166a | 98 | } else { |
mmlhein | 9:b53b3bb0166a | 99 | col = 4; |
mmlhein | 9:b53b3bb0166a | 100 | } |
mmlhein | 9:b53b3bb0166a | 101 | } else { |
hafizul_arif | 5:fc218b8312eb | 102 | col = 9; |
hafizul_arif | 5:fc218b8312eb | 103 | row = 1; |
mmlhein | 9:b53b3bb0166a | 104 | } |
mmlhein | 9:b53b3bb0166a | 105 | } |
mmlhein | 4:61d3a7c1b411 | 106 | pc.printf("Cursor left: %i,%i\r\n", col, row); |
ebrahimatya | 0:65f054e83dac | 107 | } |
ebrahimatya | 0:65f054e83dac | 108 | |
mmlhein | 4:61d3a7c1b411 | 109 | void cursor_right() |
ebrahimatya | 0:65f054e83dac | 110 | { |
mmlhein | 4:61d3a7c1b411 | 111 | if(state_init) { |
mmlhein | 9:b53b3bb0166a | 112 | if (col >0 && col <13) { |
mmlhein | 9:b53b3bb0166a | 113 | if (col == 12) { |
mmlhein | 4:61d3a7c1b411 | 114 | col =3; |
mmlhein | 4:61d3a7c1b411 | 115 | row =1; |
mmlhein | 9:b53b3bb0166a | 116 | } else if (col ==10) |
mmlhein | 4:61d3a7c1b411 | 117 | col = 12; |
mmlhein | 4:61d3a7c1b411 | 118 | else if (col ==7) |
mmlhein | 4:61d3a7c1b411 | 119 | col = 10; |
mmlhein | 4:61d3a7c1b411 | 120 | else if (col == 4) { |
mmlhein | 4:61d3a7c1b411 | 121 | col = 7; |
mmlhein | 4:61d3a7c1b411 | 122 | } else if (col ==3 && row == 1) { |
mmlhein | 4:61d3a7c1b411 | 123 | col = 4; |
mmlhein | 4:61d3a7c1b411 | 124 | row = 0; |
mmlhein | 4:61d3a7c1b411 | 125 | } else |
mmlhein | 4:61d3a7c1b411 | 126 | col = 4; |
mmlhein | 9:b53b3bb0166a | 127 | } else |
mmlhein | 4:61d3a7c1b411 | 128 | col = 4; |
mmlhein | 9:b53b3bb0166a | 129 | } else if(state_menu) { |
mmlhein | 9:b53b3bb0166a | 130 | if (col >0 && col <13) { |
mmlhein | 9:b53b3bb0166a | 131 | if(col == 3) { |
hafizul_arif | 5:fc218b8312eb | 132 | col = 9; |
mmlhein | 9:b53b3bb0166a | 133 | } else if(col == 9) { |
mmlhein | 9:b53b3bb0166a | 134 | col = 3; |
hafizul_arif | 5:fc218b8312eb | 135 | } |
mmlhein | 9:b53b3bb0166a | 136 | } else { |
mmlhein | 9:b53b3bb0166a | 137 | col = 3; |
mmlhein | 9:b53b3bb0166a | 138 | row =1; |
mmlhein | 9:b53b3bb0166a | 139 | } |
mmlhein | 9:b53b3bb0166a | 140 | } else if(state_alarm) { |
mmlhein | 9:b53b3bb0166a | 141 | if (col >0 && col <13) { |
mmlhein | 9:b53b3bb0166a | 142 | if (col == 12) { |
hafizul_arif | 5:fc218b8312eb | 143 | col =9; |
hafizul_arif | 5:fc218b8312eb | 144 | row =1; |
mmlhein | 9:b53b3bb0166a | 145 | } else if (col ==10) |
mmlhein | 9:b53b3bb0166a | 146 | col = 12; |
mmlhein | 9:b53b3bb0166a | 147 | else if (col ==7) |
mmlhein | 9:b53b3bb0166a | 148 | col = 10; |
mmlhein | 9:b53b3bb0166a | 149 | else if (col == 4) { |
mmlhein | 9:b53b3bb0166a | 150 | col = 7; |
mmlhein | 9:b53b3bb0166a | 151 | } else if (col ==3 && row == 1) { |
mmlhein | 9:b53b3bb0166a | 152 | col = 4; |
mmlhein | 9:b53b3bb0166a | 153 | row = 0; |
mmlhein | 9:b53b3bb0166a | 154 | } else if(col == 9 && row == 1) { |
mmlhein | 9:b53b3bb0166a | 155 | col = 3; |
mmlhein | 9:b53b3bb0166a | 156 | row = 1; |
mmlhein | 9:b53b3bb0166a | 157 | } else |
mmlhein | 9:b53b3bb0166a | 158 | col = 4; |
mmlhein | 9:b53b3bb0166a | 159 | } else { |
mmlhein | 9:b53b3bb0166a | 160 | col = 3; |
mmlhein | 9:b53b3bb0166a | 161 | row=1; |
mmlhein | 9:b53b3bb0166a | 162 | } |
mmlhein | 9:b53b3bb0166a | 163 | } else if (state_set) { |
mmlhein | 9:b53b3bb0166a | 164 | if (col >0 && col <13) { |
mmlhein | 9:b53b3bb0166a | 165 | if (col == 12) { |
mmlhein | 9:b53b3bb0166a | 166 | col =9; |
mmlhein | 9:b53b3bb0166a | 167 | row =1; |
mmlhein | 9:b53b3bb0166a | 168 | } else if (col ==10) |
hafizul_arif | 5:fc218b8312eb | 169 | col = 12; |
hafizul_arif | 5:fc218b8312eb | 170 | else if (col ==7) |
hafizul_arif | 5:fc218b8312eb | 171 | col = 10; |
hafizul_arif | 5:fc218b8312eb | 172 | else if (col == 4) { |
hafizul_arif | 5:fc218b8312eb | 173 | col = 7; |
hafizul_arif | 5:fc218b8312eb | 174 | } else if (col ==3 && row == 1) { |
hafizul_arif | 5:fc218b8312eb | 175 | col = 4; |
hafizul_arif | 5:fc218b8312eb | 176 | row = 0; |
mmlhein | 9:b53b3bb0166a | 177 | } else if (col == 9 && row ==1) { |
mmlhein | 9:b53b3bb0166a | 178 | col = 4; |
hafizul_arif | 5:fc218b8312eb | 179 | row = 1; |
mmlhein | 9:b53b3bb0166a | 180 | } else { |
hafizul_arif | 5:fc218b8312eb | 181 | col = 4; |
mmlhein | 9:b53b3bb0166a | 182 | } |
mmlhein | 9:b53b3bb0166a | 183 | } else { |
mmlhein | 9:b53b3bb0166a | 184 | col = 9; |
mmlhein | 9:b53b3bb0166a | 185 | row = 1; |
mmlhein | 9:b53b3bb0166a | 186 | } |
mmlhein | 9:b53b3bb0166a | 187 | } |
mmlhein | 4:61d3a7c1b411 | 188 | pc.printf("Cursor right: %i,%i\r\n", col, row); |
ebrahimatya | 0:65f054e83dac | 189 | } |
mmlhein | 9:b53b3bb0166a | 190 | /* |
mmlhein | 9:b53b3bb0166a | 191 | chg_time_{up,down} only functing at state_init or state_alarm |
mmlhein | 9:b53b3bb0166a | 192 | */ |
mmlhein | 9:b53b3bb0166a | 193 | void chg_time_up() |
mmlhein | 9:b53b3bb0166a | 194 | { |
mmlhein | 9:b53b3bb0166a | 195 | if(state_init) { |
mmlhein | 9:b53b3bb0166a | 196 | if (col ==10) { |
mmlhein | 4:61d3a7c1b411 | 197 | r_sec = r_sec +1; |
mmlhein | 4:61d3a7c1b411 | 198 | if (r_sec > 59) |
mmlhein | 9:b53b3bb0166a | 199 | r_sec = 0; |
mmlhein | 9:b53b3bb0166a | 200 | } else if (col ==7) { |
mmlhein | 4:61d3a7c1b411 | 201 | r_min = r_min + 1; |
mmlhein | 4:61d3a7c1b411 | 202 | if (r_min > 59) |
mmlhein | 9:b53b3bb0166a | 203 | r_min = 0; |
mmlhein | 9:b53b3bb0166a | 204 | } else if (col ==4) { |
mmlhein | 4:61d3a7c1b411 | 205 | r_hour = r_hour + 1; |
mmlhein | 4:61d3a7c1b411 | 206 | if (r_hour > 12) |
mmlhein | 9:b53b3bb0166a | 207 | r_hour = 1; |
mmlhein | 9:b53b3bb0166a | 208 | } else if (col == 12) { |
mmlhein | 4:61d3a7c1b411 | 209 | if(r_apm==0) |
mmlhein | 4:61d3a7c1b411 | 210 | r_apm=1; |
mmlhein | 4:61d3a7c1b411 | 211 | else |
mmlhein | 4:61d3a7c1b411 | 212 | r_apm=0; |
mmlhein | 9:b53b3bb0166a | 213 | } else |
mmlhein | 4:61d3a7c1b411 | 214 | pc.printf("lmfao"); |
mmlhein | 6:167533262100 | 215 | pc.printf("\nUP: %d:%d:%d %d\r\n", r_hour, r_min, r_sec, r_apm); |
mmlhein | 9:b53b3bb0166a | 216 | } else if(state_alarm) { |
mmlhein | 9:b53b3bb0166a | 217 | if (col ==10) { |
hafizul_arif | 5:fc218b8312eb | 218 | alarm_sec = alarm_sec +1; |
hafizul_arif | 5:fc218b8312eb | 219 | if (alarm_sec > 59) |
mmlhein | 9:b53b3bb0166a | 220 | alarm_sec = 0; |
mmlhein | 9:b53b3bb0166a | 221 | } else if (col ==7) { |
hafizul_arif | 5:fc218b8312eb | 222 | alarm_min = alarm_min + 1; |
hafizul_arif | 5:fc218b8312eb | 223 | if (alarm_min > 59) |
mmlhein | 9:b53b3bb0166a | 224 | alarm_min = 0; |
mmlhein | 9:b53b3bb0166a | 225 | } else if (col ==4) { |
hafizul_arif | 5:fc218b8312eb | 226 | alarm_hour = alarm_hour + 1; |
hafizul_arif | 5:fc218b8312eb | 227 | if (alarm_hour > 12) |
mmlhein | 9:b53b3bb0166a | 228 | alarm_hour = 1; |
mmlhein | 9:b53b3bb0166a | 229 | } else if (col == 12) { |
hafizul_arif | 5:fc218b8312eb | 230 | if(alarm_apm==0) |
hafizul_arif | 5:fc218b8312eb | 231 | alarm_apm=1; |
hafizul_arif | 5:fc218b8312eb | 232 | else |
hafizul_arif | 5:fc218b8312eb | 233 | alarm_apm=0; |
mmlhein | 9:b53b3bb0166a | 234 | } else |
hafizul_arif | 5:fc218b8312eb | 235 | pc.printf("lmfao"); |
mmlhein | 6:167533262100 | 236 | pc.printf("\nUP: %d:%d:%d %d\r\n", alarm_hour, alarm_min, alarm_sec, alarm_apm); |
mmlhein | 9:b53b3bb0166a | 237 | } |
mmlhein | 9:b53b3bb0166a | 238 | |
mmlhein | 4:61d3a7c1b411 | 239 | } |
mmlhein | 9:b53b3bb0166a | 240 | |
mmlhein | 4:61d3a7c1b411 | 241 | void chg_time_down() |
ebrahimatya | 0:65f054e83dac | 242 | { |
mmlhein | 9:b53b3bb0166a | 243 | if(state_init) { |
mmlhein | 9:b53b3bb0166a | 244 | if (col ==10) { |
mmlhein | 4:61d3a7c1b411 | 245 | r_sec = r_sec - 1; |
mmlhein | 4:61d3a7c1b411 | 246 | if (r_sec < 0) |
mmlhein | 9:b53b3bb0166a | 247 | r_sec = 59; |
mmlhein | 9:b53b3bb0166a | 248 | } else if (col ==7) { |
mmlhein | 4:61d3a7c1b411 | 249 | r_min = r_min - 1; |
mmlhein | 4:61d3a7c1b411 | 250 | if (r_min < 0) |
mmlhein | 9:b53b3bb0166a | 251 | r_min = 59; |
mmlhein | 9:b53b3bb0166a | 252 | } else if (col ==4) { |
mmlhein | 4:61d3a7c1b411 | 253 | r_hour = r_hour - 1; |
mmlhein | 4:61d3a7c1b411 | 254 | if (r_hour < 1) |
mmlhein | 9:b53b3bb0166a | 255 | r_hour = 12; |
mmlhein | 9:b53b3bb0166a | 256 | } else if (col == 12) { |
mmlhein | 4:61d3a7c1b411 | 257 | if(r_apm==0) |
mmlhein | 4:61d3a7c1b411 | 258 | r_apm=1; |
mmlhein | 4:61d3a7c1b411 | 259 | else |
mmlhein | 4:61d3a7c1b411 | 260 | r_apm=0; |
mmlhein | 9:b53b3bb0166a | 261 | } else |
mmlhein | 4:61d3a7c1b411 | 262 | pc.printf("lmfao"); |
mmlhein | 9:b53b3bb0166a | 263 | pc.printf("\nDown clock: %d:%d:%d %d\r\n", r_hour, r_min, r_sec, r_apm); |
mmlhein | 9:b53b3bb0166a | 264 | } else if(state_alarm) { |
mmlhein | 9:b53b3bb0166a | 265 | if (col ==10) { |
hafizul_arif | 5:fc218b8312eb | 266 | alarm_sec = alarm_sec - 1; |
hafizul_arif | 5:fc218b8312eb | 267 | if (alarm_sec < 0) |
mmlhein | 9:b53b3bb0166a | 268 | alarm_sec = 59; |
mmlhein | 9:b53b3bb0166a | 269 | } else if (col ==7) { |
hafizul_arif | 5:fc218b8312eb | 270 | alarm_min = alarm_min - 1; |
hafizul_arif | 5:fc218b8312eb | 271 | if (alarm_min < 0) |
mmlhein | 9:b53b3bb0166a | 272 | alarm_min = 59; |
mmlhein | 9:b53b3bb0166a | 273 | } else if (col ==4) { |
hafizul_arif | 5:fc218b8312eb | 274 | alarm_hour = alarm_hour - 1; |
hafizul_arif | 5:fc218b8312eb | 275 | if (alarm_hour < 1) |
mmlhein | 9:b53b3bb0166a | 276 | alarm_hour = 12; |
mmlhein | 9:b53b3bb0166a | 277 | } else if (col == 12) { |
hafizul_arif | 5:fc218b8312eb | 278 | if(alarm_apm==0) |
hafizul_arif | 5:fc218b8312eb | 279 | alarm_apm=1; |
hafizul_arif | 5:fc218b8312eb | 280 | else |
hafizul_arif | 5:fc218b8312eb | 281 | alarm_apm=0; |
mmlhein | 9:b53b3bb0166a | 282 | } else |
hafizul_arif | 5:fc218b8312eb | 283 | pc.printf("lmfao"); |
mmlhein | 9:b53b3bb0166a | 284 | pc.printf("\nDown alarm: %d:%d:%d %d\r\n", alarm_hour, alarm_min, alarm_sec, alarm_apm); |
mmlhein | 9:b53b3bb0166a | 285 | } |
ebrahimatya | 0:65f054e83dac | 286 | } |
mmlhein | 9:b53b3bb0166a | 287 | /* |
mmlhein | 9:b53b3bb0166a | 288 | Display sections. |
mmlhein | 9:b53b3bb0166a | 289 | */ |
mmlhein | 9:b53b3bb0166a | 290 | void show_menu() |
mmlhein | 9:b53b3bb0166a | 291 | { |
mmlhein | 9:b53b3bb0166a | 292 | if(alarm_up) { |
mmlhein | 6:167533262100 | 293 | lcd.locate(2,1); |
mmlhein | 6:167533262100 | 294 | lcd.printf("*"); |
mmlhein | 9:b53b3bb0166a | 295 | } else { |
mmlhein | 6:167533262100 | 296 | lcd.locate(2,1); |
mmlhein | 6:167533262100 | 297 | lcd.printf(" "); |
mmlhein | 6:167533262100 | 298 | } |
mmlhein | 6:167533262100 | 299 | lcd.locate(3,1); |
mmlhein | 6:167533262100 | 300 | lcd.printf("Alarm"); |
mmlhein | 6:167533262100 | 301 | lcd.locate(9,1); |
mmlhein | 6:167533262100 | 302 | lcd.printf("Set"); |
mmlhein | 6:167533262100 | 303 | } |
mmlhein | 9:b53b3bb0166a | 304 | void view_clock() |
mmlhein | 9:b53b3bb0166a | 305 | { |
mmlhein | 9:b53b3bb0166a | 306 | lcd.locate(3,0); |
mmlhein | 9:b53b3bb0166a | 307 | time_t seconds = time(NULL); |
mmlhein | 9:b53b3bb0166a | 308 | char buffer[32]; |
mmlhein | 9:b53b3bb0166a | 309 | strftime(buffer, 32, "%I:%M:%S %p", localtime(&seconds)); |
mmlhein | 9:b53b3bb0166a | 310 | lcd.printf("%s", buffer); |
mmlhein | 9:b53b3bb0166a | 311 | |
mmlhein | 9:b53b3bb0166a | 312 | //Print main Menu |
mmlhein | 9:b53b3bb0166a | 313 | show_menu(); |
mmlhein | 9:b53b3bb0166a | 314 | // Update our clock string. |
mmlhein | 9:b53b3bb0166a | 315 | clock_string = buffer; |
mmlhein | 8:c8421fc56e8f | 316 | } |
mmlhein | 9:b53b3bb0166a | 317 | void blink_cursor() |
mmlhein | 9:b53b3bb0166a | 318 | { |
mmlhein | 6:167533262100 | 319 | lcd.locate(col, row); |
mmlhein | 6:167533262100 | 320 | lcd.printf("_"); |
mmlhein | 9:b53b3bb0166a | 321 | } |
mmlhein | 6:167533262100 | 322 | void blink_num() |
mmlhein | 6:167533262100 | 323 | { |
mmlhein | 9:b53b3bb0166a | 324 | |
mmlhein | 9:b53b3bb0166a | 325 | if (r_hour > 9) { |
mmlhein | 6:167533262100 | 326 | lcd.locate(3,0); |
mmlhein | 6:167533262100 | 327 | lcd.printf("%d:", r_hour); |
mmlhein | 9:b53b3bb0166a | 328 | } else { |
mmlhein | 6:167533262100 | 329 | lcd.locate(3,0); |
mmlhein | 6:167533262100 | 330 | lcd.printf("0%d:", r_hour); |
mmlhein | 6:167533262100 | 331 | } |
mmlhein | 9:b53b3bb0166a | 332 | if (r_min > 9) { |
mmlhein | 6:167533262100 | 333 | lcd.locate(6,0); |
mmlhein | 6:167533262100 | 334 | lcd.printf("%d:", r_min); |
mmlhein | 9:b53b3bb0166a | 335 | } else { |
mmlhein | 6:167533262100 | 336 | lcd.locate(6,0); |
mmlhein | 6:167533262100 | 337 | lcd.printf("0%d:", r_min); |
mmlhein | 6:167533262100 | 338 | } |
mmlhein | 9:b53b3bb0166a | 339 | if (r_sec > 9) { |
mmlhein | 6:167533262100 | 340 | lcd.locate(9,0); |
mmlhein | 6:167533262100 | 341 | lcd.printf("%d", r_sec); |
mmlhein | 9:b53b3bb0166a | 342 | } else { |
mmlhein | 6:167533262100 | 343 | lcd.locate(9,0); |
mmlhein | 6:167533262100 | 344 | lcd.printf("0%d", r_sec); |
mmlhein | 6:167533262100 | 345 | } |
mmlhein | 6:167533262100 | 346 | lcd.locate(12,0); |
mmlhein | 6:167533262100 | 347 | if (r_apm ==0) |
mmlhein | 6:167533262100 | 348 | lcd.printf("AM"); |
mmlhein | 6:167533262100 | 349 | else |
mmlhein | 6:167533262100 | 350 | lcd.printf("PM"); |
mmlhein | 6:167533262100 | 351 | lcd.locate(3,1); |
mmlhein | 6:167533262100 | 352 | lcd.printf("Done"); |
mmlhein | 9:b53b3bb0166a | 353 | |
mmlhein | 9:b53b3bb0166a | 354 | if (state_set) { // Print "Back" if this is state_set |
mmlhein | 9:b53b3bb0166a | 355 | lcd.locate(9,1); |
mmlhein | 9:b53b3bb0166a | 356 | lcd.printf("Back"); |
mmlhein | 9:b53b3bb0166a | 357 | } |
mmlhein | 6:167533262100 | 358 | return; |
mmlhein | 6:167533262100 | 359 | } |
hafizul_arif | 5:fc218b8312eb | 360 | |
mmlhein | 9:b53b3bb0166a | 361 | void alarm_disp() |
mmlhein | 9:b53b3bb0166a | 362 | { |
mmlhein | 9:b53b3bb0166a | 363 | lcd.cls(); |
mmlhein | 9:b53b3bb0166a | 364 | if (alarm_hour > 9) { |
hafizul_arif | 5:fc218b8312eb | 365 | lcd.locate(3,0); |
hafizul_arif | 5:fc218b8312eb | 366 | lcd.printf("%d:", alarm_hour); |
mmlhein | 9:b53b3bb0166a | 367 | } else { |
hafizul_arif | 5:fc218b8312eb | 368 | lcd.locate(3,0); |
hafizul_arif | 5:fc218b8312eb | 369 | lcd.printf("0%d:", alarm_hour); |
hafizul_arif | 5:fc218b8312eb | 370 | } |
mmlhein | 9:b53b3bb0166a | 371 | if (alarm_min > 9) { |
hafizul_arif | 5:fc218b8312eb | 372 | lcd.locate(6,0); |
hafizul_arif | 5:fc218b8312eb | 373 | lcd.printf("%d:", alarm_min); |
mmlhein | 9:b53b3bb0166a | 374 | } else { |
hafizul_arif | 5:fc218b8312eb | 375 | lcd.locate(6,0); |
hafizul_arif | 5:fc218b8312eb | 376 | lcd.printf("0%d:", alarm_min); |
hafizul_arif | 5:fc218b8312eb | 377 | } |
mmlhein | 9:b53b3bb0166a | 378 | if (alarm_sec > 9) { |
hafizul_arif | 5:fc218b8312eb | 379 | lcd.locate(9,0); |
hafizul_arif | 5:fc218b8312eb | 380 | lcd.printf("%d", alarm_sec); |
mmlhein | 9:b53b3bb0166a | 381 | } else { |
hafizul_arif | 5:fc218b8312eb | 382 | lcd.locate(9,0); |
hafizul_arif | 5:fc218b8312eb | 383 | lcd.printf("0%d", alarm_sec); |
hafizul_arif | 5:fc218b8312eb | 384 | } |
hafizul_arif | 5:fc218b8312eb | 385 | lcd.locate(12,0); |
hafizul_arif | 5:fc218b8312eb | 386 | if (alarm_apm ==0) |
hafizul_arif | 5:fc218b8312eb | 387 | lcd.printf("AM"); |
hafizul_arif | 5:fc218b8312eb | 388 | else |
hafizul_arif | 5:fc218b8312eb | 389 | lcd.printf("PM"); |
hafizul_arif | 5:fc218b8312eb | 390 | lcd.locate(3,1); |
hafizul_arif | 5:fc218b8312eb | 391 | lcd.printf("Off"); |
hafizul_arif | 5:fc218b8312eb | 392 | lcd.locate(9,1); |
hafizul_arif | 5:fc218b8312eb | 393 | lcd.printf("On"); |
hafizul_arif | 5:fc218b8312eb | 394 | return; |
hafizul_arif | 5:fc218b8312eb | 395 | } |
mmlhein | 9:b53b3bb0166a | 396 | |
mmlhein | 9:b53b3bb0166a | 397 | void alarm_sound() |
mmlhein | 9:b53b3bb0166a | 398 | { |
mmlhein | 9:b53b3bb0166a | 399 | float frequency[]= {659,554,659,554,440,494,554,587,494,659,554,440}; //frequency array |
mmlhein | 9:b53b3bb0166a | 400 | float beat[]= {1,1,1,1,1,0.5,0.5,1,1,1,1,2}; //beat array |
mmlhein | 9:b53b3bb0166a | 401 | lcd.cls(); |
mmlhein | 9:b53b3bb0166a | 402 | lcd.printf("Press button to off alarm"); |
mmlhein | 9:b53b3bb0166a | 403 | while(1) { |
mmlhein | 9:b53b3bb0166a | 404 | for(int i=0; i<=11; i++) { |
mmlhein | 9:b53b3bb0166a | 405 | buzzer.period(1/(2*frequency[i]));// set PWM period |
mmlhein | 9:b53b3bb0166a | 406 | buzzer=0.8;// set duty cycle |
mmlhein | 9:b53b3bb0166a | 407 | wait(0.4*beat[i]);// hold for beat period |
mmlhein | 9:b53b3bb0166a | 408 | } |
mmlhein | 9:b53b3bb0166a | 409 | if(joycenter) { //Off the alarm |
mmlhein | 9:b53b3bb0166a | 410 | buzzer.period(0); |
mmlhein | 9:b53b3bb0166a | 411 | buzzer=0; |
mmlhein | 9:b53b3bb0166a | 412 | col=0; |
mmlhein | 9:b53b3bb0166a | 413 | row=0; |
mmlhein | 9:b53b3bb0166a | 414 | lcd.cls(); |
mmlhein | 9:b53b3bb0166a | 415 | break; |
mmlhein | 9:b53b3bb0166a | 416 | } |
mmlhein | 9:b53b3bb0166a | 417 | } |
mmlhein | 9:b53b3bb0166a | 418 | } |
mmlhein | 9:b53b3bb0166a | 419 | |
mmlhein | 9:b53b3bb0166a | 420 | |
mmlhein | 9:b53b3bb0166a | 421 | //Function alarm_chk is in progress |
mmlhein | 9:b53b3bb0166a | 422 | void alarm_chk() |
mmlhein | 9:b53b3bb0166a | 423 | { |
mmlhein | 9:b53b3bb0166a | 424 | //we basically, comparing 2 strings. alarm string and the clock strings if match we ring it |
mmlhein | 9:b53b3bb0166a | 425 | //we want to disable cursor movement. |
mmlhein | 9:b53b3bb0166a | 426 | if(clock_string == alarm_string) { |
mmlhein | 9:b53b3bb0166a | 427 | pc.printf("%s %s : same\r\n", alarm_string, clock_string); |
mmlhein | 9:b53b3bb0166a | 428 | //Disable cursor movement. |
mmlhein | 9:b53b3bb0166a | 429 | state_menu = false; |
mmlhein | 9:b53b3bb0166a | 430 | state_set = false; |
mmlhein | 9:b53b3bb0166a | 431 | state_alarm = false; |
mmlhein | 9:b53b3bb0166a | 432 | blinker_cursor.detach(); |
mmlhein | 9:b53b3bb0166a | 433 | alarm_sound(); |
mmlhein | 9:b53b3bb0166a | 434 | } |
mmlhein | 9:b53b3bb0166a | 435 | blinker_cursor.attach(&blink_cursor, 0.1); |
mmlhein | 9:b53b3bb0166a | 436 | } |
mmlhein | 9:b53b3bb0166a | 437 | |
mmlhein | 8:c8421fc56e8f | 438 | void __set_alarm_string() |
mmlhein | 8:c8421fc56e8f | 439 | { |
mmlhein | 8:c8421fc56e8f | 440 | char buffer_alarm[32]; |
mmlhein | 8:c8421fc56e8f | 441 | alarm_string.clear(); |
mmlhein | 8:c8421fc56e8f | 442 | if(alarm_hour <9) { |
mmlhein | 8:c8421fc56e8f | 443 | sprintf (buffer_alarm, "0%d:", alarm_hour); |
mmlhein | 8:c8421fc56e8f | 444 | } else { |
mmlhein | 8:c8421fc56e8f | 445 | sprintf (buffer_alarm, "%d:", alarm_hour); |
mmlhein | 8:c8421fc56e8f | 446 | } |
mmlhein | 8:c8421fc56e8f | 447 | alarm_string += buffer_alarm; |
mmlhein | 8:c8421fc56e8f | 448 | if (alarm_min <9) { |
mmlhein | 8:c8421fc56e8f | 449 | sprintf (buffer_alarm, "0%d:", alarm_min); |
mmlhein | 8:c8421fc56e8f | 450 | } else { |
mmlhein | 8:c8421fc56e8f | 451 | sprintf (buffer_alarm, "%d:", alarm_min); |
mmlhein | 8:c8421fc56e8f | 452 | } |
mmlhein | 8:c8421fc56e8f | 453 | alarm_string += buffer_alarm; |
mmlhein | 8:c8421fc56e8f | 454 | if (alarm_sec<9) { |
mmlhein | 8:c8421fc56e8f | 455 | sprintf (buffer_alarm, "0%d", alarm_sec); |
mmlhein | 8:c8421fc56e8f | 456 | } else { |
mmlhein | 8:c8421fc56e8f | 457 | sprintf (buffer_alarm, "%d", alarm_sec); |
mmlhein | 8:c8421fc56e8f | 458 | } |
mmlhein | 8:c8421fc56e8f | 459 | alarm_string += buffer_alarm; |
mmlhein | 8:c8421fc56e8f | 460 | if(alarm_apm ==0) { |
mmlhein | 8:c8421fc56e8f | 461 | sprintf (buffer_alarm, " %s", "AM"); |
mmlhein | 8:c8421fc56e8f | 462 | } else { |
mmlhein | 8:c8421fc56e8f | 463 | sprintf (buffer_alarm, " %s", "PM"); |
mmlhein | 8:c8421fc56e8f | 464 | } |
mmlhein | 8:c8421fc56e8f | 465 | alarm_string += buffer_alarm; |
mmlhein | 8:c8421fc56e8f | 466 | } |
mmlhein | 9:b53b3bb0166a | 467 | |
mmlhein | 9:b53b3bb0166a | 468 | /* |
mmlhein | 9:b53b3bb0166a | 469 | state section. |
mmlhein | 9:b53b3bb0166a | 470 | */ |
mmlhein | 8:c8421fc56e8f | 471 | void setup_alarm() |
mmlhein | 8:c8421fc56e8f | 472 | { |
hafizul_arif | 5:fc218b8312eb | 473 | state_alarm = true; |
hafizul_arif | 5:fc218b8312eb | 474 | state_menu = false; |
hafizul_arif | 5:fc218b8312eb | 475 | blinker_numer.attach(&alarm_disp,0.5); |
mmlhein | 8:c8421fc56e8f | 476 | while(1) { |
hafizul_arif | 5:fc218b8312eb | 477 | wait(1); |
mmlhein | 8:c8421fc56e8f | 478 | if(col == 3 && row ==1) { |
mmlhein | 8:c8421fc56e8f | 479 | if(joycenter) { //Turn off Alarm and back to main menu |
mmlhein | 9:b53b3bb0166a | 480 | blinker_numer.detach();//stop alarm_disp |
hafizul_arif | 5:fc218b8312eb | 481 | state_alarm = false; |
hafizul_arif | 5:fc218b8312eb | 482 | state_menu = true; |
hafizul_arif | 5:fc218b8312eb | 483 | alarm_up = false; |
hafizul_arif | 5:fc218b8312eb | 484 | check_alarm.detach(); |
mmlhein | 8:c8421fc56e8f | 485 | alarm_string.clear(); |
mmlhein | 9:b53b3bb0166a | 486 | col=0; |
mmlhein | 9:b53b3bb0166a | 487 | row=0; |
hafizul_arif | 5:fc218b8312eb | 488 | break; |
hafizul_arif | 5:fc218b8312eb | 489 | } |
mmlhein | 8:c8421fc56e8f | 490 | } else if(col == 9 && row == 1) {//Turn on Alarm and back to main menu |
mmlhein | 8:c8421fc56e8f | 491 | if(joycenter) { |
hafizul_arif | 5:fc218b8312eb | 492 | blinker_numer.detach(); |
hafizul_arif | 5:fc218b8312eb | 493 | state_alarm = false; |
hafizul_arif | 5:fc218b8312eb | 494 | state_menu = true; |
mmlhein | 9:b53b3bb0166a | 495 | alarm_up = true; |
mmlhein | 9:b53b3bb0166a | 496 | // Turn on the alarm. |
hafizul_arif | 5:fc218b8312eb | 497 | check_alarm.attach(&alarm_chk,1); |
mmlhein | 9:b53b3bb0166a | 498 | // Set alarm string |
mmlhein | 8:c8421fc56e8f | 499 | __set_alarm_string(); |
mmlhein | 9:b53b3bb0166a | 500 | col=0; |
mmlhein | 9:b53b3bb0166a | 501 | row=0; |
hafizul_arif | 5:fc218b8312eb | 502 | break; |
hafizul_arif | 5:fc218b8312eb | 503 | } |
hafizul_arif | 5:fc218b8312eb | 504 | } |
mmlhein | 9:b53b3bb0166a | 505 | state_alarm = true; |
mmlhein | 9:b53b3bb0166a | 506 | state_menu = false; |
hafizul_arif | 5:fc218b8312eb | 507 | } |
hafizul_arif | 5:fc218b8312eb | 508 | } |
hafizul_arif | 5:fc218b8312eb | 509 | |
mmlhein | 9:b53b3bb0166a | 510 | void setup_init() |
mmlhein | 9:b53b3bb0166a | 511 | { |
mmlhein | 10:2a47ac757d14 | 512 | if (state_set) { |
mmlhein | 10:2a47ac757d14 | 513 | state_init = false; |
mmlhein | 10:2a47ac757d14 | 514 | state_menu = false; |
mmlhein | 10:2a47ac757d14 | 515 | } else { |
mmlhein | 10:2a47ac757d14 | 516 | state_init = true; |
mmlhein | 10:2a47ac757d14 | 517 | state_menu = false; |
mmlhein | 10:2a47ac757d14 | 518 | } |
mmlhein | 10:2a47ac757d14 | 519 | |
mmlhein | 8:c8421fc56e8f | 520 | lcd.cls(); |
mmlhein | 4:61d3a7c1b411 | 521 | blinker_cursor.attach(&blink_cursor, 0.1); |
mmlhein | 4:61d3a7c1b411 | 522 | blinker_numer.attach(&blink_num, 0.5); |
mmlhein | 9:b53b3bb0166a | 523 | while (1) { |
mmlhein | 4:61d3a7c1b411 | 524 | // This is where, we select "Done", and we press joycenter to end the initial setup. |
mmlhein | 9:b53b3bb0166a | 525 | if(col==3 && row==1) { |
mmlhein | 9:b53b3bb0166a | 526 | if(joycenter) { |
mmlhein | 9:b53b3bb0166a | 527 | blinker_numer.detach(); // Stop viewing number. |
mmlhein | 9:b53b3bb0166a | 528 | blinker_cursor.detach(); // Stop blinking the cursor. |
mmlhein | 9:b53b3bb0166a | 529 | |
mmlhein | 4:61d3a7c1b411 | 530 | //Calculate the unix timestamp |
mmlhein | 4:61d3a7c1b411 | 531 | //1h : 3600, 1m: 60, 1s: 1 |
mmlhein | 9:b53b3bb0166a | 532 | if(r_apm==0) { // AM |
mmlhein | 4:61d3a7c1b411 | 533 | if(r_hour ==12) |
mmlhein | 4:61d3a7c1b411 | 534 | epoch = (0 *3600) + (r_min *60) +(r_sec); |
mmlhein | 4:61d3a7c1b411 | 535 | else |
mmlhein | 4:61d3a7c1b411 | 536 | epoch = (r_hour *3600) + (r_min *60) +(r_sec); |
mmlhein | 9:b53b3bb0166a | 537 | } else if (r_apm ==1) { //PM |
mmlhein | 4:61d3a7c1b411 | 538 | if(r_hour ==12) |
mmlhein | 4:61d3a7c1b411 | 539 | epoch = (r_hour *3600) + (r_min *60) +(r_sec); |
mmlhein | 4:61d3a7c1b411 | 540 | else |
mmlhein | 4:61d3a7c1b411 | 541 | epoch = 43200+(r_hour *3600) + (r_min *60) +(r_sec); |
mmlhein | 9:b53b3bb0166a | 542 | } |
mmlhein | 9:b53b3bb0166a | 543 | |
mmlhein | 8:c8421fc56e8f | 544 | pc.printf("%d\r\n", epoch); |
mmlhein | 9:b53b3bb0166a | 545 | // Set time base on epoch value. |
mmlhein | 8:c8421fc56e8f | 546 | set_time(epoch); |
mmlhein | 9:b53b3bb0166a | 547 | |
mmlhein | 9:b53b3bb0166a | 548 | // When setup_init() done, we move the cursor to default state, |
mmlhein | 9:b53b3bb0166a | 549 | row=0; |
mmlhein | 9:b53b3bb0166a | 550 | col=0; |
mmlhein | 9:b53b3bb0166a | 551 | |
mmlhein | 4:61d3a7c1b411 | 552 | state_init = false; |
mmlhein | 9:b53b3bb0166a | 553 | state_menu = true; |
mmlhein | 10:2a47ac757d14 | 554 | state_set = false; |
mmlhein | 9:b53b3bb0166a | 555 | break; |
mmlhein | 4:61d3a7c1b411 | 556 | } |
mmlhein | 10:2a47ac757d14 | 557 | } else if (col ==9 && row ==1) {//back button is pressed |
mmlhein | 10:2a47ac757d14 | 558 | // When setup_init() done, we move the cursor to default state, |
mmlhein | 10:2a47ac757d14 | 559 | row=0; |
mmlhein | 10:2a47ac757d14 | 560 | col=0; |
mmlhein | 10:2a47ac757d14 | 561 | state_init =false; |
mmlhein | 10:2a47ac757d14 | 562 | state_menu = true; |
mmlhein | 10:2a47ac757d14 | 563 | state_set = false; |
mmlhein | 10:2a47ac757d14 | 564 | break; |
mmlhein | 9:b53b3bb0166a | 565 | } |
ebrahimatya | 0:65f054e83dac | 566 | } |
ebrahimatya | 0:65f054e83dac | 567 | } |
mmlhein | 9:b53b3bb0166a | 568 | |
mmlhein | 9:b53b3bb0166a | 569 | /* |
mmlhein | 9:b53b3bb0166a | 570 | Always back to main_menu state. |
mmlhein | 9:b53b3bb0166a | 571 | */ |
mmlhein | 9:b53b3bb0166a | 572 | void main_menu() |
mmlhein | 4:61d3a7c1b411 | 573 | { |
mmlhein | 9:b53b3bb0166a | 574 | state_menu = true; |
mmlhein | 9:b53b3bb0166a | 575 | // Start viewing clock! |
mmlhein | 9:b53b3bb0166a | 576 | clock_viewer.attach(&view_clock,1); |
mmlhein | 9:b53b3bb0166a | 577 | blinker_cursor.attach(&blink_cursor, 0.1); |
mmlhein | 9:b53b3bb0166a | 578 | lcd.cls(); |
ebrahimatya | 0:65f054e83dac | 579 | |
mmlhein | 9:b53b3bb0166a | 580 | while(1) { |
hafizul_arif | 5:fc218b8312eb | 581 | wait(1); |
mmlhein | 9:b53b3bb0166a | 582 | if(col == 3 && row == 1) { |
mmlhein | 9:b53b3bb0166a | 583 | if(joycenter) { |
hafizul_arif | 5:fc218b8312eb | 584 | clock_viewer.detach(); |
mmlhein | 6:167533262100 | 585 | setup_alarm(); |
hafizul_arif | 5:fc218b8312eb | 586 | clock_viewer.attach(&view_clock,1); |
hafizul_arif | 5:fc218b8312eb | 587 | } |
mmlhein | 9:b53b3bb0166a | 588 | } else if(col == 9 && row ==1) { |
mmlhein | 9:b53b3bb0166a | 589 | if(joycenter) { |
mmlhein | 8:c8421fc56e8f | 590 | clock_viewer.detach(); |
mmlhein | 9:b53b3bb0166a | 591 | state_set = true; |
mmlhein | 8:c8421fc56e8f | 592 | setup_init(); |
mmlhein | 8:c8421fc56e8f | 593 | clock_viewer.attach(&view_clock,1); |
hafizul_arif | 5:fc218b8312eb | 594 | } |
hafizul_arif | 5:fc218b8312eb | 595 | } |
mmlhein | 9:b53b3bb0166a | 596 | state_menu = true; |
hafizul_arif | 5:fc218b8312eb | 597 | } |
hafizul_arif | 5:fc218b8312eb | 598 | } |
hafizul_arif | 5:fc218b8312eb | 599 | |
mmlhein | 9:b53b3bb0166a | 600 | /* |
mmlhein | 9:b53b3bb0166a | 601 | main function, duh. |
mmlhein | 9:b53b3bb0166a | 602 | */ |
mmlhein | 9:b53b3bb0166a | 603 | int main() |
mmlhein | 9:b53b3bb0166a | 604 | { |
mmlhein | 9:b53b3bb0166a | 605 | // Initial value for our cursor |
mmlhein | 4:61d3a7c1b411 | 606 | row =0 ; |
mmlhein | 4:61d3a7c1b411 | 607 | col=0 ; |
mmlhein | 9:b53b3bb0166a | 608 | |
mmlhein | 9:b53b3bb0166a | 609 | // Initial value for alarm |
mmlhein | 6:167533262100 | 610 | alarm_hour=12; |
mmlhein | 6:167533262100 | 611 | alarm_min=0; |
mmlhein | 9:b53b3bb0166a | 612 | alarm_sec=0; |
mmlhein | 6:167533262100 | 613 | alarm_apm=0; |
mmlhein | 9:b53b3bb0166a | 614 | // Initial value for clock |
mmlhein | 4:61d3a7c1b411 | 615 | r_hour=12 ; |
mmlhein | 4:61d3a7c1b411 | 616 | r_min=0 ; |
mmlhein | 4:61d3a7c1b411 | 617 | r_sec = 0; |
mmlhein | 4:61d3a7c1b411 | 618 | r_apm = 0; //0-AM, 1-PM |
mmlhein | 4:61d3a7c1b411 | 619 | epoch = 0; // 12:00:00 AM |
mmlhein | 9:b53b3bb0166a | 620 | |
mmlhein | 9:b53b3bb0166a | 621 | // Set joystick to interrupt and call specific function the cursor value. |
mmlhein | 6:167533262100 | 622 | left.rise(&cursor_left); |
mmlhein | 6:167533262100 | 623 | right.rise(&cursor_right); |
mmlhein | 6:167533262100 | 624 | up.rise(&chg_time_up); |
mmlhein | 6:167533262100 | 625 | down.rise(&chg_time_down); |
mmlhein | 9:b53b3bb0166a | 626 | |
mmlhein | 9:b53b3bb0166a | 627 | // Initialize all the state to false. |
mmlhein | 9:b53b3bb0166a | 628 | state_init = false; |
mmlhein | 9:b53b3bb0166a | 629 | state_menu = false; |
mmlhein | 9:b53b3bb0166a | 630 | state_alarm = false; |
mmlhein | 9:b53b3bb0166a | 631 | alarm_up = false; |
mmlhein | 9:b53b3bb0166a | 632 | state_set = false; |
mmlhein | 9:b53b3bb0166a | 633 | alarm_ring = false; |
mmlhein | 9:b53b3bb0166a | 634 | |
mmlhein | 6:167533262100 | 635 | /*Run setup init -> show main menu |
mmlhein | 9:b53b3bb0166a | 636 | |_ setup Alarm (state_alarm) |
mmlhein | 6:167533262100 | 637 | | |_Off alarm |
mmlhein | 6:167533262100 | 638 | | |_On alarm |
mmlhein | 9:b53b3bb0166a | 639 | |_ Change time (state_init) |
mmlhein | 9:b53b3bb0166a | 640 | |
mmlhein | 9:b53b3bb0166a | 641 | The up/down only work in state_init and state_alarm |
mmlhein | 9:b53b3bb0166a | 642 | The left/right should work on every state except in state which alarm is ringging. |
mmlhein | 9:b53b3bb0166a | 643 | |
mmlhein | 9:b53b3bb0166a | 644 | Every time we choose the option in any state, the default value for cursor is |
mmlhein | 9:b53b3bb0166a | 645 | col=0 and row=0. This to avoid accidently go to another state. |
mmlhein | 6:167533262100 | 646 | */ |
mmlhein | 4:61d3a7c1b411 | 647 | setup_init(); |
hafizul_arif | 5:fc218b8312eb | 648 | main_menu(); |
mmlhein | 9:b53b3bb0166a | 649 | } |