Skip to content

Commit

Permalink
Improved led strip controller
Browse files Browse the repository at this point in the history
- Faster communication between server and controller
- More robust protocol with start/end characters
- Update rate from client to led strip ~10x faster
- Ack sent from controller to server, server retries if nothing received
- Server automatically flashes led strip controller on launch
- New Christmas and Confetti light modes
- Removed slow rainbow
- Added slider to adjust speed (led refresh rate)
- Minor code-style improvements
- Read serial data using serialEvent(), store in buffer
  • Loading branch information
rdudhagra committed Dec 24, 2021
1 parent d8fde83 commit 84bb184
Show file tree
Hide file tree
Showing 13 changed files with 374 additions and 163 deletions.
41 changes: 41 additions & 0 deletions Light Strip Controller/main/christmas.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef LIGHT_STRIP_CONTROLLER_CHRISTMAS_H

#define LIGHT_STRIP_CONTROLLER_CHRISTMAS_H

#include "constants.h"
#include <FastLED.h>

void christmas(CRGB *leds, uint8_t *dat)
{
if (*dat == 0)
{
// White, Green, White, Red
fill_gradient_RGB(leds, 0, CRGB::CadetBlue, NUM_LEDS / 4 - 1, CRGB::Green);
fill_gradient_RGB(leds, NUM_LEDS / 4, CRGB::Green, NUM_LEDS / 2 - 1, CRGB::CadetBlue);
fill_gradient_RGB(leds, NUM_LEDS / 2, CRGB::CadetBlue, NUM_LEDS / 4 * 3 - 1, CRGB::Red);
fill_gradient_RGB(leds, NUM_LEDS / 4 * 3, CRGB::Red, NUM_LEDS - 1, CRGB::CadetBlue);
*dat = 1;
}
else
{
// save the first element
CRGB first = leds[0];
// shift every element down one
for (int i = 1; i < NUM_LEDS; i++)
{
leds[i - 1] = leds[i];
}
// put the first element in the last slot
leds[NUM_LEDS - 1] = first;
}
}

uint8_t *init_christmas_dat()
{
uint8_t *dat = (uint8_t *)malloc(sizeof(uint8_t));
*dat = 0;

return dat;
}

#endif
1 change: 0 additions & 1 deletion Light Strip Controller/main/colorpulse.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#define PI 128 // This is with relation to 2pi=256, used by 8-bit FastLED trig funcs

const uint8_t N_OVER_2 = NUM_LEDS / 2;
const uint16_t PULSE_MAX_RNG_VAL = (uint16_t)(16384.0 * PULSE_FREQUENCY / FRAMES_PER_SECOND);
const uint8_t A = 255 / NUM_LEDS;

const CRGB BLACK = CRGB(0, 0, 0);
Expand Down
28 changes: 28 additions & 0 deletions Light Strip Controller/main/confetti.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef LIGHT_STRIP_CONTROLLER_CONFETTI_H

#define LIGHT_STRIP_CONTROLLER_CONFETTI_H

#include "constants.h"
#include <FastLED.h>

// Adapted from https://github.com/atuline/FastLED-Demos/blob/master/confetti/confetti.ino

void confetti(CRGB *leds, uint8_t *dat)
{
(void)dat;

fadeToBlackBy(leds, NUM_LEDS, CONFETTI_DECAY_RATE);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV((*dat + random16(256))/4 , CONFETTI_SATURATION, 255); // 12 bits for hue so that the hue increment isn't too quick.
*dat++;
}

uint8_t *init_confetti_dat()
{
uint8_t *dat = (uint8_t *)malloc(sizeof(uint8_t));
*dat = 0;

return dat;
}

#endif
28 changes: 18 additions & 10 deletions Light Strip Controller/main/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,50 @@
#define LIGHT_STRIP_CONTROLLER_CONSTANTS_H

// General Constants
#define DEBUG true
#define SERIAL_BAUD_RATE 2400
#define DEBUG false
#define SERIAL_BAUD_RATE 115200
#define BUF_SIZE 32

// Communication Protocol Constants
#define START_CHAR '['
#define END_CHAR ']'
#define BRIGHTNESS_CMD '!'
#define FPS_CMD '@'
#define RGB_CMD '#'

// LED Strip Constants
#define DATA_PIN 3
#define LED_TYPE WS2813
#define NUM_LEDS 240
#define BRIGHTNESS 255
#define MAX_MILLIAMPS 12000
#define FRAMES_PER_SECOND 25

// Color Modes
#define OFF 0
#define RAINBOW 1
#define SLOW_RAINBOW 2
#define CHRISTMAS 2
#define COLOR_PULSE 3
#define AMBIANCE 4
#define CONFETTI 5

#define SOLID_COLOR 255 // Not to be used by client...only internally

// Slow Rainbow Mode Constants
#define SLOW_RAINBOW_MULTIPLIER 10 // This number is how many times slower \
// the slow rainbow effect is compared \
// to the normal rainbow effect

// Color Pulse Mode Constants
#define PULSE_FREQUENCY 3 // Frequency for a new pulse in Hz \
// Will be on average this value... \
// actual pulses will be created using rng
#define PULSE_MIN_SATURATION 225 // Out of 255
#define PULSE_INTENSITY 50 // bigger the number, longer the leds stay bright, 0 is no change
#define PULSE_BACKGROUND_BRIGHTNESS 128 // 0..255
#define PULSE_BACKGROUND_BRIGHTNESS 80 // 0..255

// Ambiance Mode Constants
#define AMBIANCE_SATURATION 100
#define AMBIANCE_CHANGE_RATE 0.03 // Defines the bounds for the random walk
#define AMBIANCE_MAX_CHANGE_RATE 0.3

// Confetti Mode Constants
#define CONFETTI_DECAY_RATE 2 // Low values = slower fade
#define CONFETTI_SATURATION 150


#endif
Loading

0 comments on commit 84bb184

Please sign in to comment.