Created
November 25, 2016 12:42
-
-
Save unknowndomain/309c5cd37f10e67bfdd5f95fbf0eca8f to your computer and use it in GitHub Desktop.
Takes CSV RGB values and outputs to NeoPixels.
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 <Adafruit_NeoPixel.h> | |
| #define PIN 6 | |
| Adafruit_NeoPixel strip = Adafruit_NeoPixel( 30, PIN, NEO_GRB + NEO_KHZ800 ); | |
| void setup() { | |
| Serial.begin( 9600 ); | |
| strip.begin(); | |
| strip.show(); | |
| } | |
| void loop() { | |
| if ( Serial.available() >= 6 ) { | |
| String data = Serial.readStringUntil( '\n' ); | |
| int rPos = data.indexOf( "," ); | |
| int gPos = data.indexOf( ",", rPos + 1 ); | |
| // Skip if invalid data | |
| if ( rPos == -1 || gPos == -1 ) return; | |
| int r = data.substring( 0, rPos ).toInt(); | |
| int g = data.substring( rPos + 1, gPos ).toInt(); | |
| int b = data.substring( gPos + 1 ).toInt(); | |
| for ( uint16_t i = 0; i < strip.numPixels(); i++ ) { | |
| strip.setPixelColor( i, r, g, b ); | |
| } | |
| strip.show(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment