gamma correction; red cycle pattern
This commit is contained in:
@@ -1,3 +1,21 @@
|
|||||||
|
#define GAMMA_CORRECTION { \
|
||||||
|
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
|
||||||
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, \
|
||||||
|
2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, \
|
||||||
|
3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, \
|
||||||
|
6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, \
|
||||||
|
11, 11, 12, 12, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 17, 17, \
|
||||||
|
18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, \
|
||||||
|
26, 27, 28, 28, 29, 30, 30, 31, 32, 33, 33, 34, 35, 36, 36, 37, \
|
||||||
|
38, 39, 40, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 51, \
|
||||||
|
52, 53, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 68, 69, \
|
||||||
|
70, 71, 73, 74, 75, 76, 78, 79, 80, 82, 83, 84, 86, 87, 88, 90, \
|
||||||
|
91, 93, 94, 96, 97, 99,100,102,103,105,106,108,110,111,113,115, \
|
||||||
|
116,118,120,121,123,125,127,128,130,132,134,136,138,139,141,143, \
|
||||||
|
145,147,149,151,153,155,157,159,161,163,165,168,170,172,174,176, \
|
||||||
|
178,181,183,185,187,190,192,194,197,199,201,204,206,209,211,214, \
|
||||||
|
216,219,221,224,226,229,232,234,237,240,242,245,248,250,253,255}
|
||||||
|
|
||||||
// COMMON SETTINGS
|
// COMMON SETTINGS
|
||||||
// ----------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------------
|
||||||
// These settings are used in both SW UART, HW UART and SPI mode
|
// These settings are used in both SW UART, HW UART and SPI mode
|
||||||
|
|||||||
@@ -10,16 +10,21 @@
|
|||||||
|
|
||||||
#include "BluefruitConfig.h"
|
#include "BluefruitConfig.h"
|
||||||
|
|
||||||
|
const uint8_t PROGMEM gamma[] = GAMMA_CORRECTION;
|
||||||
|
|
||||||
#define REQUIRE_SERIAL false
|
#define REQUIRE_SERIAL false
|
||||||
#define BT_SCAN_MS 50
|
#define BT_SCAN_MS 50
|
||||||
#define MIN_FIRMWARE "0.7.0"
|
#define MIN_FIRMWARE "0.7.0"
|
||||||
#define FACTORYRESET true
|
#define FACTORYRESET true
|
||||||
#define DIM_FACTOR 32
|
|
||||||
|
|
||||||
#define SHIFTING_STOPPED 0
|
#define SHIFTING_STOPPED 0
|
||||||
#define SHIFTING_FORWARD 1
|
#define SHIFTING_FORWARD 1
|
||||||
#define SHIFTING_REVERSE 2
|
#define SHIFTING_REVERSE 2
|
||||||
|
|
||||||
|
#define PATTERN_OFF 0
|
||||||
|
#define PATTERN_RAINBOW 1
|
||||||
|
#define PATTERN_RED 2
|
||||||
|
|
||||||
// Updated with bluetooth connection state
|
// Updated with bluetooth connection state
|
||||||
volatile bool conn = false;
|
volatile bool conn = false;
|
||||||
|
|
||||||
@@ -133,29 +138,22 @@ class Strip {
|
|||||||
unsigned long last;
|
unsigned long last;
|
||||||
uint8_t offset = num_pixels;
|
uint8_t offset = num_pixels;
|
||||||
uint8_t shifting = SHIFTING_REVERSE;
|
uint8_t shifting = SHIFTING_REVERSE;
|
||||||
Adafruit_NeoPixel pixel;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Adafruit_NeoPixel pixel;
|
||||||
uint16_t wait;
|
uint16_t wait;
|
||||||
char pattern;
|
char pattern;
|
||||||
uint8_t amplitude = 0;
|
uint8_t amplitude = 0;
|
||||||
|
|
||||||
Strip(uint8_t led_pin, uint8_t strip_len) {
|
Strip(uint8_t led_pin, uint8_t strip_len) {
|
||||||
pattern = 'r';
|
pattern = PATTERN_RED;
|
||||||
pin = led_pin;
|
pin = led_pin;
|
||||||
num_pixels = strip_len;
|
num_pixels = strip_len;
|
||||||
wait = 0;
|
wait = 0;
|
||||||
last = millis();
|
last = millis();
|
||||||
offset = 0;
|
offset = 0;
|
||||||
pixel = Adafruit_NeoPixel(num_pixels, pin, NEO_GRBW + NEO_KHZ800);
|
pixel = Adafruit_NeoPixel(num_pixels, pin, NEO_GRBW + NEO_KHZ800);
|
||||||
}
|
|
||||||
|
|
||||||
void off(void){
|
|
||||||
pixel.begin();
|
pixel.begin();
|
||||||
for(uint8_t i=0; i<num_pixels; i++){
|
|
||||||
pixel.setPixelColor(i, pixel.Color(0,0,0));
|
|
||||||
}
|
|
||||||
pixel.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_shift_direction(uint8_t new_shift){
|
void set_shift_direction(uint8_t new_shift){
|
||||||
@@ -173,14 +171,22 @@ class Strip {
|
|||||||
last = now;
|
last = now;
|
||||||
add_offset();
|
add_offset();
|
||||||
}
|
}
|
||||||
if (pattern == 'o'){
|
if (pattern == PATTERN_RAINBOW){
|
||||||
off();
|
|
||||||
} else {
|
|
||||||
rainbow();
|
rainbow();
|
||||||
|
} else if (pattern == PATTERN_RED){
|
||||||
|
red();
|
||||||
|
} else {
|
||||||
|
off();
|
||||||
}
|
}
|
||||||
|
pixel.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void off(void){
|
||||||
|
for(uint8_t i=0; i<num_pixels; i++){
|
||||||
|
pixel.setPixelColor(i, pixel.Color(0,0,0));
|
||||||
|
}
|
||||||
|
}
|
||||||
void add_offset(void){
|
void add_offset(void){
|
||||||
/* Increments the offset counter. See get_offset_loc() */
|
/* Increments the offset counter. See get_offset_loc() */
|
||||||
offset++;
|
offset++;
|
||||||
@@ -209,17 +215,38 @@ class Strip {
|
|||||||
}
|
}
|
||||||
return index; // SHIFTING_STOPPED
|
return index; // SHIFTING_STOPPED
|
||||||
}
|
}
|
||||||
void set_pixel(uint8_t index, uint8_t rgb[]){
|
void set_pixel_rgb(uint8_t index, uint8_t rgb[]){
|
||||||
|
set_pixel_rgb(index, rgb[0], rgb[1], rgb[2]);
|
||||||
|
}
|
||||||
|
void set_pixel_rgb(uint8_t index, uint8_t red, uint8_t green, uint8_t blue){
|
||||||
pixel.setPixelColor(
|
pixel.setPixelColor(
|
||||||
get_offset_loc(index),
|
get_offset_loc(index),
|
||||||
pixel.Color(rgb[0]/DIM_FACTOR, rgb[1]/DIM_FACTOR, rgb[2]/DIM_FACTOR)
|
pixel.Color(
|
||||||
|
pgm_read_byte(&gamma[red]),
|
||||||
|
pgm_read_byte(&gamma[green]),
|
||||||
|
pgm_read_byte(&gamma[blue])
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
void set_pixel_rgbw(uint8_t index, uint8_t rgb[]){
|
||||||
|
set_pixel_rgbw(index, rgb[0], rgb[1], rgb[2], rgb[3]);
|
||||||
|
}
|
||||||
|
void set_pixel_rgbw(uint8_t index, uint8_t red, uint8_t green, uint8_t blue, uint8_t white){
|
||||||
|
pixel.setPixelColor(
|
||||||
|
get_offset_loc(index),
|
||||||
|
pixel.Color(
|
||||||
|
pgm_read_byte(&gamma[red]),
|
||||||
|
pgm_read_byte(&gamma[green]),
|
||||||
|
pgm_read_byte(&gamma[blue]),
|
||||||
|
pgm_read_byte(&gamma[white])
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
void rainbow(void){
|
void rainbow(void){
|
||||||
uint8_t rgb[] = {255, 0, 0}; // starting RGB value
|
uint8_t rgb[] = {255, 0, 0}; // starting RGB value
|
||||||
uint8_t phase_len = num_pixels / 6; // how long each rainbow phase is
|
uint8_t phase_len = num_pixels / 6; // how long each rainbow phase is
|
||||||
uint8_t bump = 255 / phase_len; // how much to increase between pixels
|
uint8_t bump = 255 / phase_len; // how much to increase between pixels
|
||||||
set_pixel(0, rgb); // first pixel
|
set_pixel_rgb(0, rgb); // first pixel
|
||||||
for (uint8_t index=1; index < num_pixels; index++){
|
for (uint8_t index=1; index < num_pixels; index++){
|
||||||
uint8_t phase = index / phase_len; // which section we're in
|
uint8_t phase = index / phase_len; // which section we're in
|
||||||
if (phase % 2 == 0){ // even-index phases add; odd-indexed subtracts
|
if (phase % 2 == 0){ // even-index phases add; odd-indexed subtracts
|
||||||
@@ -236,9 +263,26 @@ class Strip {
|
|||||||
rgb[(6 - phase + 2) % 3] = 255;
|
rgb[(6 - phase + 2) % 3] = 255;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set_pixel(index, rgb);
|
set_pixel_rgb(index, rgb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void red(void){
|
||||||
|
float bump = 255.0 / (num_pixels / 2 + 1);
|
||||||
|
uint8_t half_point = num_pixels / 2 + 1;
|
||||||
|
float red = 0;
|
||||||
|
set_pixel_rgb(0, 1, 0, 0);
|
||||||
|
//set_pixel_rgbw(0, 0, 0, 0, 255);
|
||||||
|
for (uint8_t index=1; index < num_pixels; index++){
|
||||||
|
if (index < half_point){
|
||||||
|
red += bump;
|
||||||
|
} else {
|
||||||
|
red -= bump;
|
||||||
|
}
|
||||||
|
uint8_t red_int = (uint8_t)red;
|
||||||
|
//uint8_t white_int = (255 - red_int + 1) / 2;
|
||||||
|
set_pixel_rgb(index, red_int, 0, 0);
|
||||||
|
//set_pixel_rgbw(index, red_int, 0, 0, white_int);
|
||||||
}
|
}
|
||||||
pixel.show();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -262,10 +306,10 @@ void set_pattern(char data[], uint16_t len){
|
|||||||
if (len != 1){
|
if (len != 1){
|
||||||
to_rx = msg_pattern_invalid;
|
to_rx = msg_pattern_invalid;
|
||||||
} else if (data[0] == 'r'){
|
} else if (data[0] == 'r'){
|
||||||
strip.pattern = 'r';
|
strip.pattern = PATTERN_RED;
|
||||||
to_rx = msg_pattern_rainbow;
|
to_rx = msg_pattern_rainbow;
|
||||||
} else if (data[0] == 'o') {
|
} else if (data[0] == 'o') {
|
||||||
strip.pattern = 'o';
|
strip.pattern = PATTERN_OFF;
|
||||||
to_rx = msg_pattern_off;
|
to_rx = msg_pattern_off;
|
||||||
} else {
|
} else {
|
||||||
to_rx = msg_pattern_invalid;
|
to_rx = msg_pattern_invalid;
|
||||||
@@ -317,7 +361,6 @@ void setup(void) {
|
|||||||
}
|
}
|
||||||
bluetooth_setup();
|
bluetooth_setup();
|
||||||
strip.wait = 50;
|
strip.wait = 50;
|
||||||
strip.off();
|
|
||||||
Serial.println(F("Ready"));
|
Serial.println(F("Ready"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user