Skip to content
Snippets Groups Projects
Verified Commit 426ba2d7 authored by Andreas Horn's avatar Andreas Horn
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
/.vscode/*
# 12bit RGBW Strip Version 1
One module consists of 6 LEDs. LEDs `LED3` and `LED4` are wired in a revers order (WBGR instead of RGBW).
\ No newline at end of file
#include "rgbw-strip-12bit.h"
// one block has 6 LEDs
#define NUM_STRIP_BLOCKS 1
#define DIN 5
#define CLK 6
#define LAT 7
#define BLK 8 // set to -1 to if not used (can be pulled to GND manually)
RgbwStrip12bit strip = RgbwStrip12bit(NUM_STRIP_BLOCKS, CLK, DIN, LAT);
void setup() {
Serial.begin(9600);
Serial.println("12bit RGBW strip test");
strip.begin();
if (BLK >= 0) {
pinMode(BLK, OUTPUT);
digitalWrite(BLK, LOW);
}
}
void loop() {
colorWipe(4095, 0, 0, 0, 100); // red
delay(200);
colorWipe(0, 4095, 0, 0, 100); // green
delay(200);
colorWipe(0, 0, 4095, 0, 100); // blue
delay(200);
colorWipe(0, 0, 0, 4095, 100); // white
delay(200);
rainbowCycle(2);
}
// light up one LED after another
void colorWipe(uint16_t r, uint16_t g, uint16_t b, uint16_t w, uint8_t wait) {
for (uint16_t i = 0; i < 6 * NUM_STRIP_BLOCKS; i++) {
strip.setLED(i, r, g, b, w);
strip.write();
delay(wait);
}
}
// shows a rainbow
void rainbowCycle(uint8_t wait) {
uint32_t i, j;
for (j = 0; j < 4096; j++) { // one cycle of all colors on wheel
for (i = 0; i < 6 * NUM_STRIP_BLOCKS; i++) {
Wheel(i, ((i * 4096 / (6 * NUM_STRIP_BLOCKS)) + j) & 4095);
}
strip.write();
delay(wait);
}
}
// Input a value 0 to 4095 to get a color value.
// The colours are a transition r - g - b - back to r.
void Wheel(uint8_t ledn, uint16_t WheelPos) {
if (WheelPos < 1365) {
strip.setLED(ledn, 3 * WheelPos, 4095 - 3 * WheelPos, 0, 0);
} else if (WheelPos < 2731) {
WheelPos -= 1365;
strip.setLED(ledn, 4095 - 3 * WheelPos, 0, 3 * WheelPos, 0);
} else {
WheelPos -= 2731;
strip.setLED(ledn, 0, 3 * WheelPos, 4095 - 3 * WheelPos, 0);
}
}
\ No newline at end of file
name=12bit RGBW Stripe v1
version=1.0.0
author=ahorn42
maintainer=Andreas Horn <ahorn@c3pb.de>
sentence=Library for a 12bit RGBW strip with 6 LEDs based on TLC5947.
category=Display
url=https://git.c3pb.de/ahorn/lib-12-bit-rgbw-strip
architectures=*
#include <rgbw-strip-12bit.h>
RgbwStrip12bit::RgbwStrip12bit(uint16_t num, uint8_t clk, uint8_t data, uint8_t latch) {
this->num = num;
this->clk = clk;
this->dat = data;
this->lat = latch;
pwmBuffer = (uint16_t*) malloc(2 * 24 * num);
memset(pwmBuffer, 0, 2 * 24 * num);
}
void RgbwStrip12bit::write(void) {
digitalWrite(lat, LOW);
// 24 channels per TLC5974
for (int16_t c = 24 * num - 1; c >= 0; c--) {
// 12 bits per channel, send MSB first
for (int8_t b = 11; b >= 0; b--) {
digitalWrite(clk, LOW);
if (pwmBuffer[c] & (1 << b))
digitalWrite(dat, HIGH);
else
digitalWrite(dat, LOW);
digitalWrite(clk, HIGH);
}
}
digitalWrite(clk, LOW);
digitalWrite(lat, HIGH);
digitalWrite(lat, LOW);
}
void RgbwStrip12bit::setPWM(uint16_t channel, uint16_t pwm) {
if (pwm > 4095)
pwm = 4095;
if (channel > 24 * num)
return;
pwmBuffer[channel] = pwm;
}
void RgbwStrip12bit::setLED(uint16_t ledNum, uint16_t r, uint16_t g, uint16_t b, uint16_t w) {
if (ledNum % 6 == 2 || ledNum % 6 == 3) {
setPWM(ledNum * 4, r);
setPWM(ledNum * 4 + 1, g);
setPWM(ledNum * 4 + 2, b);
setPWM(ledNum * 4 + 3, w);
} else {
setPWM(ledNum * 4, w);
setPWM(ledNum * 4 + 1, b);
setPWM(ledNum * 4 + 2, g);
setPWM(ledNum * 4 + 3, r);
}
}
boolean RgbwStrip12bit::begin() {
if (!pwmBuffer)
return false;
pinMode(clk, OUTPUT);
pinMode(dat, OUTPUT);
pinMode(lat, OUTPUT);
digitalWrite(lat, LOW);
return true;
}
\ No newline at end of file
#ifndef RGBW_STRIP_12BIT_V1_H
#define RGBW_STRIP_12BIT_V1_H
#include <Arduino.h>
class RgbwStrip12bit {
public:
RgbwStrip12bit(uint16_t num, uint8_t clk, uint8_t data, uint8_t latch);
boolean begin(void);
void setPWM(uint16_t channel, uint16_t pwm);
void setLED(uint16_t ledNum, uint16_t r, uint16_t g, uint16_t b, uint16_t w);
void write(void);
private:
uint16_t* pwmBuffer;
uint16_t num;
uint8_t clk;
uint8_t dat;
uint8_t lat;
};
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment