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.

69 lines
1.5KB

  1. /* WS2812Serial BasicTest Example
  2. Test LEDs by turning then 7 different colors.
  3. This example code is in the public domain. */
  4. #include <WS2812Serial.h>
  5. const int numled = 64;
  6. const int pin = 1;
  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, 17, 20, 24, 29, 39
  13. byte drawingMemory[numled*3]; // 3 bytes per LED
  14. DMAMEM byte displayMemory[numled*12]; // 12 bytes per LED
  15. WS2812Serial leds(numled, displayMemory, drawingMemory, pin, WS2812_GRB);
  16. #define RED 0xFF0000
  17. #define GREEN 0x00FF00
  18. #define BLUE 0x0000FF
  19. #define YELLOW 0xFFFF00
  20. #define PINK 0xFF1088
  21. #define ORANGE 0xE05800
  22. #define WHITE 0xFFFFFF
  23. // Less intense...
  24. /*
  25. #define RED 0x160000
  26. #define GREEN 0x001600
  27. #define BLUE 0x000016
  28. #define YELLOW 0x101400
  29. #define PINK 0x120009
  30. #define ORANGE 0x100400
  31. #define WHITE 0x101010
  32. */
  33. void setup() {
  34. leds.begin();
  35. }
  36. void loop() {
  37. // change all the LEDs in 1.5 seconds
  38. int microsec = 1500000 / leds.numPixels();
  39. colorWipe(RED, microsec);
  40. colorWipe(GREEN, microsec);
  41. colorWipe(BLUE, microsec);
  42. colorWipe(YELLOW, microsec);
  43. colorWipe(PINK, microsec);
  44. colorWipe(ORANGE, microsec);
  45. colorWipe(WHITE, microsec);
  46. }
  47. void colorWipe(int color, int wait) {
  48. for (int i=0; i < leds.numPixels(); i++) {
  49. leds.setPixel(i, color);
  50. leds.show();
  51. delayMicroseconds(wait);
  52. }
  53. }