-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlarm_Clock.ino
147 lines (121 loc) · 3.36 KB
/
Alarm_Clock.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const int redLED = 11;
const int blueLED = 10;
const int greenLED = 9;
const int nightLED = 6;
const int dayLED = 5;
const int btn1 = 8;
const int btn2 = 7;
const int speaker = 3;
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
int nightValue = 0;
int dayValue = 0;
//both buttons activate the menu when either or are pressed
int btn1State = 0; // this button sets the mode 1 - SNOOZE | 2 - STOP || hold to select(btn 2 value) ---> [if selected light up 3rd LED Green to set Time; Blue to set Alarm and sound alarm] use this button to confirm settime |OR| setalarm
int btn2State = 0; // this button sets the time 1 - Set Alarm || hold to select(btn 1 value) ---> [if selected light up LED corresponding to DayMode light LEDS fully |OR| NightMODE fade then out] then using this button set the time for every 10 intervals light light and move on to a new one. then select minutes every 10 min intervals
//PRESS BOTH BUTTONS ON THIRD FUNCTION TO SNOOZE -|OR|- TO STOP
int ledState = LOW;
bool menu = false;
bool disabled = false;
bool playSound = false;
unsigned long previousTime = 0;
long interval = 1000;
int seconds = 0;
int minutes = 0;
int hours = 0;
void setup() {
Serial.begin(9600);
pinMode(redLED, OUTPUT);
pinMode(blueLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(nightLED, OUTPUT);
pinMode(dayLED, OUTPUT);
pinMode(btn1, INPUT);
pinMode(btn2, INPUT);
}
void loop() {
unsigned long currentTime = millis();
unsigned long xTime = millis()/5000;
if(currentTime - previousTime > interval){
previousTime = currentTime;
if(ledState == LOW){
//Serial.println("High");
ledState = HIGH;
} else {
//Serial.println("Low");
ledState = LOW;
}
//digitalWrite(nightLED, ledState);
seconds++;
Time(seconds);
if(menu && !disabled){
digitalWrite(nightLED, ledState);
digitalWrite(dayLED, ledState);
mainMenu();
} else {
if(btn1State == HIGH || btn2State == HIGH){
menu = true;
}
}
}
}
void Time (int seconds){
if(seconds >= 60){
minutes++;
seconds = 0;
Serial.print(minutes);
Serial.println(" : Minutes");
}
if(minutes >= 60){
hours++;
minutes = 0;
Serial.print(hours);
Serial.println(" : hours");
}
if(hours >= 24){
hours = 0;
}
}
void Alarm (){
//wakes up at 10:01 am;
if(hours == 10 && minutes == 1){
long internalClock = (0.5 * sin((xTime - 1.5))) + 0.5
redValue = fade(100.0);
greenValue = fade(120.0);
blueValue = fade(128.0);
if(playSound){
tone(speaker, 294, 500);
}
}
}
void setTime() {
minutes = 10;
hours = 0;
seconds = 0;
}
int mainMenu(){
if(btn1State == HIGH){
Serial.println("Press other button to SNOOZE");
if(btn2State == HIGH){
//turn off alarm and wake up again int 10 minutes
disabled = true;
menu = false;
return 0;
}
}
if(btn2State == HIGH){
Serial.println("Press other button to STOP");
if(btn1State == HIGH){
//turn off alarm
disabled = true;
menu = false;
return 0;
}
}
}
int fade(float range){
float xTime = millis()/5000.0;
int value = range + (int)range * sin(xTime*2.0*PI);
return value;
}