Skip to content
This repository was archived by the owner on May 16, 2023. It is now read-only.

Commit 157dcaa

Browse files
committed
update : assignment #8
1 parent 4551e46 commit 157dcaa

File tree

6 files changed

+90
-18
lines changed

6 files changed

+90
-18
lines changed

assignment_7/17_0077_0107.ino

+76-18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ struct Time {
1010
int sec;
1111
};
1212

13+
// ==== LDR SETTING ====
14+
#define LDR_PIN A3
15+
unsigned int analogValue;
16+
1317
// ==== OLED SETTING ====
1418
#define OLED_RESET -1
1519
#define SCREEN_WIDTH 128
@@ -60,6 +64,7 @@ Time alarm = { 0, 0, 0 };
6064
Time alarmSave = { 0, 0, 0 };
6165
int onAlarm = 0;
6266

67+
6368
// ==== MODE SETTING ====
6469
#define CLOCK_MODE 0
6570
#define COUNTER_UP_MODE 1
@@ -120,16 +125,22 @@ void timer() {
120125
clock.hour += clock.min / 60;
121126
clock.min %= 60;
122127
clock.hour %= 24;
128+
if (clock.sec == 0) {
129+
EEPROM.update(20, clock.hour);
130+
EEPROM.update(21, clock.min);
131+
}
123132
}
124133

125134
void change_hour() {
126135
clock.hour += 1;
136+
EEPROM.update(20, clock.hour);
127137
clock.hour %= 24;
128138
}
129139

130140
void change_min() {
131141
clock.min += 1;
132142
clock.hour += clock.min / 60;
143+
EEPROM.update(21, clock.min);
133144
clock.min %= 60;
134145
}
135146

@@ -198,8 +209,8 @@ void change_mode() {
198209
}
199210

200211
// ==== Time Text ====
201-
String timerText = "00 : 00 : 00";
202-
String countUpText = "00 : 00 : 00";
212+
String timerText = "00 : 00";
213+
String countUpText = "00 : 00";
203214
// String countDownText = "00 : 00 : 00";
204215
String alarmText = "00 : 00";
205216
String saveAlarmText = "00 : 00";
@@ -210,17 +221,17 @@ void time_text() {
210221
timerText[5] = (clock.min / 10) + '0';
211222
timerText[6] = (clock.min % 10) + '0';
212223

213-
timerText[10] = (clock.sec / 10) + '0';
214-
timerText[11] = (clock.sec % 10) + '0';
224+
// timerText[10] = (clock.sec / 10) + '0';
225+
// timerText[11] = (clock.sec % 10) + '0';
215226

216-
countUpText[0] = (countUp.hour / 10) + '0';
217-
countUpText[1] = (countUp.hour % 10) + '0';
227+
// countUpText[0] = (countUp.hour / 10) + '0';
228+
// countUpText[1] = (countUp.hour % 10) + '0';
218229

219-
countUpText[5] = (countUp.min / 10) + '0';
220-
countUpText[6] = (countUp.min % 10) + '0';
230+
countUpText[0] = (countUp.min / 10) + '0';
231+
countUpText[1] = (countUp.min % 10) + '0';
221232

222-
countUpText[10] = (countUp.sec / 10) + '0';
223-
countUpText[11] = (countUp.sec % 10) + '0';
233+
countUpText[5] = (countUp.sec / 10) + '0';
234+
countUpText[6] = (countUp.sec % 10) + '0';
224235

225236
// countDownText[0] = (countDown.hour / 10) + '0';
226237
// countDownText[1] = (countDown.hour % 10) + '0';
@@ -245,13 +256,27 @@ void time_text() {
245256
}
246257

247258
void display_text(int x1, int y1, String name, int x2, int y2, String timer) {
259+
OLED.setTextSize(1);
248260
OLED.setCursor(x1, y1);
249261
OLED.println(name);
262+
OLED.setTextSize(2);
250263
OLED.setCursor(x2, y2);
251264
OLED.println(timer);
252265
}
253266

254-
267+
void display_alarm() {
268+
OLED.clearDisplay();
269+
OLED.setTextColor(WHITE);
270+
if (analogValue > 900) {
271+
OLED.dim(true);
272+
} else {
273+
OLED.dim(false);
274+
}
275+
OLED.setCursor(10, 10);
276+
OLED.setTextSize(2);
277+
OLED.print("WAKE UP!!");
278+
OLED.display();
279+
}
255280

256281
void setup() {
257282
Serial.begin(9600);
@@ -265,10 +290,28 @@ void setup() {
265290
}
266291
Timer1.initialize(1000000);
267292
Timer1.attachInterrupt(interruptClock);
293+
// ==== WRITE EEPROM ====
294+
// EEPROM.write(20, clock.hour);
295+
// EEPROM.write(21, clock.min);
296+
297+
// ==== READ EEPROM ====
298+
clock.hour = EEPROM.read(20);
299+
clock.min = EEPROM.read(21);
268300
}
269301

270302
void loop() {
271303

304+
unsigned int analogValue = analogRead(LDR_PIN);
305+
306+
OLED.clearDisplay();
307+
OLED.setTextColor(WHITE);
308+
309+
if (analogValue > 900) {
310+
OLED.dim(true);
311+
} else {
312+
OLED.dim(false);
313+
}
314+
272315
if (debounce(0)) {
273316
if (!digitalRead(button[0])) {
274317
switch (MODE) {
@@ -332,11 +375,19 @@ void loop() {
332375
}
333376

334377
if (onAlarm && alarmSave.hour == clock.hour && alarmSave.min == clock.min && clock.sec == 0) {
335-
tone(BUZZER_PIN, 440, 100);
336-
onAlarm = 0;
378+
while (1) {
379+
// tone(BUZZER_PIN, 440, 100);
380+
display_alarm();
381+
if (debounce(0)) {
382+
if (!digitalRead(button[0])) {
383+
OLED.clearDisplay();
384+
onAlarm = 0;
385+
break;
386+
}
387+
}
388+
}
337389
}
338390

339-
340391
// Serial.print(get_x());
341392
// Serial.print(" ");
342393
// Serial.print(get_y());
@@ -345,8 +396,12 @@ void loop() {
345396

346397
time_text();
347398

348-
OLED.clearDisplay();
349-
OLED.setTextColor(WHITE);
399+
400+
if (get_x() > 360) {
401+
OLED.setRotation(2);
402+
} else {
403+
OLED.setRotation(0);
404+
}
350405

351406
switch (MODE) {
352407
case CLOCK_MODE:
@@ -360,9 +415,12 @@ void loop() {
360415
// break;
361416
case ALARM_MODE:
362417
display_text(10, 0, "Alarm", 10, 12, alarmText);
363-
display_text(10, 24, saveAlarmText, 70, 24, onAlarm == 0 ? "OFF" : "ON");
418+
OLED.setTextSize(1);
419+
OLED.setCursor(80, 0);
420+
OLED.println(onAlarm == 0 ? "OFF" : "ON");
421+
// display_text(10, 24, saveAlarmText, 70, 24, onAlarm == 0 ? "OFF" : "ON");
364422
break;
365423
}
366-
OLED.setTextSize(1);
424+
367425
OLED.display();
368426
}

assignment_7/clear_eeprom.ino

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <EEPROM.h>
2+
3+
void setup()
4+
{
5+
6+
for (int i = 0; i < EEPROM.length(); i++)
7+
{
8+
EEPROM.write(i, 0);
9+
}
10+
}
11+
12+
void loop()
13+
{
14+
}

assignment_8/image/17_0077_0107.mp4

7.49 MB
Binary file not shown.
3.43 MB
Loading

sheet/ICT65-10.pdf

833 KB
Binary file not shown.

sheet/ICT65-11.pdf

733 KB
Binary file not shown.

0 commit comments

Comments
 (0)