microrobotics icon

DIATONE 3X4 2812 LED Matrix 5V

microrobotics | PRO | 05/10/23 11:53:32 AM UTC | 0 ⭐ | 2501 👁️ | Never ⏰ | []
Arduino |

1.56 KB

|

None

|

0 👍

/

0 👎

/*
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.
 
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.
 
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.
 
Please note the Adafruit_NeoPixel library uses a considerable amount of dynamic memory, so be aware if your project has other memory requirements.
 
Here's an example of how to light up the matrix in different colors:
*/
 
#include <Adafruit_NeoPixel.h>
 
#define LED_PIN    2  // The pin your LED strip is connected to
#define LED_COUNT 12  // The number of LEDs in the matrix
 
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
 
void setup() {
  strip.begin();           // Initialize the NeoPixel library
  strip.show();            // Initialize all pixels to 'off'
}
 
void loop() {
  // Make the LEDs show different colors
  for(int i=0; i<LED_COUNT; i++) {
    strip.setPixelColor(i, strip.Color(random(0,255), random(0,255), random(0,255)));  // Random color
  }
  strip.show();   // Send the updated pixel colors to the hardware.
  delay(500);     // Pause before next pass through loop
}
 

Comments