-
Notifications
You must be signed in to change notification settings - Fork 0
/
giant_led_w_time.ino
100 lines (83 loc) · 2.11 KB
/
giant_led_w_time.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
#include "LEDTime.h"
#include <FastLED.h>
#define LED_PIN D3
#define NUM_LEDS 4
#define BRIGHTNESS 255
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define UPDATES_PER_SECOND 20
CRGBPalette16 currentPalette;
TBlendType currentBlending;
CRGB leds[NUM_LEDS];
#include <Button.h>
#include <PushButton.h>
PushButton button = PushButton(D5);
int currentMode = 0;
int totalModes = 2;
bool wasHeld = false;
void setup() {
delay(1000);
Serial.begin(115200);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
connectWiFi();
timeClient.begin();
button.onRelease(onButtonReleased);
button.onHoldRepeat(1000, 80, onButtonHeld);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.setTextSize(4);
display.setTextColor(WHITE);
display.dim(false);
display.clearDisplay();
Serial.println("OK let's go");
delay(1000);
}
void loop() {
displayDate();
button.update();
switch (currentMode) {
case -1:
/* Do nothing */
break;
case 0:
static uint8_t startIndex = 0;
startIndex += 1;
FillLEDsFromPaletteColors(startIndex);
FastLED.setBrightness(BRIGHTNESS);
FastLED.delay(1000 / UPDATES_PER_SECOND);
FastLED.show();
break;
case 1:
/* Turn off LEDs */
FillLEDsWithColor(CRGB::Black);
FastLED.show();
break;
}
}
void onButtonReleased(Button& btn, uint16_t duration) {
if (!wasHeld) {
currentMode++;
currentMode %= totalModes;
Serial.println("button pressed");
}
wasHeld = false;
}
void onButtonHeld(Button& btn, uint16_t duration, uint16_t repeatCount) {
wasHeld = true;
currentMode = -1;
static uint8_t colorIndex = 0;
FillLEDsFromPaletteColors(colorIndex);
colorIndex += 10;
FastLED.show();
}
void FillLEDsWithColor(CRGB color) {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = color;
}
}
void FillLEDsFromPaletteColors(uint8_t colorIndex) {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette(currentPalette, colorIndex, BRIGHTNESS, currentBlending);
}
}