You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.4KB

  1. // FastLED Cylon Example, using Non-Blocking WS2812Serial
  2. #include <WS2812Serial.h>
  3. #define USE_WS2812SERIAL
  4. #include <FastLED.h>
  5. // How many leds in your strip?
  6. #define NUM_LEDS 64
  7. // Usable pins:
  8. // Teensy LC: 1, 4, 5, 24
  9. // Teensy 3.2: 1, 5, 8, 10, 20, 31
  10. // Teensy 3.5: 1, 5, 8, 10, 20, 26, 32, 33, 48
  11. // Teensy 3.6: 1, 5, 8, 10, 20, 26, 32, 33
  12. #define DATA_PIN 1
  13. // Define the array of leds
  14. CRGB leds[NUM_LEDS];
  15. void setup() {
  16. Serial.begin(57600);
  17. Serial.println("resetting");
  18. LEDS.addLeds<WS2812SERIAL,DATA_PIN,RGB>(leds,NUM_LEDS);
  19. LEDS.setBrightness(84);
  20. }
  21. void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }
  22. void loop() {
  23. static uint8_t hue = 0;
  24. Serial.print("x");
  25. // First slide the led in one direction
  26. for(int i = 0; i < NUM_LEDS; i++) {
  27. // Set the i'th led to red
  28. leds[i] = CHSV(hue++, 255, 255);
  29. // Show the leds
  30. FastLED.show();
  31. // now that we've shown the leds, reset the i'th led to black
  32. // leds[i] = CRGB::Black;
  33. fadeall();
  34. // Wait a little bit before we loop around and do it again
  35. delay(20);
  36. }
  37. Serial.print("x");
  38. // Now go in the other direction.
  39. for(int i = (NUM_LEDS)-1; i >= 0; i--) {
  40. // Set the i'th led to red
  41. leds[i] = CHSV(hue++, 255, 255);
  42. // Show the leds
  43. FastLED.show();
  44. // now that we've shown the leds, reset the i'th led to black
  45. // leds[i] = CRGB::Black;
  46. fadeall();
  47. // Wait a little bit before we loop around and do it again
  48. delay(20);
  49. }
  50. }