Skip to content

Instantly share code, notes, and snippets.

@yyolk
Forked from greymechanic/parseIntArd.ino
Created June 18, 2013 20:07
Show Gist options
  • Save yyolk/5808818 to your computer and use it in GitHub Desktop.
Save yyolk/5808818 to your computer and use it in GitHub Desktop.
// 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