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.

60 lines
1.5KB

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