Skip to content

Instantly share code, notes, and snippets.

@gelicia
Created March 24, 2019 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gelicia/e2a6d48ab87df29f492c29caa72699f1 to your computer and use it in GitHub Desktop.
Save gelicia/e2a6d48ab87df29f492c29caa72699f1 to your computer and use it in GitHub Desktop.
claptrap eye
#include <FastLED.h>
#define LED_PIN 9
#define SENSOR_PIN 10
#define NUM_LEDS 3
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
#define UPDATES_PER_SECOND 100
// Gradient palette "cw6_042_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/cw/6/tn/cw6-042.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 8 bytes of program space.
DEFINE_GRADIENT_PALETTE( blue_p ) {
0, 3, 37, 51,
255, 7, 65, 60};
// Gradient palette "cw6_006_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/cw/6/tn/cw6-006.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 8 bytes of program space.
DEFINE_GRADIENT_PALETTE( red_p ) {
0, 146, 37, 1,
255, 35, 1, 1};
int mode = 0;
int storeSensorVal = LOW;
CRGBPalette16 currentPalette;
extern CRGBPalette16 madPalette;
extern const TProgmemPalette16 madPalette_p PROGMEM;
extern CRGBPalette16 finePalette;
extern const TProgmemPalette16 finePalette_p PROGMEM;
CRGBPalette16 redPalette = red_p;
CRGBPalette16 bluePalette = blue_p;
int numModes = 3;
CRGBPalette16 modes[3] = { RainbowColors_p, blue_p, red_p};
void setup() {
Serial.begin(9600);
pinMode(SENSOR_PIN, INPUT);
delay( 3000 ); // power-up safety delay
FastLED.setMaxPowerInVoltsAndMilliamps(3.7, 200);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
void loop()
{
int sensorVal = digitalRead(SENSOR_PIN);
if (sensorVal == HIGH && storeSensorVal == LOW){
mode++;
if (mode == numModes) {
mode = 0;
}
}
storeSensorVal = sensorVal;
currentPalette = modes[mode];
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++) {
uint8_t idx = map(i, 0, NUM_LEDS, 0, 255) + colorIndex;
leds[i] = ColorFromPalette( currentPalette, idx, brightness, LINEARBLEND);
colorIndex += 3;
}
}
const TProgmemPalette16 madPalette_p PROGMEM = {
CRGB::Red,
CRGB::Red,
CRGB::Red
};
const TProgmemPalette16 finePalette_p PROGMEM = {
CRGB::Teal,
CRGB::Blue,
CRGB::Teal
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment