Advertisement
computermuseo

arcobaleno led strip ws2812b arduino

Mar 23rd, 2017
1,625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #include "FastLED.h"
  2.  
  3. // How many leds in your strip?
  4. #define NUM_LEDS 30
  5.  
  6. // For led chips like Neopixels, which have a data line, ground, and power, you just
  7. // need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
  8. // ground, and power), like the LPD8806, define both DATA_PIN and CLOCK_PIN
  9. #define DATA_PIN 6
  10. #define CLOCK_PIN 13
  11.  
  12. // Define the array of leds
  13. CRGB leds[NUM_LEDS];
  14.  
  15. void setup() {
  16. Serial.begin(57600);
  17. Serial.println("resetting");
  18. LEDS.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
  19. LEDS.setBrightness(255);
  20. }
  21.  
  22. void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }
  23.  
  24. void loop() {
  25. static uint8_t hue = 0;
  26. Serial.print("x");
  27. // First slide the led in one direction
  28. for(int i = 0; i < NUM_LEDS; i++) {
  29. // Set the i'th led to red
  30. leds[i] = CHSV(hue++, 255, 255);
  31. // Show the leds
  32. FastLED.show();
  33. // now that we've shown the leds, reset the i'th led to black
  34. // leds[i] = CRGB::Black;
  35. fadeall();
  36. // Wait a little bit before we loop around and do it again
  37. delay(10);
  38. }
  39. Serial.print("x");
  40.  
  41. // Now go in the other direction.
  42. for(int i = (NUM_LEDS)-1; i >= 0; i--) {
  43. // Set the i'th led to red
  44. leds[i] = CHSV(hue++, 255, 255);
  45. // Show the leds
  46. FastLED.show();
  47. // now that we've shown the leds, reset the i'th led to black
  48. // leds[i] = CRGB::Black;
  49. fadeall();
  50. // Wait a little bit before we loop around and do it again
  51. delay(10);
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement