Skip to content
Permalink
Browse files

Add files via upload

  • Loading branch information...
stevenb9 committed May 16, 2019
1 parent fe881c5 commit e0a82342c47d684316becf20dc0b6c4e3b5f85ac
Showing with 131 additions and 0 deletions.
  1. +131 −0 Jukebox.ino
@@ -0,0 +1,131 @@
#include <FastLED.h>

#define LED_PIN 7
#define BTN_PIN 4
#define NUM_LEDS 144
#define BRIGHTNESS 255
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define UPDATES_PER_SECOND 200

CRGB leds[NUM_LEDS];

int counter = 0;
int buttonState = 0;

CRGBPalette16 currentPalette;
TBlendType currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;

void setup() {
delay( 1500 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
pinMode(BTN_PIN, INPUT_PULLUP);
Serial.begin(9600);

currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
}

void loop()
{
ChangePalettePeriodically();

static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */

FillLEDsFromPaletteColors( startIndex);

FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);
}

void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 255;

for( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
colorIndex += 3;
}
}

void ChangePalettePeriodically()
{
Serial.println(digitalRead(BTN_PIN));

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if(digitalRead(BTN_PIN) == LOW) {
counter = counter + 1;
delay(130);
}

if(counter == 4) {
counter = 0;
}

if( counter == 0) { currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; }
if( counter == 1) { currentPalette = RainbowStripeColors_p; currentBlending = LINEARBLEND; }
if( counter == 2) { currentPalette = CloudColors_p; currentBlending = LINEARBLEND; }
if( counter == 3) { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND; }
if( counter == 4) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
}

// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette()
{
for( int i = 0; i < 16; i++) {
currentPalette[i] = CHSV( random8(), 255, random8());
}
}

void SetupBlackAndWhiteStripedPalette()
{
// 'black out' all 16 palette entries...
fill_solid( currentPalette, 16, CRGB::Black);
// and set every fourth one to white.
currentPalette[0] = CRGB::White;
currentPalette[4] = CRGB::White;
currentPalette[8] = CRGB::White;
currentPalette[12] = CRGB::White;

}

// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
{
CRGB purple = CHSV( HUE_PURPLE, 255, 255);
CRGB green = CHSV( HUE_GREEN, 255, 255);
CRGB black = CRGB::Black;

currentPalette = CRGBPalette16(
green, green, black, black,
purple, purple, black, black,
green, green, black, black,
purple, purple, black, black );
}

const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
CRGB::Red,
CRGB::Gray, // 'white' is too bright compared to red and blue
CRGB::Blue,
CRGB::Black,

CRGB::Red,
CRGB::Gray,
CRGB::Blue,
CRGB::Black,

CRGB::Red,
CRGB::Red,
CRGB::Gray,
CRGB::Gray,
CRGB::Blue,
CRGB::Blue,
CRGB::Black,
CRGB::Black
};

0 comments on commit e0a8234

Please sign in to comment.
You can’t perform that action at this time.