Our new assignment is to make a creative animation with our Neopixel FeatherWing. I hope I’m wrong, but I don’t believe the example files that were uploaded for class were set up properly to take advantage of the RGB to HSB conversion table. I’m completely lost again, and really don’t clearly understand what I’m doing, feeling frustrated and starting to think I need to look at Max if I want to program anything that works in the future.

I wish I could post links of a site that  helped, but I really can’t find videos to help me program the FeatherWing. Really, the main issue is this color conversion code we are using, which I have zero control over after working on for hours. Over it.

Here’s what I’ve cooked up so far:

/*
Control a RGB led with Hue, Saturation and Brightness (HSB / HSV )

Hue is change by an analog input.
Brightness is changed by a fading function.
Saturation stays constant at 255

getRGB() function based on <http://www.codeproject.com/miscctrl/CPicker.asp>
dim_curve idea by Jims

created 05-01-2010 by kasperkamperman.com
*/

/*
dim_curve ‘lookup table’ to compensate for the nonlinearity of human vision.
Used in the getRGB function on saturation and brightness to make ‘dimming’ look more natural.
Exponential function used to create values below :
x from 0 – 255 : y = round(pow( 2.0, x+64/40.0) – 1)
*/

const byte dim_curve[] = {
0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6,
6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11,
11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15,
15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20,
20, 20, 21, 21, 22, 22, 22, 23, 23, 24, 24, 25, 25, 25, 26, 26,
27, 27, 28, 28, 29, 29, 30, 30, 31, 32, 32, 33, 33, 34, 35, 35,
36, 36, 37, 38, 38, 39, 40, 40, 41, 42, 43, 43, 44, 45, 46, 47,
48, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
63, 64, 65, 66, 68, 69, 70, 71, 73, 74, 75, 76, 78, 79, 81, 82,
83, 85, 86, 88, 90, 91, 93, 94, 96, 98, 99, 101, 103, 105, 107, 109,
110, 112, 114, 116, 118, 121, 123, 125, 127, 129, 132, 134, 136, 139, 141, 144,
146, 149, 151, 154, 157, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 190,
193, 196, 200, 203, 207, 211, 214, 218, 222, 226, 230, 234, 238, 242, 248, 255,
};

#include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(32, 6, NEO_GRB + NEO_KHZ800);

int rgb_colors[3]; //recieves the results from hsb conversion
int scenelength[3] = {5000, 5000, 1000};
int scene = 1;
byte matrix[8][4] = {
{24, 16, 8, 0}, //board oriented with USB cable at top
{25, 17, 9, 1},
{26, 18, 10, 2},
{27, 19, 11, 3},
{28, 20, 12, 4},
{29, 21, 13, 5},
{30, 22, 14, 6},
{31, 23, 15, 7}
};

byte matrix2[8][4] = {
{24, 16, 8, 0}, //board oriented with USB cable at top
{25, 17, 9, 1},
{26, 18, 10, 2},
{27, 19, 11, 3},
{28, 20, 12, 4},
{29, 21, 13, 5},
{30, 22, 14, 6},
{31, 23, 15, 7}
};

byte C[8][4] = {
{0, 1, 1, 0},
{1, 0, 0, 0},
{1, 0, 0, 0},
{1, 0, 0, 0},
{1, 0, 0, 0},
{1, 0, 0, 0},
{1, 0, 0, 0},
{0, 1, 1, 0}
};

int h, s, b;
byte column = 0;
byte row = 0;
byte offset = 0;
unsigned long lastTime = 0;
unsigned long columnTime = 0;
unsigned long offsetTime = 0;
unsigned long rowTime = 0;
unsigned long currentTime = 0;

void setup() {
pixels.begin();
// s = 250;
// b = 120;
}

void loop() {
currentTime = millis();
pixels.clear();
if (currentTime – lastTime > scenelength[scene – 1]) {
scene++;
lastTime = currentTime;
if (scene > 2) scene = 1;
}

switch (scene) {
case 1:
act1();//do something when var equals 1

break;
case 2:
act2();//do something when var equals 2
break;
// case 3:
// act3();
// break;
default:
// if nothing else matches, do the default
// default is optional
break;
}
pixels.show();
}

void act1() {
for (int i = 0; i < 8; i++) {
pixels.setPixelColor(matrix[i][column], (pixels.Color(rgb_colors[0], rgb_colors[1], rgb_colors[2])));
for (int y = 0; y < 4 ; y++) {
pixels.setPixelColor(matrix[row][y], (pixels.Color(rgb_colors[0], rgb_colors[1], rgb_colors[2])));
h = ((cos((currentTime + i * 200) / 1000.0) + 1.0) * 100.0); // 180 is max to hit full 360 color range.
if (h > 1 && h < 300) {
b = 200;
s = 255;
} else {
b = 50;
s = 255;
}
}
}
if (currentTime – columnTime > 200) {
column++;
if (column > 3)column = 0;
columnTime = currentTime;
}
if (currentTime – rowTime > 50) {
row++;
if (row > 7)row = 0;
rowTime = currentTime;
}
getRGB(h, s, b, rgb_colors); // converts HSB to RGB
}

void act2() {
for (int i = 0; i < 4; i++) {
pixels.setPixelColor(matrix2[row][i], (pixels.Color(rgb_colors[0], rgb_colors[1], rgb_colors[2])));
h = ((sin((currentTime + i * 500) / 100) + 1.0) * 100); //((sin((currentTime + 1 * ??) / strobespeed) +1.0 *
s = 255;
b = 200;
}
if (currentTime – rowTime > 400) {
row++;
if (row > 7)row = 0;
rowTime = currentTime;
}
getRGB(h, s, b, rgb_colors); // converts HSB to RGB
}

void act3() {
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 8; y++) {
if ( C[y][(x + offset) % 4] ) { //keep (x + offset) in bounds of the array
pixels.setPixelColor(matrix[y][x], pixels.Color(200, 0, 100));
}
}
}
if (currentTime – offsetTime > 100) {
offset–;
if (offset < 0)offset = 3;
offsetTime = currentTime;
}
}
void getRGB(int hue, int sat, int val, int colors[3]) {
/* convert hue, saturation and brightness ( HSB/HSV ) to RGB
The dim_curve is used only on brightness/value and on saturation (inverted).
This looks the most natural.
*/
val = dim_curve[val];
sat = 255 – dim_curve[255 – sat];

int r;
int g;
int b;
int base;

hue = hue % 360; //account for hues going over the 360

if (sat == 0) { // Acromatic color (gray). Hue doesn’t mind.
colors[0] = val;
colors[1] = val;
colors[2] = val;
} else {

base = ((255 – sat) * val) >> 8;

switch (hue / 60) {
case 0:
r = val;
g = (((val – base) * hue) / 60) + base;
b = base;
break;

case 1:
r = (((val – base) * (60 – (hue % 60))) / 60) + base;
g = val;
b = base;
break;

case 2:
r = base;
g = val;
b = (((val – base) * (hue % 60)) / 60) + base;
break;

case 3:
r = base;
g = (((val – base) * (60 – (hue % 60))) / 60) + base;
b = val;
break;

case 4:
r = (((val – base) * (hue % 60)) / 60) + base;
g = base;
b = val;
break;

case 5:
r = val;
g = base;
b = (((val – base) * (60 – (hue % 60))) / 60) + base;
break;
}

colors[0] = r;
colors[1] = g;
colors[2] = b;
}
}

 

agencywordpress themes