Advertisement
AsmodHacker

24/4 Array Scanner

Jul 8th, 2015
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #include <avr/power.h>
  3. #define PIN 6
  4. #define NUMPIXELS 24
  5. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  6. String input = "";
  7. int firstVal, secondVal;
  8. const int numberOfPieces = 96;
  9. String pieces[numberOfPieces];
  10. int counter = 0;
  11. int lastIndex = 0;
  12.  
  13. void setup() {
  14. pixels.begin();
  15. Serial.begin(250000);
  16. }
  17.  
  18. void loop() {
  19. if (Serial.available() > 0) {
  20. char ch = Serial.read();
  21. if (ch == '\n') {
  22. for (int i = 0; i < input.length(); i++) {
  23. if (input.substring(i, i + 1) == ",") {
  24. pieces[counter] = input.substring(lastIndex, i);
  25. lastIndex = i + 1;
  26. counter++;
  27. }
  28. if (i == input.length() - 1) { pieces[counter] = input.substring(lastIndex, i); }
  29. }
  30. for(int i = 0;i<96;i += 4)
  31. {
  32. pixels.setPixelColor(pieces[i].toInt(), pixels.Color(pieces[i+1].toInt(),pieces[i+2].toInt(), pieces[i+3].toInt()));
  33. }
  34. pixels.show();
  35. input = "";
  36. counter = 0;
  37. lastIndex = 0;
  38. }
  39. else {
  40. input += ch;
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement