Created
April 7, 2017 03:53
-
-
Save edfungus/47041819855fe7f0c32c479a75c0d8ab to your computer and use it in GitHub Desktop.
Control led strip via serial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "FastLED.h" | |
#include "EEPROM.h" | |
// How many leds in your strip? | |
#define NUM_LEDS 37 | |
#define DATA_PIN 7 | |
#define addrHue 0 | |
#define addrOnoff 2 | |
// Define the array of leds | |
CRGB leds[NUM_LEDS]; | |
uint8_t hue = 0; | |
uint8_t onoff = 255; | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("starting..."); | |
delay(1000); | |
LEDS.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS); | |
LEDS.setBrightness(84); | |
hue = EEPROM.read(addrHue); | |
onoff = EEPROM.read(addrOnoff); | |
setHue(); | |
} | |
void fadeall() { | |
for(int i = 0; i < NUM_LEDS; i++) { | |
leds[i].nscale8(250); | |
} | |
} | |
void setHue() { | |
EEPROM.write(addrHue, hue); | |
EEPROM.write(addrOnoff, onoff); | |
for(int i = 0; i < NUM_LEDS; i++) { | |
leds[i] = CHSV(hue, 255, onoff); | |
} | |
FastLED.show(); | |
fadeall(); | |
Serial.println(hue, DEC); | |
} | |
void loop() { | |
if (Serial.available() > 0) { | |
byte raw = Serial.read() * 2; | |
if (raw == 122) { // = | |
hue++; | |
setHue(); | |
} | |
if (raw == 90) { // - | |
hue--; | |
setHue(); | |
} | |
if (raw == 186) { // ] | |
onoff = 255; | |
setHue(); | |
} | |
if (raw == 182) { // [ | |
onoff = 0; | |
setHue(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment