Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #include <avr/power.h>
- #define PIN 6
- #define NUMPIXELS 24
- Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
- String input = "";
- int firstVal, secondVal;
- const int numberOfPieces = 96;
- String pieces[numberOfPieces];
- int counter = 0;
- int lastIndex = 0;
- void setup() {
- pixels.begin();
- Serial.begin(250000);
- }
- void loop() {
- if (Serial.available() > 0) {
- char ch = Serial.read();
- if (ch == '\n') {
- for (int i = 0; i < input.length(); i++) {
- if (input.substring(i, i + 1) == ",") {
- pieces[counter] = input.substring(lastIndex, i);
- lastIndex = i + 1;
- counter++;
- }
- if (i == input.length() - 1) { pieces[counter] = input.substring(lastIndex, i); }
- }
- for(int i = 0;i<96;i += 4)
- {
- pixels.setPixelColor(pieces[i].toInt(), pixels.Color(pieces[i+1].toInt(),pieces[i+2].toInt(), pieces[i+3].toInt()));
- }
- pixels.show();
- input = "";
- counter = 0;
- lastIndex = 0;
- }
- else {
- input += ch;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement