RGB_SK6812.ino 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. Description: Control RGB Unit to scroll through three colors of red, green and blue
  3. Please install library before compiling:
  4. AdaFruit NeoPixel: https://github.com/adafruit/Adafruit_NeoPixel
  5. */
  6. #include <Adafruit_NeoPixel.h>
  7. #include <M5Stack.h>
  8. // Which pin on the Arduino is connected to the NeoPixels?
  9. // On a Trinket or Gemma we suggest changing this to 1
  10. #define PIN 26
  11. // How many NeoPixels are attached to the Arduino?
  12. #define NUMPIXELS 3
  13. // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
  14. // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
  15. // example for more information on possible values.
  16. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  17. int delayval = 150; // delay for half a second
  18. void setup() {
  19. M5.begin();
  20. M5.Power.begin();
  21. pixels.begin(); // This initializes the NeoPixel library.
  22. M5.Lcd.setTextFont(4);
  23. M5.Lcd.setCursor(70, 100, 4);
  24. M5.Lcd.println(("RGB Example"));
  25. }
  26. void loop() {
  27. pixels.setPixelColor(0, pixels.Color(100,0,0)); // Moderately bright red color.
  28. pixels.setPixelColor(1, pixels.Color(0,100,0)); // Moderately bright green color.
  29. pixels.setPixelColor(2, pixels.Color(0,0,100)); // Moderately bright blue color.
  30. pixels.show(); // This sends the updated pixel color to the hardware.
  31. delay(delayval); // Delay for a period of time (in milliseconds)
  32. pixels.setPixelColor(0, pixels.Color(0,100,0));
  33. pixels.setPixelColor(1, pixels.Color(0,0,100));
  34. pixels.setPixelColor(2, pixels.Color(100,0,0));
  35. pixels.show();
  36. delay(delayval);
  37. pixels.setPixelColor(0, pixels.Color(0,0,100));
  38. pixels.setPixelColor(1, pixels.Color(100,0,0));
  39. pixels.setPixelColor(2, pixels.Color(0,100,0));
  40. pixels.show();
  41. delay(delayval);
  42. // pixels.setPixelColor(0, pixels.Color(100,100,100));
  43. // pixels.setPixelColor(1, pixels.Color(100,100,100));
  44. // pixels.setPixelColor(2, pixels.Color(100,100,100));
  45. // pixels.show();
  46. // delay(delayval);
  47. }