LED Strip Pattern Collection
Jump to navigation
Jump to search
| Noisebridge | About | Visit | 272 | Manual | Contact | Guilds | Stuff | Events | Projects | Meetings | Donate | E |
| Guilds (Volunteer) | Maintainers | Meta | Code | Electronics | Fabrication | Games | Sewing | Music | AI | Neuro | Philosophy | Funding | Art | Security | Ham | WGs | E |
| Art | Artbridge | Decorating Noisebridge | Posters | Wall Art | LED Art | LED Signage | ANSI Art | Projection | Payphone | NoiseCanvas | E |
| LED Art | Noisebridge Sign | Welcome Sign | Donation Sign | Flaschen Taschen | Noise Square Table | Big LED Screen | Circuit Chandelier | Mooninite | Patterns | Edit |
LED Strip Pattern Collelction[edit]
Example code for use with LED controllers to make cool patterns.
Note: Some of these may be written specifically for octows2811, neopixel or fastSPI, but it's usually easy to port between them (change the show and set color functions).
Try the LED talk page for some great outside links!
Random Twinkle[edit]
// number, twinkle color, background color, delay
// twinkleRand(5,strip.Color(255,255,255),strip.Color(255, 0, 100),90);
// twinkle random number of pixels
void twinkleRand(int num,uint32_t c,uint32_t bg,int wait) {
// set background
stripSet(bg,0);
// for each num
for (int i=0; i<num; i++) {
strip.setPixelColor(random(strip.numPixels()),c);
}
strip.show();
delay(wait);
}
Set All Pixels Quickly[edit]
// quickly set the entire strip a color
void stripSet(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
}
// move the show outside the loop
strip.show();
delay(wait);
}
Simple Wave[edit]
// very simple wave: velocity, cycles,delay between frames
// simpleWave(0.03,5,10);
void simpleWave(float rate,int cycles, int wait) {
float pos=0.0;
// cycle through x times
for(int x=0; x<(strip.numPixels()*cycles); x++)
{
pos = pos+rate;
for(int i=0; i<strip.numPixels(); i++) {
// sine wave, 3 offset waves make a rainbow!
float level = sin(i+pos) * 127 + 128;
// set color level
strip.setPixelColor(i,(int)level,0,0);
}
strip.show();
delay(wait);
}
}
HSV to RGB[edit]
Really useful function returns RGB values from Hue Saturation Brightness! From teldredge's FAST_SPI LED FX EXAMPLES
void HSVtoRGB(int hue, int sat, int val,int *colors) {
int r, g, b, base;
// hue: 0-359, sat: 0-255, val (lightness): 0-255
if (sat == 0) { // Achromatic color (gray).
colors[0]=val;
colors[1]=val;
colors[2]=val;
} else {
base = ((255 - sat) * val)>>8;
switch(hue/60) {
case 0:
colors[0] = val;
colors[1] = (((val-base)*hue)/60)+base;
colors[2] = base;
break;
case 1:
colors[0] = (((val-base)*(60-(hue%60)))/60)+base;
colors[1] = val;
colors[2] = base;
break;
case 2:
colors[0] = base;
colors[1] = val;
colors[2] = (((val-base)*(hue%60))/60)+base;
break;
case 3:
colors[0] = base;
colors[1] = (((val-base)*(60-(hue%60)))/60)+base;
colors[2] = val;
break;
case 4:
colors[0] = (((val-base)*(hue%60))/60)+base;
colors[1] = base;
colors[2] = val;
break;
case 5:
colors[0] = val;
colors[1] = base;
colors[2] = (((val-base)*(60-(hue%60)))/60)+base;
break;
}
}
}