2020-05-25 04:56:48 +03:00

346 lines
7.7 KiB
C++

#define BETWEEN_FADE 15
#define FADE_RATE 15
#define BLINK_RATE 250
//------------------------------------------------------
// Clearing The LED Strip
//------------------------------------------------------
void LED_CLEAR()
{
// Make Sure Of The Core
#ifdef ESP32
LED_BOOST_CHK();
#endif
// Clear The Strip Color
pixels.clear();
// Make Sure Of The Core
#ifdef ESP32
delay(1);
#endif
// Show On LED Strip
LED_SHOW();
// Make Sure Of The Core
#ifdef ESP32
BOOST_OFF;
#endif
}
//------------------------------------------------------
// DISPLAY ON STRIP
//------------------------------------------------------
void LED_SHOW()
{
// Make Sure Of The Core
#ifdef ESP32
LED_BOOST_CHK();
#endif
// Pass It To The LED Strip
pixels.show();
}
//------------------------------------------------------
// Set LED Brightness
//------------------------------------------------------
void LED_SET_BRIGHTNESS(uint8_t Value)
{
// Make Sure Of The Core
#ifdef ESP32
LED_BOOST_CHK();
#endif
// Set The Brightness
pixels.setBrightness(Value);
}
//------------------------------------------------------
// Set LED Color
//------------------------------------------------------
void LED_SET_COLOR(uint8_t R, uint8_t G, uint8_t B, uint8_t Intensity)
{
// Make Sure Of The Core
#ifdef ESP32
LED_BOOST_CHK();
#endif
// Set Intensity
LED_SET_BRIGHTNESS(Intensity);
// Loop
for(int i=0; i<NUM_PIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(R, G, B));
}
// Show The Colors On LED Strip
LED_SHOW();
}
//------------------------------------------------------
// BLINK
//------------------------------------------------------
void LED_BLINK(uint8_t R, uint8_t G, uint8_t B, int Times)
{
for(int i=0; i<Times; i++)
{
LED_SET_COLOR(R, G, B, 255);
delay(BLINK_RATE);
LED_CLEAR();
delay(BLINK_RATE);
}
}
//------------------------------------------------------
// COLOR WHIPE
//------------------------------------------------------
// Fill the dots one after the other with a color
void LED_COLOR_WIPE(uint32_t c, uint8_t wait)
{
// Make Sure Of The Core
#ifdef ESP32
LED_BOOST_CHK();
#endif
// Work Loop
for(uint16_t i=0; i<NUM_PIXELS; i++)
{
pixels.setPixelColor(i, c);
LED_SHOW();
delay(wait);
}
}
//------------------------------------------------------
// END GAME LIGHTING SIGNAL
//------------------------------------------------------
// Slightly different, this makes the rainbow equally distributed throughout
void LED_RAINBOW_CYCLE(uint8_t wait)
{
// Make Sure Of The Core
#ifdef ESP32
LED_BOOST_CHK();
#endif
// Loop Variables
uint16_t i, j;
// The Loop
for(j=0; j<256*5; j++)
{
// 5 cycles of all colors on WHEEL
for(i=0; i< pixels.numPixels(); i++)
{
pixels.setPixelColor(i, LED_COLOR_WHEEL(((i * 256 / pixels.numPixels()) + j) & 255));
}
LED_SHOW();
delay(wait);
}
}
//------------------------------------------------------
// END GAME LIGHTING SIGNAL
//------------------------------------------------------
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t LED_COLOR_WHEEL(byte WHEELPos)
{
// Make Sure Of The Core
#ifdef ESP32
LED_BOOST_CHK();
#endif
// Wheel Sequance
WHEELPos = 255 - WHEELPos;
if(WHEELPos < 85)
{
return pixels.Color(255 - WHEELPos * 3, 0, WHEELPos * 3);
}
if(WHEELPos < 170)
{
WHEELPos -= 85;
return pixels.Color(0, WHEELPos * 3, 255 - WHEELPos * 3);
}
WHEELPos -= 170;
return pixels.Color(WHEELPos * 3, 255 - WHEELPos * 3, 0);
}
//------------------------------------------------------
// Set Color Fade In
//------------------------------------------------------
void LED_FADEIN(uint8_t R, uint8_t G, uint8_t B)
{
// Make Sure Of The Core
#ifdef ESP32
LED_BOOST_CHK();
#endif
// Loop For Fade
for(int i=0; i<=255; i++)
{
pixels.setBrightness(i);
for(int j=0; j<NUM_PIXELS; j++)
{
pixels.setPixelColor(j, pixels.Color(R, G, B));
}
LED_SHOW();
delay(4);
}
}
//------------------------------------------------------
// Set Color Fade Out
//------------------------------------------------------
void LED_FADEOUT(uint8_t R, uint8_t G, uint8_t B)
{
// Make Sure Of The Core
#ifdef ESP32
LED_BOOST_CHK();
#endif
// Loop For Fade Out
for(int i=255; i>=0; i--)
{
pixels.setBrightness(i);
for(int j=0; j<NUM_PIXELS; j++)
{
pixels.setPixelColor(j, pixels.Color(R, G, B));
}
LED_SHOW();
delay(4);
}
}
//------------------------------------------------------
// Set LED Color Cross Fade
//------------------------------------------------------
void LED_CROSS_FADE(uint8_t R, uint8_t G, uint8_t B, unsigned int Times)
{
// Make Sure Of The Core
#ifdef ESP32
LED_BOOST_CHK();
#endif
for(int i=0; i<Times; i++)
{
LED_FADEIN(R, G, B);
LED_FADEOUT(R, G, B);
delay(BETWEEN_FADE);
}
}
//------------------------------------------------------
// REACTION GAME START LED SIGNAL
//------------------------------------------------------
void LED_SIGNAL_START()
{
// Cross Fade White Color To Get ready 3 Times
LED_CROSS_FADE(255, 255, 255, 3);
// Set Strip Color Green
LED_SET_COLOR(0, 255, 0, 255);
}
//------------------------------------------------------
// REACTION GAME END SINGNAL LED SIGNAL
//------------------------------------------------------
void LED_SIGNAL_END()
{
// Blink Red Twice
LED_BLINK(255, 0, 0, 2);
// Fade The Red Color To Nothing
LED_FADEOUT(255, 0, 0);
}
//------------------------------------------------------
// REACTION GAME START LED CELEBRATION
//------------------------------------------------------
void LED_SIGNAL_CELEBRATION()
{
// Display Rainbow Twice
LED_RAINBOW_CYCLE(2);
// Grean Light OUT
LED_FADEOUT(0, 255, 0);
}
//------------------------------------------------------
// REACTION GAME RESET LED SIGNAL
//------------------------------------------------------
void LED_SIGNAL_RESET()
{
// Light Bright Blue
LED_BLINK(0, 0, 255, 2);
// Wait For 1/4 Second
delay(250);
// Fade Out The Blue
LED_SET_COLOR(0, 255, 0, 255);
// Set Strip Color Green
LED_SET_COLOR(0, 255, 0, 255);
}
//------------------------------------------------------
// DISPLAY BAHRAIN FLAG
//------------------------------------------------------
void LED_BAHRAIN_FLAG()
{
// Make Sure Of The Core
#ifdef ESP32
LED_BOOST_CHK();
#endif
LED_SET_BRIGHTNESS(255);
LED_COLOR_WIPE(pixels.Color(255, 255, 255), 30); // White
delay(250);
LED_COLOR_WIPE(pixels.Color(255, 0, 0), 30); // Red
delay(250);
LED_FADEOUT(255, 0, 0);
}
//------------------------------------------------------
// DISPLAY COLOMBIA FLAG
//------------------------------------------------------
void LED_COLOMBIA_FLAG()
{
// Make Sure Of The Core
#ifdef ESP32
LED_BOOST_CHK();
#endif
LED_SET_BRIGHTNESS(255);
LED_COLOR_WIPE(pixels.Color(255, 255, 0), 30); // Yellow
delay(250);
LED_COLOR_WIPE(pixels.Color(0, 0, 255), 30); // Blue
delay(250);
LED_COLOR_WIPE(pixels.Color(255, 0, 0), 30); // Red
delay(250);
LED_FADEOUT(255, 0, 0);
}