Created
July 30, 2017 21:44
-
-
Save edfungus/9d920083005b7b142c41f34f3912b0c1 to your computer and use it in GitHub Desktop.
RBG LED strip with serial color and brightness control
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" | |
#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