Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2.  
  3. // Which pin on the Arduino is connected to the NeoPixels?
  4. #define PIN 6
  5.  
  6. // How many NeoPixels are attached to the Arduino?
  7. #define NUMPIXELS 30
  8.  
  9. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  10.  
  11. void setup() {
  12. // initialize serial
  13. Serial.begin(9600);
  14. // This initializes the NeoPixel library.
  15. pixels.begin();
  16. }
  17.  
  18. void loop() {
  19.  
  20. // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
  21. // if there's any serial available, read it:
  22. while (Serial.available() > 0) {
  23.  
  24. // look for the next valid integer in the incoming serial stream:
  25. int red = Serial.parseInt();
  26. // do it again:
  27. int green = Serial.parseInt();
  28. // do it again:
  29. int blue = Serial.parseInt();
  30.  
  31. // look for the newline. That's the end of your sentence:
  32. if (Serial.read() == '\n') {
  33. red = constrain(red, 0, 255);
  34. green = constrain(green, 0, 255);
  35. blue = constrain(blue, 0, 255);
  36.  
  37. for(int i=0;i<NUMPIXELS;i++){
  38.  
  39. // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
  40. pixels.setPixelColor(i, pixels.Color(red,green,blue));
  41. pixels.show(); // This sends the updated pixel color to the hardware.
  42.  
  43. }
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement