-
Notifications
You must be signed in to change notification settings - Fork 0
/
Top_Hat.ino
160 lines (120 loc) · 3.43 KB
/
Top_Hat.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
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <FastLED.h>
#define LED_PIN1 6
#define LED_PIN2 1
#define NUM_LEDS1 70
#define NUM_LEDS2 68
#define NUM_LEDS (NUM_LEDS1+NUM_LEDS2)
#define MAX_SINGLE_STRIP_LENGTH 13
#define DEFAULT_BRIGHTNESS 64
struct CRGB leds[NUM_LEDS];
#define DEBUG
//#define DEBUG_ANIMATIONS
#include "DebugUtils.h"
CRGBPalette16 gPalettes[] = {HeatColors_p, LavaColors_p, RainbowColors_p,
CloudColors_p, OceanColors_p, ForestColors_p, PartyColors_p};
uint8_t gCurrentPaletteIndex = 0;
typedef struct {
uint8_t mStart;
uint8_t mLength;
bool isDown;
} Strip;
Strip strips[] = {
{0, 13, true},
{13, 12, false},
{25, 11, true},
{36, 11, false},
{47, 11, true},
{58, 12, false},
{70, 13, true},
{83, 10, false},
{93, 11, true},
{104, 11, false},
{115, 11, true},
{126, 12, false}
};
uint8_t ledPosDown(uint8_t stripIndex, uint8_t pixelIndex)
{
if (strips[stripIndex].isDown) {
return strips[stripIndex].mStart + pixelIndex;
} else {
return strips[stripIndex].mStart + strips[stripIndex].mLength - 1 - pixelIndex;
}
}
uint8_t ledPosUp(uint8_t stripIndex, uint8_t pixelIndex)
{
if (strips[stripIndex].isDown) {
return strips[stripIndex].mStart + strips[stripIndex].mLength - 1 - pixelIndex;
} else {
return strips[stripIndex].mStart + pixelIndex;
}
}
static const int numberOfStrips = sizeof(strips) / sizeof(strips[0]);
#define MIC_PIN A10
#include "SoundReactive.h"
uint8_t gHue = 0;
typedef uint8_t (*Animation)(uint8_t arg1, uint8_t arg2);
typedef struct {
Animation mPattern;
uint8_t mArg1;
uint8_t mArg2;
} AnimationPattern;
#include "Animations.h"
/**
* Button Switcher
*/
#include "Button.h"
#define BUTTON_PIN 12
Button button(BUTTON_PIN, true);
#include "SettingsMode.h"
AnimationPattern gAnimations[] = {
// {movingCircle, 0, 0},
{animationSwitcher, 0, 0},
{drops, 1, 4},
{drops, 0, 4},
{spiral, 0, 1},
{sinelon, 5, 4},
{soundAnimate, 0, 0},
{soundAnimate, 1, 0},
};
uint8_t gCurrentPatternNumber = 0;
void setup() {
DEBUG_START(57600);
FastLED.addLeds<NEOPIXEL, LED_PIN1>(leds, 0, NUM_LEDS1).setCorrection(TypicalLEDStrip);
FastLED.addLeds<NEOPIXEL, LED_PIN2>(leds, NUM_LEDS1, NUM_LEDS2).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(DEFAULT_BRIGHTNESS);
set_max_power_in_volts_and_milliamps(5, 500);
fill_solid(leds, NUM_LEDS, CRGB::Black);
show_at_max_brightness_for_power();
delay(100);
// Button
button.attachClick(onClick);
button.attachTripleClick(onTripleClick);
}
static const int numberOfPatterns = sizeof(gAnimations) / sizeof(gAnimations[0]);
void onClick() {
PRINT("Next animation");
gCurrentPatternNumber = (gCurrentPatternNumber+1) % numberOfPatterns;
}
void onTripleClick() {
PRINT("Opening settings");
SettingsMode settings = SettingsMode(&button);
settings.showSettings();
uint8_t brightness = settings.getUserBrightness();
PRINTX("TripleClick - New brightness: ", brightness);
FastLED.setBrightness(brightness);
}
void loop() {
random16_add_entropy(random());
button.tick();
uint8_t arg1 = gAnimations[gCurrentPatternNumber].mArg1;
uint8_t arg2 = gAnimations[gCurrentPatternNumber].mArg2;
Animation animate = gAnimations[gCurrentPatternNumber].mPattern;
animate(arg1, arg2);
// soundAnimate(0, 0);
// sinelon(5, 4);
show_at_max_brightness_for_power();
gHue++;
#ifdef DEBUG_ANIMATIONS
EVERY_N_MILLISECONDS(500) {Serial.print("FPS: ");Serial.println(FastLED.getFPS());}
#endif
}