-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoom_Program_Lights_V2.ino
More file actions
150 lines (116 loc) · 3.52 KB
/
Room_Program_Lights_V2.ino
File metadata and controls
150 lines (116 loc) · 3.52 KB
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
/*
Logic:
When I Click the Red button it open the serialized lights until it close
When I Click the Blue buttonn it open the night time activity
*/
const int BUTTON_2 = 4; // Button pin for opening and closing the serialized lights
const int BUTTON_1 = 5; // Button pin for opening and closing the night time activity lights
const int NIGHT_ACTIVITY_TRANSISTOR = 6; // Transistor to handle 5 volts to night time activity lights
const int LEDS[] = { A5 , A4 , A3 , A2 }; // ( Red , Blue , Yellow, White )
int clickDelay = 30; // microsecond delay from button
// Button for Night Time Activity
int clickCounter1 = 0; // microsecond counter from button
bool isActionIsButton1 = false; // if the action is in the button
bool isNightLightOpen = false; // If the night time activity light is open
// Button for serialized lights
int clickCounter2 = 0; // microsecond counter from button
bool isActionIsButton2 = false; // if the action is in the button
/*
The leds must have different colors ( Red , Blue , Yellow, White )
Sleeping Color:
Deep Red = 225 , 25 , 0 , 0
Warm White = 0 , 100 , 50 , 225
Peach = 100 , 0 , 225, 0
Burnt Orange = 225, 150 , 225, 0
*/
int row = 4;
int cols = 4;
int pos = -1 ;
int SLEEPING_COLOR[4][4] = {
{225 , 180 , 0 , 0},
{0 , 190, 150, 225},
{180 , 0 , 225 , 0},
{225, 150 , 225, 0}
};
bool isClicked(int pin){
if (digitalRead(pin) == HIGH){
return true;
}
return false;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
int range = random(0, 1000);
for (int i = 0; i < range; i++) {
randomSeed(analogRead(A0));
}
for ( int pin : ::LEDS ){
pinMode(pin , OUTPUT);
}
pinMode(::BUTTON_1 , INPUT);
pinMode(::BUTTON_2 , INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
// Night Time Activity Logic
bool clicked1 = false;
if (!::isActionIsButton1){
clicked1 = ::isClicked(::BUTTON_1);
if (clicked1){
::isActionIsButton1 = true;
}
} else {
delayMicroseconds(1);
::clickCounter1 = ::clickCounter1 + 1;
if (::clickCounter1 == ::clickDelay){
::isActionIsButton1 = false;
::clickCounter1 = 0;
}
Serial.println("Night Time Button Counter : " + (String)::clickCounter1);
}
if ( clicked1 ){
// Check if the night time button is clicked
if (::isNightLightOpen){
// If open then close it
::isNightLightOpen = false;
digitalWrite(::NIGHT_ACTIVITY_TRANSISTOR , LOW);
} else {
// If close then open it
::isNightLightOpen = true;
digitalWrite(::NIGHT_ACTIVITY_TRANSISTOR, HIGH);
}
}
// Serialized Activity Logic
bool clicked2 = false;
if (!::isActionIsButton2){
clicked2 = ::isClicked(::BUTTON_2);
if (clicked2){
::isActionIsButton2 = true;
}
} else {
delayMicroseconds(1);
::clickCounter2 = ::clickCounter2 + 1;
if (::clickCounter2 == ::clickDelay){
::isActionIsButton2 = false;
::clickCounter2 = 0;
}
Serial.println("Serialized Button Counter : " + (String)::clickCounter2);
}
if (clicked2){
// Check if the serialized button is clicked
::pos = ::pos + 1;
// Check if the pos is greater than rows, if true then close the lights and change the pos to -1
if (::pos >= ::row){
for (int i = 0 ; i < ::cols ; i++){
analogWrite(::LEDS[i], 0);
}
::pos = -1;
} else {
for (int i = 0 ; i < ::cols ; i++){
analogWrite(::LEDS[i], ::SLEEPING_COLOR[pos][i]);
}
}
}
}