Created
January 12, 2019 00:59
-
-
Save Mateo-S/a480341bb0863f403cf322b1ee324ac7 to your computer and use it in GitHub Desktop.
Put an rgb value in the serial monitor, get that color on the LED strip
This file contains 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
/* | |
ledColorTest.ino - Code to run on Chairmans Visual for the 2019 season | |
author - Mateo Silver | |
REFERENCE COLORS: | |
Red - (255,0, 0) | |
Blue - (0,0, 255) | |
Green - (0,255, 0) | |
White - (255,255, 255) | |
Purple - (128,0, 128) | |
Orange - (255,127, 0) | |
*/ | |
#include <FastLED.h> | |
#define NUM_LEDS 150 | |
#define DATA_PIN 6 | |
String input = ""; | |
int r = 255; | |
int g = 255; | |
int b = 255; | |
CRGB leds[NUM_LEDS]; | |
String midString(String str, String start, String finish){ | |
int locStart = str.indexOf(start); | |
if (locStart==-1) return ""; | |
locStart += start.length(); | |
int locFinish = str.indexOf(finish, locStart); | |
if (locFinish==-1) return ""; | |
return str.substring(locStart, locFinish); | |
} | |
void setup() { | |
Serial.begin(9600); | |
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); | |
Serial.println("Make sure you put a space after ONLY the second comma\nE.g. '(255,122, 94)'"); | |
} | |
void loop() { | |
if (Serial.available() > 0) | |
{ | |
input = Serial.readString(); | |
Serial.print(input); | |
r = midString(input, "(" , ",").toInt(); | |
g = midString(input, "," , ",").toInt(); | |
b = midString(input, ", " , ")").toInt(); | |
Serial.println(r); | |
Serial.println(g); | |
Serial.println(b); | |
for(int i = 0; i < NUM_LEDS; i++){ | |
leds[i] = CRGB(r,g,b); | |
} | |
FastLED.show(); | |
delay(30); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment