-
-
Save yyolk/5808818 to your computer and use it in GitHub Desktop.
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
// Receive multiple numeric fields using Arduino 1.0 Stream parsing | |
#include "SPI.h" | |
#include "Adafruit_WS2801.h" | |
Adafruit_WS2801 strip = Adafruit_WS2801(64); | |
const int NUMBER_OF_FIELDS = 192; // how many comma-separated fields we expect | |
int fieldIndex = 0; // the current field being received | |
int values[NUMBER_OF_FIELDS]; // array holding values for all the fields | |
void setup() { | |
Serial.begin(115200); // Initialize serial port to send and receive at 9600 baud | |
Serial.flush(); | |
strip.begin(); | |
strip.show(); | |
} | |
void loop() { | |
if( Serial.available() > 0) { | |
while(Serial.available() > 0) { | |
for(fieldIndex = 0; fieldIndex < NUMBER_OF_FIELDS; fieldIndex ++) { | |
values[fieldIndex] = Serial.parseInt(); // get a numeric value | |
} | |
//Serial.print( fieldIndex); | |
//Serial.println(" fields received:"); | |
for(int i=0; i < fieldIndex; i+=3) { | |
//Serial.println(values[i]);\ | |
strip.setPixelColor(i/3, values[i+2],values[i+1],values[0]); | |
} | |
strip.show(); | |
fieldIndex = 0; // ready to start over | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment