Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Here's the example code for controlling the CJMCU-9813 Full Colour RGB LED Module using the P9813 driver with an Arduino:
- This code sets the RGB LED color to red, green, and blue in sequence, with a 1-second delay between each color change.
- Connect the CJMCU-9813 Full Colour RGB LED Module to the Arduino as follows:
- VCC pin to 5V (or the appropriate voltage for your module)
- GND pin to GND
- DATA pin to digital pin 5 on the Arduino
- CLK pin to digital pin 4 on the Arduino
- Please note that you may need to adjust the pin numbers in the code depending on the specific pins you choose to use for connecting the module to your Arduino.
- */
- #include <Arduino.h>
- const int clkPin = 4; // Connect this pin to the CLK pin of the module
- const int dataPin = 5; // Connect this pin to the DATA pin of the module
- void setup() {
- pinMode(clkPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- }
- void loop() {
- setColor(255, 0, 0); // Set LED color to red
- delay(1000);
- setColor(0, 255, 0); // Set LED color to green
- delay(1000);
- setColor(0, 0, 255); // Set LED color to blue
- delay(1000);
- }
- void setColor(byte red, byte green, byte blue) {
- sendFrame(0x00); // Start frame
- sendFrame(((blue & 0xC0) >> 6) | ((green & 0xC0) >> 4) | ((red & 0xC0) >> 2));
- sendFrame(blue);
- sendFrame(green);
- sendFrame(red);
- }
- void sendFrame(byte value) {
- for (byte bit = 0x80; bit != 0; bit >>= 1) {
- digitalWrite(clkPin, LOW);
- digitalWrite(dataPin, (value & bit) ? HIGH : LOW);
- digitalWrite(clkPin, HIGH);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement