/*
Strip RGB LED Demo WS2812 LED
Author: Bonezegei (Jofel Batutay)
Date: October 2023
Uses 24 bit Hex color format
Note : The Colors used on this demo was not set to maximum since it will be too bright during testing
*/
#include <Bonezegei_WS2812.h>
#define LED_COUNT 10
Bonezegei_WS2812 rgb(14, LED_COUNT);
void setup() {
Serial.begin(115200);
rgb.begin();
}
#define LED_COLOR_RED 0x0f0000
#define LED_COLOR_GREEN 0x0f00
#define LED_COLOR_BLUE 0x0f
typedef struct {
uint8_t state;
uint32_t value;
}color_state_t;
enum color_names_t{
RED_MIN = 0,
RED_LOW,
RED_MID,
RED_HIGH,
GREEN_MIN,
GREEN_LOW,
GREEN_MID,
GREEN_HIGH,
BLUE_MIN,
BLUE_LOW,
BLUE_MID,
BLUE_HIGH,
COLOR_MAX
};
enum LED_OPS_T{
LED_SET = 0,
LED_ADD =1,
LED_CLEAR =2,
} ;
#define DIMENSION( x) (sizeof(x) / sizeof(&x[0]))
color_state_t led_states[]
{
{color_names_t::RED_MIN, 0x010000},
{color_names_t::RED_LOW, 0x030000},
{color_names_t::RED_MID, 0x070000},
{color_names_t::RED_HIGH, 0x0F0000},
{color_names_t::GREEN_MIN, 0x0100},
{color_names_t::GREEN_LOW, 0x0300},
{color_names_t::GREEN_MID, 0x0700},
{color_names_t::GREEN_HIGH, 0x0F00},
{color_names_t::BLUE_MIN, 0x01},
{color_names_t::BLUE_LOW, 0x03},
{color_names_t::BLUE_MID, 0x07},
{color_names_t::BLUE_HIGH, 0x0F},
};
uint32_t get_led_value( char state)
{
for (int entry; entry < DIMENSION(led_states); entry++)
{
if(state == led_states[entry].state)
{
return led_states[entry].value;
}
}
}
uint32_t led_setting[LED_COUNT];
void adjust_led_setting(uint16_t led, uint32_t setting, uint8_t ops)
{
if (led >= LED_COUNT) return;
switch (ops)
{
case LED_OPS_T::LED_SET:
led_setting[led] = setting;
break;
case LED_OPS_T::LED_ADD:
led_setting[led] += setting;
break;
case LED_OPS_T::LED_CLEAR:
led_setting[led] = 0;
break;
break;
default:
//do nothing
break;
}
}
void set_leds(void)
{
for (int led = 0; led < LED_COUNT; led++) {
rgb._setPixel(led, led_setting[led]);
}
rgb.display();
delay(10);
}
void rotate_leds_backward(void)
{
// 0 is now 1, 1 is now 2, n is now 0
uint32_t temp = led_setting[0];
for (int led=1; led < LED_COUNT; led++)
{
led_setting[led-1] = led_setting[led];
}
led_setting[LED_COUNT-1]=temp;
}
void rotate_leds_forward(void)
{
// n is now 0, 0 is now 1, 1 is now 2
uint32_t temp = led_setting[LED_COUNT-1];
for (int led=0; led < LED_COUNT-1; led++)
{
led_setting[led+1] = led_setting[led];
}
led_setting[0]=temp;
}
/*
color_names_t::COLOR_MAX
adjust_led_setting(led, get_led_value() LED_SET)
*/
void loop() {
rgb.fill(LED_COLOR_RED); //RED
delay(1000);
rgb.fill(0x0f00); //GREEN
delay(1000);
rgb.fill(0x0f); //BLUE
delay(1000);
rgb.fill(0x0);
delay(1000);
Serial.println("test print");
for (int a = 0; a < LED_COUNT; a++) {
rgb._setPixel(a, LED_COLOR_GREEN);
delay(10);
}
rgb.display();
delay(1000);
for (int a = 0; a < LED_COUNT; a=a+2) {
rgb.setPixel(a, LED_COLOR_BLUE);
delay(1000);
}
for (int a = 1; a < LED_COUNT; a = a + 2) {
rgb.setPixel(a, LED_COLOR_RED);
delay(1000);
}
delay(5000);
/*
for (int a = 0; a < LED_COUNT; a++) {
rgb.setPixel(a, LED_COLOR_GREEN);
delay(10);
}
for (int a = 0; a < LED_COUNT; a++) {
rgb.setPixel(a, LED_COLOR_BLUE);
delay(10);
}
for (int a = 0; a < LED_COUNT; a++) {
rgb.setPixel(a, a << 16);
delay(20);
}
for (int a = 0; a < LED_COUNT; a++) {
rgb.setPixel(a, a << 8);
delay(20);
}
for (int a = 0; a < LED_COUNT; a++) {
rgb.setPixel(a, a);
delay(20);
}
//fade
for (int a = 0; a < 96; a++) {
rgb.fill(a); //BLUE
delay(10);
}
for (int a = 96; a > 0; a--) {
rgb.fill(a); //BLUE
delay(10);
}
//fade
for (int a = 0; a < 96; a++) {
rgb.fill(a << 8);
delay(10);
}
for (int a = 96; a > 0; a--) {
rgb.fill(a << 8);
delay(10);
}
//fade
for (int a = 0; a < 96; a++) {
rgb.fill(a);
delay(10);
}
for (int a = 96; a > 0; a--) {
rgb.fill(a);
delay(10);
}
//fade
for (int a = 0; a < 96; a++) {
rgb.fill(a << 16);
delay(10);
}
for (int a = 96; a > 0; a--) {
rgb.fill(a << 16);
delay(10);
}
//fade
for (int a = 0; a < 96; a++) {
rgb.fill((a << 16) | (a << 8));
delay(10);
}
for (int a = 96; a > 0; a--) {
rgb.fill((a << 16) | (a << 8));
delay(10);
}
//fade
for (int a = 0; a < 96; a++) {
rgb.fill((a << 8) | a);
delay(10);
}
for (int a = 96; a > 0; a--) {
rgb.fill((a << 8) | a);
delay(10);
}
//fade
for (int a = 0; a < 96; a++) {
rgb.fill((a << 16) | a);
delay(10);
}
for (int a = 96; a > 0; a--) {
rgb.fill((a << 16) | a);
delay(10);
}
//fade
for (int a = 0; a < 96; a++) {
rgb.fill((a << 8) | (a << 16) | a);
delay(10);
}
for (int a = 96; a > 0; a--) {
rgb.fill((a << 8) | (a << 16) | a);
delay(10);
}
*/
}