putting bac the led strip library

This commit is contained in:
ghassan committed 2020-03-22 00:58:38 +03:00
1 parent 9f86415b9a
commit 84539fecfc
3 files changed
+278 -314

No files matched your search

+24 -12
View File
@@ -39,8 +39,15 @@
#include <Button.h>
#include <TimeTrigger.h>
#include <ArduinoJson.h>
#include <NeoPixelBus.h>
#include <BluetoothSerial.h>
#include <Adafruit_NeoPixel.h>
//======================================================
// OVER THE AIR PROGRAMMING
//======================================================
// #include <WiFi.h>
// #include <ESPmDNS.h>
// #include <WiFiUdp.h>
// #include <ArduinoOTA.h>
//======================================================
// PUBLIC VARIABLES
//======================================================
@@ -90,7 +97,7 @@
#define POWER_SETUP pinMode(POWER_PIN, OUTPUT)
#define POWER_OFF digitalWrite(POWER_PIN, LOW)
#define POWER_ON digitalWrite(POWER_PIN, HIGH)
TimeTrigger POWER_PRESS(4000); // The Interval In mSeconds
TimeTrigger POWER_PRESS(4000); // The Interval In mSeconds
//------------------------------------------------------
// Piezo Transducer
//------------------------------------------------------
@@ -114,10 +121,12 @@
//------------------------------------------------------
// Neo Pixel LED Strip
//------------------------------------------------------
#define PIXEL_COUNT 21 // make sure to set this to the number of pixels in your strip
#define PIXEL_PIN 26 // make sure to set this to the correct pin, ignored for Esp8266
// three element pixels, in different order and speeds
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> PIXEL_STRIP(PIXEL_COUNT, PIXEL_PIN);
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1
#define NUMPIXELS 16 // Number Of LED's
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
//------------------------------------------------------
// JSON Object & Memory
//------------------------------------------------------
@@ -157,12 +166,8 @@
// Power Hold
POWER_SETUP;
POWER_ON;
// Turn On Booster
BOOST_SETUP;
BOOST_OFF;
// Charging Status Pin
// Charging Status Pin Setup
STAT_SETUP;
// I2C Module & OLED
@@ -171,6 +176,13 @@
OLED_INIT();
OLED_CLEAR();
OLED_SHOW();
// IF Charger Connected Dont Allow Any One To Play
// Turn On Booster
BOOST_SETUP;
BOOST_ON;
// Start Buttons Function
BTN_PREVIOUS.begin();
+247 -295
View File
@@ -1,295 +1,247 @@
////======================================================
//// NEO PIXEL LED STRIP
////======================================================
//// PUBLIC DEFINITIONS
////------------------------------------------------------
// #define BETWEEN_FADE 15
// #define FADE_RATE 15
// #define BLINK_RATE 250
// #define ColorSaturation 128
////------------------------------------------------------
//// PURE COLOR
////------------------------------------------------------
// RgbColor red(colorSaturation, 0, 0);
// RgbColor green(0, colorSaturation, 0);
// RgbColor blue(0, 0, colorSaturation);
// RgbColor white(colorSaturation);
// RgbColor black(0);
////------------------------------------------------------
//// HSL COLOR
////------------------------------------------------------
// HslColor hslRed(red);
// HslColor hslGreen(green);
// HslColor hslBlue(blue);
// HslColor hslWhite(white);
// HslColor hslBlack(black);
////------------------------------------------------------
//// Clearing The LED Strip
////------------------------------------------------------
// void LED_CLEAR()
// {
// // Make Sure Boost Is On
// BOOST_ON;
//
// // Clear The Strip Color
// PIXEL_STRIP.clear();
//
// // Show On LED Strip
// LED_SHOW();
// }
////------------------------------------------------------
//// DISPLAY ON STRIP
////------------------------------------------------------
// void LED_SHOW()
// {
// // Make Sure Boost Is On
// BOOST_ON;
//
// // Pass It To The LED Strip
// PIXEL_STRIP.show();
// }
////------------------------------------------------------
//// Set LED Brightness
////------------------------------------------------------
// void LED_SET_BRIGHTNESS(uint8_t Value)
// {
// // Make Sure Boost Is On
// BOOST_ON;
//
// // Set The Brightness
// PIXEL_STRIP.setBrightness(Value);
// }
////------------------------------------------------------
//// Set LED Color
////------------------------------------------------------
// void LED_SET_COLOR(uint8_t R, uint8_t G, uint8_t B, uint8_t Intensity)
// {
// // Make Sure Boost Is On
// BOOST_ON;
//
// // Set Intensity
// LED_SET_BRIGHTNESS(Intensity);
//
// // Loop
// for(int i=0; i<NUM_PIXELS; i++) {
// PIXEL_STRIP.setPixelColor(i, PIXEL_STRIP.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 Boost Is On
// BOOST_ON;
//
// // Work Loop
// for(uint16_t i=0; i<NUM_PIXELS; i++)
// {
// PIXEL_STRIP.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 Boost Is On
// BOOST_ON;
//
// // 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< PIXEL_STRIP.numPixels(); i++)
// {
// PIXEL_STRIP.setPixelColor(i, LED_COLOR_WHEEL(((i * 256 / PIXEL_STRIP.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 Boost Is On
// BOOST_ON;
//
// // Wheel Sequance
// WHEELPos = 255 - WHEELPos;
//
// if(WHEELPos < 85)
// {
// return PIXEL_STRIP.Color(255 - WHEELPos * 3, 0, WHEELPos * 3);
// }
// if(WHEELPos < 170)
// {
// WHEELPos -= 85;
// return PIXEL_STRIP.Color(0, WHEELPos * 3, 255 - WHEELPos * 3);
// }
// WHEELPos -= 170;
// return PIXEL_STRIP.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 Boost Is On
// BOOST_ON;
//
// // Loop For Fade
// for(int i=0; i<=255; i++)
// {
// PIXEL_STRIP.setBrightness(i);
// for(int j=0; j<NUM_PIXELS; j++)
// {
// PIXEL_STRIP.setPixelColor(j, PIXEL_STRIP.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 Boost Is On
// BOOST_ON;
//
// // Loop For Fade Out
// for(int i=255; i>=0; i--)
// {
// PIXEL_STRIP.setBrightness(i);
// for(int j=0; j<NUM_PIXELS; j++)
// {
// PIXEL_STRIP.setPixelColor(j, PIXEL_STRIP.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 Boost Is On
// BOOST_ON;
//
// 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()
// {
// BOOST_ON;
// LED_SET_BRIGHTNESS(255);
// LED_COLOR_WIPE(PIXEL_STRIP.Color(255, 255, 255), 30); // White
// delay(250);
// LED_COLOR_WIPE(PIXEL_STRIP.Color(255, 0, 0), 30); // Red
// delay(250);
// LED_FADEOUT(255, 0, 0);
// }
////------------------------------------------------------
//// DISPLAY COLOMBIA FLAG
////------------------------------------------------------
// void LED_COLOMBIA_FLAG()
// {
// BOOST_ON;
// LED_SET_BRIGHTNESS(255);
// LED_COLOR_WIPE(PIXEL_STRIP.Color(255, 255, 0), 30); // Yellow
// delay(250);
// LED_COLOR_WIPE(PIXEL_STRIP.Color(0, 0, 255), 30); // Blue
// delay(250);
// LED_COLOR_WIPE(PIXEL_STRIP.Color(255, 0, 0), 30); // Red
// delay(250);
// LED_FADEOUT(255, 0, 0);
// }
//======================================================
// NEO PIXEL LED STRIP
//======================================================
// PUBLIC DEFINITIONS
//------------------------------------------------------
#define BETWEEN_FADE 15
#define FADE_RATE 15
#define BLINK_RATE 250
#define ColorSaturation 128
//------------------------------------------------------
// Clearing The LED Strip
//------------------------------------------------------
void LED_CLEAR()
{
// Clear The Strip Color
PIXEL_STRIP.clear();
// Show On LED Strip
LED_SHOW();
}
//------------------------------------------------------
// DISPLAY ON STRIP
//------------------------------------------------------
void LED_SHOW()
{
// Pass It To The LED Strip
PIXEL_STRIP.show();
}
//------------------------------------------------------
// Set LED Brightness
//------------------------------------------------------
void LED_SET_BRIGHTNESS(uint8_t Value)
{
// Set The Brightness
PIXEL_STRIP.setBrightness(Value);
}
//------------------------------------------------------
// Set LED Color
//------------------------------------------------------
void LED_SET_COLOR(uint8_t R, uint8_t G, uint8_t B, uint8_t Intensity)
{
// Set Intensity
LED_SET_BRIGHTNESS(Intensity);
// Loop
for(int i=0; i<NUM_PIXELS; i++) {
PIXEL_STRIP.setPixelColor(i, PIXEL_STRIP.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)
{
// Work Loop
for(uint16_t i=0; i<NUM_PIXELS; i++)
{
PIXEL_STRIP.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)
{
// 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< PIXEL_STRIP.numPixels(); i++)
{
PIXEL_STRIP.setPixelColor(i, LED_COLOR_WHEEL(((i * 256 / PIXEL_STRIP.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)
{
// Wheel Sequance
WHEELPos = 255 - WHEELPos;
if(WHEELPos < 85)
{
return PIXEL_STRIP.Color(255 - WHEELPos * 3, 0, WHEELPos * 3);
}
if(WHEELPos < 170)
{
WHEELPos -= 85;
return PIXEL_STRIP.Color(0, WHEELPos * 3, 255 - WHEELPos * 3);
}
WHEELPos -= 170;
return PIXEL_STRIP.Color(WHEELPos * 3, 255 - WHEELPos * 3, 0);
}
//------------------------------------------------------
// Set Color Fade In
//------------------------------------------------------
void LED_FADEIN(uint8_t R, uint8_t G, uint8_t B)
{
// Loop For Fade
for(int i=0; i<=255; i++)
{
PIXEL_STRIP.setBrightness(i);
for(int j=0; j<NUM_PIXELS; j++)
{
PIXEL_STRIP.setPixelColor(j, PIXEL_STRIP.Color(R, G, B));
}
LED_SHOW();
delay(4);
}
}
//------------------------------------------------------
// Set Color Fade Out
//------------------------------------------------------
void LED_FADEOUT(uint8_t R, uint8_t G, uint8_t B)
{
// Loop For Fade Out
for(int i=255; i>=0; i--)
{
PIXEL_STRIP.setBrightness(i);
for(int j=0; j<NUM_PIXELS; j++)
{
PIXEL_STRIP.setPixelColor(j, PIXEL_STRIP.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)
{
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()
{
LED_SET_BRIGHTNESS(255);
LED_COLOR_WIPE(PIXEL_STRIP.Color(255, 255, 255), 30); // White
delay(250);
LED_COLOR_WIPE(PIXEL_STRIP.Color(255, 0, 0), 30); // Red
delay(250);
LED_FADEOUT(255, 0, 0);
}
//------------------------------------------------------
// DISPLAY COLOMBIA FLAG
//------------------------------------------------------
void LED_COLOMBIA_FLAG()
{
LED_SET_BRIGHTNESS(255);
LED_COLOR_WIPE(PIXEL_STRIP.Color(255, 255, 0), 30); // Yellow
delay(250);
LED_COLOR_WIPE(PIXEL_STRIP.Color(0, 0, 255), 30); // Blue
delay(250);
LED_COLOR_WIPE(PIXEL_STRIP.Color(255, 0, 0), 30); // Red
delay(250);
LED_FADEOUT(255, 0, 0);
}