-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparatissima_stelle.ino
168 lines (129 loc) · 4.35 KB
/
paratissima_stelle.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
161
162
163
164
165
166
167
168
/*
Lights display for paratissima
@author Enkel Bici
Based on inoise8_pal_demo code from Andrew Tuline
*/
#include "FastLED.h"
/*
There are 21 stars with 8 leds each totalling 168
*/
#define STARS 19
#define STAR_LEDS 8
#define NUM_LEDS STARS*STAR_LEDS
//#define NUM_LEDS 168
// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
//#APA102
//#define DATA_PIN 6
//#define CLOCK_PIN 5
//for ws2812b
#define DATA_PIN 7
#define BRIGHTNESS 255
#define LED_TYPE WS2812B // Only use the LED_PIN for WS2812's
#define COLOR_ORDER GRB
// Define the array of leds
CRGB leds[NUM_LEDS];
static uint16_t dist; // A random number for our noise generator.
uint16_t scale = 30; // Wouldn't recommend changing this on the fly, or the animation will be really blocky.
uint8_t maxChanges = 48; // Value for blending between palettes.
/*
#f8ca00
#fd0
gold
hsl(48,100,48)
rgb(248,202,0)
*/
CRGB rgb(248,202,0); //gold rgb
static uint8_t baseHue = 48; //gold hue
// microphone on analog input 0
static uint8_t audioInputPin = 0;
CRGBPalette16 currentPalette(CRGB::Black);
//CRGBPalette16 targetPalette(OceanColors_p);
CRGBPalette16 targetPalette(rgb);
void setup() {
Serial.begin(115200);
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
//FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, BGR>(leds, NUM_LEDS);
LEDS.setBrightness(BRIGHTNESS);
//dist = random16(12345); // A semi-random number for our noise generator
}
void loop() {
//testYellow();
//read analog microphone
dist=analogRead(audioInputPin);
Serial.println(dist);
EVERY_N_MILLISECONDS(10) {
nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); // Blend towards the target palette
fillnoise8(); // Update the LED array with noise at the new location
}
EVERY_N_SECONDS(5) {
// Change the target palette to a random saturation every 5 seconds.
targetPalette = CRGBPalette16(
CHSV(baseHue, 255, random8(128,255)),
CHSV(baseHue, 255, random8(128,255)),
CHSV(baseHue, 255, random8(128,255)),
CHSV(baseHue, 255, random8(128,255)));
//targetPalette = CRGBPalette16(RainbowColors_p);
}
LEDS.show(); // Display the LED's at every loop cycle.
}
void fillnoise8() {
//int seed = analogRead(0);
//dist = random16(seed); // A semi-random number for our noise generator
for(int i = 0; i < NUM_LEDS; i++) { // Just ONE loop to fill up the LED array as all of the pixels change.
uint8_t index = inoise8(i*scale, dist+i*scale) % 255; // Get a value from the noise function. I'm using both x and y axis.
leds[i] = ColorFromPalette(currentPalette, index, 255, LINEARBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED.
}
dist += beatsin8(10,1, 4); // Moving along the distance (that random number we started out with). Vary it a bit with a sine wave.
// In some sketches, I've used millis() instead of an incremented counter. Works a treat.
} // fillnoise8()
void ledswitch(CRGB color){
// Turn the LED on, then pause
for(int i = 0; i < NUM_LEDS; i++){
leds[i] = color;
}
FastLED.show();
}
void testYellow(){
int on=1000;
int off=500;
/*
#f8ca00
#fd0
gold
hsl(48,100,48)
rgb(248,202,0)
*/
Serial.println("Gold");
// Turn the LED on, then pause
CRGB rgb(248,202,0);
ledswitch(rgb);
delay(on);
ledswitch(CRGB::Black);
delay(off);
}
void testrgb(){
int on=5000;
int off=1000;
Serial.println("Red");
ledswitch(CRGB::Red);
delay(on);
ledswitch(CRGB::Black);
delay(off);
Serial.println("Green");
ledswitch(CRGB::Green);
delay(on);
ledswitch(CRGB::Black);
delay(off);
Serial.println("Blue");
ledswitch(CRGB::Blue);
delay(on);
ledswitch(CRGB::Black);
delay(off);
Serial.println("White");
ledswitch(CRGB::White);
delay(on);
ledswitch(CRGB::Black);
delay(off);
}