HEX_SK6812.ino 930 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. Description: Control HEX Unit 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 37
  10. CRGB leds[NUM_LEDS];
  11. uint8_t gHue = 0;
  12. void setup() {
  13. Serial.begin(115200);
  14. M5.Power.begin();
  15. M5.begin();
  16. M5.Lcd.clear(BLACK);
  17. M5.Lcd.setTextColor(YELLOW); M5.Lcd.setTextSize(2); M5.Lcd.setCursor(40, 0);
  18. M5.Lcd.println("HEX Example");
  19. M5.Lcd.setTextColor(WHITE);
  20. M5.Lcd.setCursor(0, 25);
  21. M5.Lcd.println("Display rainbow effect");
  22. // Neopixel initialization
  23. FastLED.addLeds<WS2811,Neopixel_PIN,GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  24. FastLED.setBrightness(10);
  25. }
  26. void loop(){
  27. fill_rainbow( leds, NUM_LEDS, gHue, 7);
  28. FastLED.show();// must be executed for neopixel becoming effective
  29. EVERY_N_MILLISECONDS( 20 ) { gHue++; }
  30. }