Advertisement
microrobotics

DIATONE 3X4 2812 LED Matrix 5V

May 10th, 2023
1,297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. For a DIATONE 3x4 WS2812 LED Matrix, which is often used in FPV drone builds, it's usually controlled through flight controller firmware like Betaflight or Cleanflight, as they have built-in support for WS2812 LEDs.
  3.  
  4. However, if you want to control it using an Arduino or ESP32, you can use the Adafruit_NeoPixel library. The DIN (Data IN) pin is used to send data to the LED matrix.
  5.  
  6. In this code, replace LED_PIN with the pin connected to the DIN of your LED matrix, and LED_COUNT with the total number of LEDs in the matrix. This code will light up each LED in a random color and refresh every half a second.
  7.  
  8. Please note the Adafruit_NeoPixel library uses a considerable amount of dynamic memory, so be aware if your project has other memory requirements.
  9.  
  10. Here's an example of how to light up the matrix in different colors:
  11. */
  12.  
  13. #include <Adafruit_NeoPixel.h>
  14.  
  15. #define LED_PIN    2  // The pin your LED strip is connected to
  16. #define LED_COUNT 12  // The number of LEDs in the matrix
  17.  
  18. // Declare our NeoPixel strip object:
  19. Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
  20.  
  21. void setup() {
  22.   strip.begin();           // Initialize the NeoPixel library
  23.   strip.show();            // Initialize all pixels to 'off'
  24. }
  25.  
  26. void loop() {
  27.   // Make the LEDs show different colors
  28.   for(int i=0; i<LED_COUNT; i++) {
  29.     strip.setPixelColor(i, strip.Color(random(0,255), random(0,255), random(0,255)));  // Random color
  30.   }
  31.   strip.show();   // Send the updated pixel colors to the hardware.
  32.   delay(500);     // Pause before next pass through loop
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement