DJ Namaste
Active member
Hello
I would like to create a way to convert simple images into a bitmask and send a fastled rainbow function or other colors through the bitmask. The code below is a pov image of a skull and crossbones. It is pretty low resolution but the example works but only displays blue where the color value is and off where 0 is. I would like to find a way to change the blue color to whatever color. Right now I use processing.js to create a file with 0 or 255 as values on and off. The processing script also needs work to make it output 0 and 1.
#include "FastLED.h"
#define NUM_LEDS 32
#define DATA_PIN 17
CRGB leds[NUM_LEDS];
void setup() {
delay(2000);
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
}
//skull data
const unsigned int array4[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 255, 255, 0, 255, 255, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 255, 0, 0, 255, 255, 255, 0, 0, 255, 0, 0, 0, 0, 0,
0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0,
0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
void loop() {
PixelRainbow(100, array4,19, 20);// ( L1, L3);
}
void PixelRainbow(unsigned long time, const unsigned int array[], int width, int height){
unsigned long currentTime = millis();
while (millis()< currentTime + (time)) {
int w= width;// previously used numberOfSlices;
int i; //i++
int h=height;
for (int x=0;x<w;x++){
for(i=0;i<h;i++){
leds=array[x+(w*i)];
}
FastLED.show();
// delayMicroseconds(4); //may need to increase / decrease depending on spin rate
}
//delayMicroseconds(10); //may need to increase / decrease depending on spin rate
}
}
// Rainbow colors that slowly cycle across LEDs
void rainbow(int cycles, int speed){ // TODO direction
if(cycles == 0){
for(int i=0; i< NUM_LEDS; i++) {
leds = Wheel(((i * 256 / NUM_LEDS)) & 255);
}
FastLED.show();
}
else{
for(int j=0; j<256*cycles; j++) {
for(int i=0; i< NUM_LEDS; i++) {
leds = Wheel(((i * 256 / NUM_LEDS) + j) & 255);
}
FastLED.show();
delay(speed);
}
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
CRGB Wheel(byte WheelPos) {
if(WheelPos < 85) {
return CRGB(WheelPos * 3, 255 - WheelPos * 3, 0);
}
else if(WheelPos < 170) {
WheelPos -= 85;
return CRGB(255 - WheelPos * 3, 0, WheelPos * 3);
}
else {
WheelPos -= 170;
return CRGB(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
CRGB randomColor(){
return Wheel(random(256));
}
I would like to create a way to convert simple images into a bitmask and send a fastled rainbow function or other colors through the bitmask. The code below is a pov image of a skull and crossbones. It is pretty low resolution but the example works but only displays blue where the color value is and off where 0 is. I would like to find a way to change the blue color to whatever color. Right now I use processing.js to create a file with 0 or 255 as values on and off. The processing script also needs work to make it output 0 and 1.
#include "FastLED.h"
#define NUM_LEDS 32
#define DATA_PIN 17
CRGB leds[NUM_LEDS];
void setup() {
delay(2000);
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
}
//skull data
const unsigned int array4[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 255, 255, 0, 255, 255, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 255, 0, 0, 255, 255, 255, 0, 0, 255, 0, 0, 0, 0, 0,
0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0,
0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
void loop() {
PixelRainbow(100, array4,19, 20);// ( L1, L3);
}
void PixelRainbow(unsigned long time, const unsigned int array[], int width, int height){
unsigned long currentTime = millis();
while (millis()< currentTime + (time)) {
int w= width;// previously used numberOfSlices;
int i; //i++
int h=height;
for (int x=0;x<w;x++){
for(i=0;i<h;i++){
leds=array[x+(w*i)];
}
FastLED.show();
// delayMicroseconds(4); //may need to increase / decrease depending on spin rate
}
//delayMicroseconds(10); //may need to increase / decrease depending on spin rate
}
}
// Rainbow colors that slowly cycle across LEDs
void rainbow(int cycles, int speed){ // TODO direction
if(cycles == 0){
for(int i=0; i< NUM_LEDS; i++) {
leds = Wheel(((i * 256 / NUM_LEDS)) & 255);
}
FastLED.show();
}
else{
for(int j=0; j<256*cycles; j++) {
for(int i=0; i< NUM_LEDS; i++) {
leds = Wheel(((i * 256 / NUM_LEDS) + j) & 255);
}
FastLED.show();
delay(speed);
}
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
CRGB Wheel(byte WheelPos) {
if(WheelPos < 85) {
return CRGB(WheelPos * 3, 255 - WheelPos * 3, 0);
}
else if(WheelPos < 170) {
WheelPos -= 85;
return CRGB(255 - WheelPos * 3, 0, WheelPos * 3);
}
else {
WheelPos -= 170;
return CRGB(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
CRGB randomColor(){
return Wheel(random(256));
}