CATEAR_SK6812.ino 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Description: Control CAT EAR to run rainbow light show
  3. Please install library before compiling:
  4. FastLED: https://github.com/FastLED/FastLED
  5. */
  6. #include <M5Stack.h>
  7. #include "FastLED.h"
  8. #define Neopixel_PIN 21
  9. #define NUM_LEDS 118
  10. CRGB leds[NUM_LEDS];
  11. uint8_t gHue = 0;
  12. static TaskHandle_t FastLEDshowTaskHandle = 0;
  13. static TaskHandle_t userTaskHandle = 0;
  14. void setup() {
  15. M5.begin();
  16. M5.Power.begin();
  17. M5.Lcd.clear(BLACK);
  18. M5.Lcd.setTextColor(YELLOW); M5.Lcd.setTextSize(2); M5.Lcd.setCursor(60, 160);
  19. M5.Lcd.println("CatEar Example");
  20. M5.Lcd.setTextColor(WHITE);
  21. // Neopixel initialization
  22. FastLED.addLeds<WS2811,Neopixel_PIN,GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  23. FastLED.setBrightness(10);
  24. xTaskCreatePinnedToCore(FastLEDshowTask, "FastLEDshowTask", 2048, NULL, 2, NULL, 1);
  25. }
  26. void loop()
  27. {
  28. }
  29. void FastLEDshowESP32()
  30. {
  31. if (userTaskHandle == 0) {
  32. userTaskHandle = xTaskGetCurrentTaskHandle();
  33. xTaskNotifyGive(FastLEDshowTaskHandle);
  34. const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 );
  35. ulTaskNotifyTake(pdTRUE, xMaxBlockTime);
  36. userTaskHandle = 0;
  37. }
  38. }
  39. void FastLEDshowTask(void *pvParameters)
  40. {
  41. for(;;) {
  42. fill_rainbow(leds, NUM_LEDS, gHue, 7);// rainbow effect
  43. FastLED.show();// must be executed for neopixel becoming effective
  44. EVERY_N_MILLISECONDS( 20 ) { gHue++; }
  45. }
  46. }