11#define NUM_STRIPS 8
2- #define NUM_LEDS_PER_STRIP 75
3- #define MOVE_PIXEL_EVERY_X_MS 5
2+ #define NUM_LEDS_PER_STRIP 210
43
54#define USE_OCTOWS2811
65#include < OctoWS2811.h>
109#include < SPI.h>
1110#include < SD.h>
1211#include < SerialFlash.h>
12+ #include < Bounce.h>
1313#include " Globals.h"
1414#include " SoundFilters.h"
1515#include " Animations.h"
@@ -29,6 +29,13 @@ float bands[6];
2929
3030CRGB leds[NUM_STRIPS * NUM_LEDS_PER_STRIP ];
3131
32+ Bounce controlButton = Bounce(CONTROL_PIN , 10 ); // 10 ms debounce
33+
34+ void printArrayToSerial (float soundArray[], int arrayLength);
35+ void printLedsToSerial (CRGB leds[]);
36+ void setBrightnessFromPot ();
37+ void setSpeedFromKY040 ();
38+ void setupKY040 ();
3239
3340void setup () {
3441 LEDS .addLeds <OCTOWS2811 >(leds, NUM_LEDS_PER_STRIP );
@@ -50,14 +57,13 @@ void setup() {
5057 memset (deltas, 0 , sizeof (deltas));
5158
5259 FastLED.setBrightness (200 );
53- }
5460
55- void printArrayToSerial (float soundArray[], int arrayLength);
56- void printLedsToSerial (CRGB leds[]);
57- void setBrightnessFromPot ();
61+ setupKY040 ();
62+ }
5863
5964void loop () {
6065 setBrightnessFromPot ();
66+ setSpeedFromKY040 ();
6167
6268 int i;
6369
@@ -67,7 +73,6 @@ void loop() {
6773 }
6874 processSound (soundArray, deltas);
6975 createBands (deltas, bands);
70- bandsAnimation (bands, leds);
7176
7277// printArrayToSerial(soundArray, NUM_BINS);
7378// printArrayToSerial(deltas, NUM_BINS);
@@ -80,14 +85,61 @@ void loop() {
8085// Serial.println(FastLED.getFPS());
8186 }
8287
88+ bandsAnimation (bands, leds);
8389 FastLED.show ();
8490}
8591
92+ void setupKY040 () {
93+ pinMode (KY040_CLK , INPUT );
94+ pinMode (KY040_DT , INPUT );
95+
96+ pinMode (CONTROL_PIN , INPUT_PULLUP );
97+ }
98+
99+ void setSpeedFromKY040 () {
100+ static uint8_t pinCLKlast = digitalRead (KY040_CLK );
101+ uint8_t currentVal;
102+ EVERY_N_MILLIS (5 ) {
103+ currentVal = digitalRead (KY040_CLK );
104+
105+ if (currentVal != pinCLKlast) {
106+ if (digitalRead (KY040_DT ) == currentVal) {
107+ animationSpeed += 1 ;
108+ } else {
109+ animationSpeed -= 1 ;
110+ }
111+ }
112+
113+ if (animationSpeed > MAX_SPEED_OFFSET ) {
114+ animationSpeed = MAX_SPEED_OFFSET ;
115+ } else if (animationSpeed < MIN_SPEED_OFFSET ) {
116+ animationSpeed = MIN_SPEED_OFFSET ;
117+ }
118+ pinCLKlast = currentVal;
119+ Serial.println (animationSpeed);
120+ }
121+ }
122+
86123void setBrightnessFromPot () {
87124 static float potValue = 0 ;
88- potValue = 0.99 * potValue + 0.01 * analogRead (A8 );
125+ static bool controlConnected = false ;
126+
127+ potValue = 0.99 * potValue + 0.01 * analogRead (BRIGHTNESS_PIN );
89128 int brightnessVal = potValue*255 /1023 ;
90- // Serial.println(brightnessVal);
129+ if (brightnessVal <= 5 ) {
130+ brightnessVal = 0 ;
131+ }
132+
133+ if (controlButton.update ()) {
134+ if (controlButton.fallingEdge ()) {
135+ controlConnected = !controlConnected;
136+ }
137+ }
138+
139+ if (!controlConnected) {
140+ brightnessVal = 255 ;
141+ }
142+
91143 FastLED.setBrightness (brightnessVal);
92144}
93145
0 commit comments