-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdabmatbrainduino.ino
More file actions
189 lines (179 loc) · 4.6 KB
/
dabmatbrainduino.ino
File metadata and controls
189 lines (179 loc) · 4.6 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#define FASTLED_ESP8266_RAW_PIN_ORDER
#define FASTLED_INTERNAL
#define FASTLED_INTERRUPT_RETRY_COUNT 0
#define FASTLED_ALLOW_INTERRUPTS 0
#include "FastLED.h"
const int buttonPin = D5; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
int lowCount = 0;
#define DATA_PIN D8
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 41
CRGB leds[NUM_LEDS];
int BRIGHTNESS = 190;
int FRAMES_PER_SECOND = 60;
int fadeHue = 190;
int heatInt = 0;
int heatInt2 = heatInt + 1;
int heatInt3 = heatInt + 2;
int coolInt = 0;
int coolInt2 = coolInt + 1;
int coolInt3 = coolInt + 2;
//mode bools
bool slowFadeOn = true;
bool lightsOff = false;
bool heatOn = false;
bool coolOn = false;
unsigned long StartTime = millis();
unsigned long CurrentTime = millis();
unsigned long ElapsedTime = CurrentTime - StartTime;
int heatingTime = 45000;
int coolingTime = 20000;
void setup() {
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
Serial.begin(115200);
pinMode(buttonPin,INPUT_PULLUP); // initialize the pushbutton pin as an input
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
if (lightsOff == false){
if(slowFadeOn){
slowFade();
}
if(heatOn){
heating();
CurrentTime = millis();
ElapsedTime = CurrentTime - StartTime;
int heatRing = (float(ElapsedTime)/float(heatingTime)) * NUM_LEDS;
Serial.print("Ele: ");
Serial.println(ElapsedTime);
Serial.print("Heat: ");
Serial.println(heatingTime);
Serial.print("Div: ");
Serial.println((float(ElapsedTime)/float(heatingTime)));
for( int i = 0; i < heatRing; i++) {
leds[i].setRGB(255, 0, 0);
}
if(ElapsedTime > heatingTime){
for( int i = 0; i < NUM_LEDS; i++) {
leds[i].setRGB(0, 0, 0);
}
FastLED.show();
heatOn = false;
StartTime = millis();
coolOn = true;
coolInt = 0;
coolInt2 = coolInt+1;
coolInt3 = coolInt+2;
}
}
if(coolOn){
cooling();
CurrentTime = millis();
ElapsedTime = CurrentTime - StartTime;
int coolRing = float(ElapsedTime)/float(coolingTime) * NUM_LEDS;
for( int i = 0; i < coolRing; i++) {
leds[i].setRGB(0, 255, 255);
}
if(ElapsedTime > coolingTime){
// time to dab
heatOn = false;
coolOn = false;
for( int k = 0; k < 6; k++) {
fadeHue = fadeHue + 40;
for( int i = 0; i < NUM_LEDS; i++) {
leds[i].setHue(fadeHue);
}
FastLED.show();
delay(300);
for( int i = 0; i < NUM_LEDS; i++) {
leds[i].setRGB(0, 0, 0);
}
FastLED.show();
delay(300);
}
slowFadeOn = true;
}
}
FastLED.show();
}else{
fadeToBlackBy( leds, NUM_LEDS, 30);
FastLED.show();
}
if (buttonState == LOW) {
lowCount++;
}
else {
if(lowCount > 0 && lowCount <= 9 && !lightsOff){
for( int i = 0; i < NUM_LEDS; i++) {
leds[i].setRGB(0, 0, 0);
}
FastLED.show();
slowFadeOn = false;
heatOn = true;
heatInt = 0;
heatInt2 = heatInt + 1;
heatInt3 = heatInt + 2;
coolOn = false;
StartTime = millis();
}
if(lowCount > 9){
lightsOff = !lightsOff;
if(!lightsOff){
slowFadeOn = true;
heatOn = false;
coolOn = false;
}
}
lowCount = 0;
}
delay(50);
}
void heating(){
leds[heatInt].setRGB(0, 0, 0);
leds[heatInt2].setRGB(140, 0, 0);
leds[heatInt3].setRGB(255, 0, 0);
FastLED.show();
heatInt++;
heatInt2++;
heatInt3++;
if(heatInt > 40){
heatInt = 0;
}
if(heatInt2 > 40){
heatInt2 = 0;
}
if(heatInt3 > 40){
heatInt3 = 0;
}
}
void cooling(){
leds[coolInt].setRGB(0, 0, 0);
leds[coolInt2].setRGB(0, 150, 150);
leds[coolInt3].setRGB(0, 255, 255);
FastLED.show();
coolInt++;
coolInt2++;
coolInt3++;
if(coolInt > 40){
coolInt = 0;
}
if(coolInt2 > 40){
coolInt2 = 0;
}
if(coolInt3 > 40){
coolInt3 = 0;
}
}
void slowFade() {
fadeHue++;
for( int i = 0; i < NUM_LEDS; i++) {
leds[i].setHue(fadeHue);
}
if(fadeHue > 255){
fadeHue = 0;
}
}