246 lines
7.6 KiB
C++
246 lines
7.6 KiB
C++
|
#include "Ledpixel.h"
|
||
|
|
||
|
bool st_refresh = true;
|
||
|
|
||
|
#if neopixel
|
||
|
#include <Adafruit_NeoPixel.h>
|
||
|
Adafruit_NeoPixel strip1(NUM_LEDS, PIN_STRIP1, NEO_GRBW + NEO_KHZ800);
|
||
|
Adafruit_NeoPixel strip2(NUM_LEDS, PIN_STRIP2, NEO_GRBW + NEO_KHZ800);
|
||
|
Adafruit_NeoPixel strip3(NUM_LEDS, PIN_STRIP3, NEO_GRBW + NEO_KHZ800);
|
||
|
Adafruit_NeoPixel strip4(1, PIN_STRIP4, NEO_GRBW + NEO_KHZ800);
|
||
|
|
||
|
#else
|
||
|
#include <FastLED.h>
|
||
|
#include "FastLED_RGBW.h"
|
||
|
CRGBW strip1[NUM_LEDS]; // FastLED with RGBW
|
||
|
CRGB *strip1B = (CRGB *) &strip1[0];
|
||
|
CRGBW strip2[NUM_LEDS]; // FastLED with RGBW
|
||
|
CRGB *strip2B = (CRGB *) &strip2[0];
|
||
|
CRGBW strip3[NUM_LEDS]; // FastLED with RGBW
|
||
|
CRGB *strip3B = (CRGB *) &strip3[0];
|
||
|
CRGBW strip4[NUM_LEDS]; // FastLED with RGBW
|
||
|
CRGB *strip4B = (CRGB *) &strip4[0];
|
||
|
#endif
|
||
|
|
||
|
void Ledpixel::begin()
|
||
|
{
|
||
|
#if neopixel
|
||
|
strip1.begin();
|
||
|
strip2.begin();
|
||
|
strip3.begin();
|
||
|
strip4.begin();
|
||
|
#else
|
||
|
FastLED.addLeds<WS2812B, PIN_STRIP1, RGB>(strip1B, getRGBWsize(NUM_LEDS));
|
||
|
FastLED.addLeds<WS2812B, PIN_STRIP2, RGB>(strip2B, getRGBWsize(NUM_LEDS));
|
||
|
FastLED.addLeds<WS2812B, PIN_STRIP3, RGB>(strip3B, getRGBWsize(NUM_LEDS));
|
||
|
FastLED.addLeds<WS2812B, PIN_STRIP4, RGB>(strip4B, getRGBWsize(NUM_LEDS));
|
||
|
for(int i=35; i>=0; i--)
|
||
|
{
|
||
|
strip1[i] = CRGBW(0,0,0,0);
|
||
|
strip2[i] = CRGBW(0,0,0,0);
|
||
|
strip3[i] = CRGBW(0,0,0,0);
|
||
|
}
|
||
|
strip4[0] = CRGBW(255,0,0,0);
|
||
|
FastLED.show();
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
void Ledpixel::refresh()
|
||
|
{
|
||
|
#if neopixel
|
||
|
strip1.show();
|
||
|
strip2.show();
|
||
|
strip3.show();
|
||
|
strip4.show();
|
||
|
#else
|
||
|
FastLED.show();
|
||
|
//delay(100);
|
||
|
#endif
|
||
|
//delay(1000);
|
||
|
}
|
||
|
|
||
|
void Ledpixel::demo_leds()
|
||
|
{
|
||
|
for(uint16_t i=0; i<NUM_LEDS; i++) {
|
||
|
#if neopixel
|
||
|
strip1.setPixelColor(i, strip1.Color(255, 0, 0, 0));
|
||
|
strip2.setPixelColor(i, strip2.Color(255, 0, 0, 0));
|
||
|
strip3.setPixelColor(i, strip3.Color(255, 0, 0, 0));
|
||
|
strip4.setPixelColor(i, strip4.Color(255, 0, 0, 0));
|
||
|
#else
|
||
|
strip1[i] = CRGBW(255,0,0,0);
|
||
|
strip2[i] = CRGBW(255,0,0,0);
|
||
|
strip3[i] = CRGBW(255,0,0,0);
|
||
|
strip4[i] = CRGBW(255,0,0,0);
|
||
|
#endif
|
||
|
}
|
||
|
delay(1000);
|
||
|
refresh();
|
||
|
for(uint16_t i=0; i<NUM_LEDS; i++) {
|
||
|
#if neopixel
|
||
|
strip1.setPixelColor(i, strip1.Color(0, 255, 0, 0));
|
||
|
strip2.setPixelColor(i, strip2.Color(0, 255, 0, 0));
|
||
|
strip3.setPixelColor(i, strip3.Color(0, 255, 0, 0));
|
||
|
strip4.setPixelColor(i, strip4.Color(0, 255, 0, 0));
|
||
|
#else
|
||
|
strip1[i] = CRGBW(0,255,0,0);
|
||
|
strip2[i] = CRGBW(0,255,0,0);
|
||
|
strip3[i] = CRGBW(0,255,0,0);
|
||
|
strip4[i] = CRGBW(0,255,0,0);
|
||
|
#endif
|
||
|
}
|
||
|
delay(1000);
|
||
|
refresh();
|
||
|
for(uint16_t i=0; i<NUM_LEDS; i++) {
|
||
|
#if neopixel
|
||
|
strip1.setPixelColor(i, strip1.Color(0, 0, 255, 0));
|
||
|
strip2.setPixelColor(i, strip2.Color(0, 0, 255, 0));
|
||
|
strip3.setPixelColor(i, strip3.Color(0, 0, 255, 0));
|
||
|
strip4.setPixelColor(i, strip4.Color(0, 0, 255, 0));
|
||
|
#else
|
||
|
strip1[i] = CRGBW(0,0,255,0);
|
||
|
strip2[i] = CRGBW(0,0,255,0);
|
||
|
strip3[i] = CRGBW(0,0,255,0);
|
||
|
strip4[i] = CRGBW(0,0,255,0);
|
||
|
#endif
|
||
|
}
|
||
|
delay(1000);
|
||
|
refresh();
|
||
|
for(uint16_t i=0; i<NUM_LEDS; i++) {
|
||
|
#if neopixel
|
||
|
strip1.setPixelColor(i, strip1.Color(0, 0, 0, 255));
|
||
|
strip2.setPixelColor(i, strip2.Color(0, 0, 0, 255));
|
||
|
strip3.setPixelColor(i, strip3.Color(0, 0, 0, 255));
|
||
|
strip4.setPixelColor(i, strip4.Color(0, 0, 0, 255));
|
||
|
#else
|
||
|
strip1[i] = CRGBW(0,0,0,255);
|
||
|
strip2[i] = CRGBW(0,0,0,255);
|
||
|
strip3[i] = CRGBW(0,0,0,255);
|
||
|
strip4[i] = CRGBW(0,0,0,255);
|
||
|
#endif
|
||
|
}
|
||
|
delay(1000);
|
||
|
refresh();
|
||
|
}
|
||
|
|
||
|
void Ledpixel::select(int mode)
|
||
|
{
|
||
|
#if neopixel
|
||
|
#else
|
||
|
switch (mode) {
|
||
|
case 0:
|
||
|
strip4[0] = CRGBW(255,0,0,0);
|
||
|
break;
|
||
|
case 1:
|
||
|
strip4[0] = CRGBW(0,255,0,0);
|
||
|
break;
|
||
|
case 2:
|
||
|
strip4[0] = CRGBW(0,0,255,0);
|
||
|
break;
|
||
|
case 3:
|
||
|
strip4[0] = CRGBW(255,255,0,0);
|
||
|
break;
|
||
|
case 4:
|
||
|
strip4[0] = CRGBW(255,0,255,0);
|
||
|
break;
|
||
|
case 5:
|
||
|
strip4[0] = CRGBW(0,0,0,255);
|
||
|
break;
|
||
|
}
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
bool status_strip[NUM_LEDS][4];
|
||
|
|
||
|
void Ledpixel::st_strip(int led, bool red, bool green, bool blue, bool white)
|
||
|
{
|
||
|
status_strip[led][0]=red;
|
||
|
status_strip[led][1]=green;
|
||
|
status_strip[led][2]=blue;
|
||
|
status_strip[led][3]=white;
|
||
|
#if neopixel
|
||
|
strip1.setPixelColor(led, strip1.Color(red*255,green*255,blue*255,white*255));
|
||
|
strip2.setPixelColor(led, strip2.Color(red*255,green*255,blue*255,white*255));
|
||
|
strip3.setPixelColor(led, strip3.Color(red*255,green*255,blue*255,white*255));
|
||
|
#else
|
||
|
strip1[led] = CRGBW(red*255,green*255,blue*255,white*255);
|
||
|
strip2[led] = CRGBW(red*255,green*255,blue*255,white*255);
|
||
|
strip3[led] = CRGBW(red*255,green*255,blue*255,white*255);
|
||
|
#endif
|
||
|
st_refresh = true;
|
||
|
}
|
||
|
|
||
|
void Ledpixel::mode1(int led_number)
|
||
|
{
|
||
|
if (led_number<=36)
|
||
|
{
|
||
|
for(int i=35; i>=(36-led_number); i--)
|
||
|
st_strip( i, 1, 0, 0, 0);
|
||
|
}
|
||
|
else if (led_number<=72)
|
||
|
{
|
||
|
for(int i=35; i>=(72-led_number); i--)
|
||
|
st_strip( i, 0, 1, 0, 0);
|
||
|
}
|
||
|
else if (led_number<=108)
|
||
|
{
|
||
|
for(int i=35; i>=(108-led_number); i--)
|
||
|
st_strip( i, 0, 0, 1, 0);
|
||
|
}
|
||
|
else if (led_number<=144)
|
||
|
{
|
||
|
for(int i=35; i>=(144-led_number); i--)
|
||
|
st_strip( i, 0, 0, 0, 1);
|
||
|
}
|
||
|
else if (led_number<=180)
|
||
|
{
|
||
|
for(int i=35; i>=(180-led_number); i--)
|
||
|
st_strip( i, 1, 1, 0, 0);
|
||
|
}
|
||
|
else if (led_number<=216)
|
||
|
{
|
||
|
for(int i=35; i>=(216-led_number); i--)
|
||
|
st_strip( i, 0, 1, 1, 0);
|
||
|
}
|
||
|
else if (led_number<=252)
|
||
|
{
|
||
|
for(int i=35; i>=(252-led_number); i--)
|
||
|
st_strip( i, 1, 0, 1, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int led_intensity_ant=0;
|
||
|
|
||
|
void Ledpixel::mode2(int led_intensity)
|
||
|
{
|
||
|
if (abs(led_intensity_ant-led_intensity)<50)
|
||
|
{
|
||
|
led_intensity_ant=led_intensity;
|
||
|
for(int i=0; i<NUM_LEDS; i++)
|
||
|
{
|
||
|
#if neopixel
|
||
|
strip1.setPixelColor(i, strip1.Color(status_strip[i][0]*led_intensity, status_strip[i][1]*led_intensity, status_strip[i][2]*led_intensity, status_strip[i][3]*led_intensity));
|
||
|
strip2.setPixelColor(i, strip2.Color(status_strip[i][0]*led_intensity, status_strip[i][1]*led_intensity, status_strip[i][2]*led_intensity, status_strip[i][3]*led_intensity));
|
||
|
strip3.setPixelColor(i, strip3.Color(status_strip[i][0]*led_intensity, status_strip[i][1]*led_intensity, status_strip[i][2]*led_intensity, status_strip[i][3]*led_intensity));
|
||
|
#else
|
||
|
strip1[i] = CRGBW(status_strip[i][0]*led_intensity, status_strip[i][1]*led_intensity, status_strip[i][2]*led_intensity, status_strip[i][3]*led_intensity);
|
||
|
strip2[i] = CRGBW(status_strip[i][0]*led_intensity, status_strip[i][1]*led_intensity, status_strip[i][2]*led_intensity, status_strip[i][3]*led_intensity);
|
||
|
strip3[i] = CRGBW(status_strip[i][0]*led_intensity, status_strip[i][1]*led_intensity, status_strip[i][2]*led_intensity, status_strip[i][3]*led_intensity);
|
||
|
#endif
|
||
|
}
|
||
|
st_refresh = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
unsigned long time_refresh_led = millis();
|
||
|
|
||
|
void Ledpixel::refresh_leds()
|
||
|
{
|
||
|
if (((millis()-time_refresh_led)>20)&& st_refresh)
|
||
|
{
|
||
|
refresh();
|
||
|
time_refresh_led = millis();
|
||
|
st_refresh = false;
|
||
|
}
|
||
|
}
|