Teensy 3.2 with BLE HM-10 using serial RX as an interrupt

Status
Not open for further replies.

mlimbrick

New member
Hello,

I am trying to figure out how best to take the code below using a push button as an interrupt and instead use RX from Bluetooth.

https://www.tweaking4all.com/hardware/arduino/arduino-all-ledstrip-effects-in-one/

The code above works as I am able to press the button and toggle between 18 different patterns (cases). With Bluetooth, I would like to be able to do the same thing, but send different ASCII characters for different cases, ideally to support 3 character in length. i.e. 000 - 999. Any help would be greatly appreciated!

Below is what I was working on
==============================================================
/*
Base code:
https://www.tweaking4all.com/hardware/arduino/arduino-all-ledstrip-effects-in-one/

Works with Teensy 3.2 to toggle all patterns with push button on all 4 strips 1-17-20
// HM-10_Teensy_comm_test works recieving input from BLE
// Need to figure out how to take a BLE signal as serial input to perform a function.
*/
#include <SoftwareSerial.h> // Library for serial comm to another device (HM-10)
#include <Adafruit_NeoPixel.h> // Library for LED functions
#include <EEPROM.h> // Library to write current state to EEPROM


#define SCB_AIRCR (*(volatile uint32_t *)0xE000ED0C) // Application Interrupt and Reset Control location
// https://www.reddit.com/r/Teensy/comments/7r19uk/reset_and_reboot_teensy_lc_via_code/

#define NUM_LEDS 74
#define PIN_A 4
#define PIN_B 5
#define PIN_C 6
#define PIN_D 7
#define MIRROR 37 // set to 1/2 of the LED count - For "Fire" pattern
#define BTserial Serial1

// http://www.martyncurrey.com/hm-10-bluetooth-4ble-modules/
// SoftwareSerial BTserial(0, 1); // (RX, TX) - Defines "BTserial" as the name of the serial connection to another board (HM-10) and defines the serial pins used
// Connect HM10 Teensy 3.2
// Pin 1/TXD to Pin 0 RX
// Pin 2/RXD to Voltage divider to Pin 1 TX

char c=' '; // is a data type that holds one character (letter, number, etc.) of data

// Defines 4 different strips that are all Neopixel compatible.
Adafruit_NeoPixel strip_A = Adafruit_NeoPixel(NUM_LEDS, PIN_A, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip_B = Adafruit_NeoPixel(NUM_LEDS, PIN_B, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip_C = Adafruit_NeoPixel(NUM_LEDS, PIN_C, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip_D = Adafruit_NeoPixel(NUM_LEDS, PIN_D, NEO_GRB + NEO_KHZ800);

#define BUTTON 2
byte selectedEffect=0;

//=====================================================================================================

void setup()
{
// Turns on function for each strip to be used
strip_A.begin();
strip_B.begin();
strip_C.begin();
strip_D.begin();

// Sends signal to all 4 strips to show nothing (clear them)
strip_A.show(); // Initialize all pixels to 'off'
strip_B.show(); // Initialize all pixels to 'off'
strip_C.show(); // Initialize all pixels to 'off'
strip_D.show(); // Initialize all pixels to 'off'

pinMode(2,INPUT_PULLUP); // Sets pin 2 to use the internal pull-up resistor
attachInterrupt (digitalPinToInterrupt (BUTTON), changeEffect, CHANGE); // States the interupt being used here is a digital pin - Button being pressed and to "change" the effect

// Setup USB serial monitor and serial comms to HM-10
while (!Serial);
delay(500);//test

Serial.begin(9600); // Turns on serial monitor from Teensy to PC with USB port
Serial.println("Sketch: "); Serial.println(__FILE__);
Serial.println("Uploaded: "); Serial.println(__DATE__);
Serial.println(" ");
delay(1000);

BTserial.begin(9600); // Turns on serial connetion from Teensy to HM-10
Serial.println("BTserial started at 9600");
Serial.println(" ");
delay(1000);
BTserial.print("AT+NAMELeviticus" ); // Changes the name broadcast by the HM-10 to "Leviticus"
}

//=====================================================================================================

// *** REPLACE FROM HERE ***
void loop() {
EEPROM.get(0,selectedEffect);

if(selectedEffect>18) {
selectedEffect=0; // start on case 0
EEPROM.put(0,0);
}

int incomingByte;

if (Serial.available() > 0) {
incomingByte = Serial.read();
Serial.print("USB received: ");
Serial.println(incomingByte, DEC);
BTserial.print("USB received:");
BTserial.println(incomingByte, DEC);
}
if (BTserial.available() > 0) {
incomingByte = BTserial.read();
Serial.print("UART received: ");
Serial.println(incomingByte, DEC);
BTserial.print("UART received:");
BTserial.println(incomingByte, DEC);
}

switch(selectedEffect) {

case 0 : {
// RGBLoop - no parameters
RGBLoop();
break;
}

case 1 : {
// FadeInOut - Color (red, green. blue)
FadeInOut(0xff, 0x00, 0x00); // red
FadeInOut(0xff, 0xff, 0xff); // white
FadeInOut(0x00, 0x00, 0xff); // blue
break;
}

case 2 : {
// Strobe - Color (red, green, blue), number of flashes, flash speed, end pause
Strobe(0xff, 0xff, 0xff, 10, 50, 1000);
break;
}

case 3 : {
// HalloweenEyes - Color (red, green, blue), Size of eye, space between eyes, fade (true/false), steps, fade delay, end pause
HalloweenEyes(0xff, 0x00, 0x00,
1, 4,
true, random(5,50), random(50,150),
random(1000, 10000));
HalloweenEyes(0xff, 0x00, 0x00,
1, 4,
true, random(5,50), random(50,150),
random(1000, 10000));
break;
}

case 4 : {
// CylonBounce - Color (red, green, blue), eye size, speed delay, end pause
CylonBounce(0xff, 0x00, 0x00, 4, 10, 50);
break;
}

case 5 : {
// NewKITT - Color (red, green, blue), eye size, speed delay, end pause
NewKITT(0xff, 0x00, 0x00, 8, 10, 50);
break;
}

case 6 : {
// Twinkle - Color (red, green, blue), count, speed delay, only one twinkle (true/false)
Twinkle(0xff, 0x00, 0x00, 10, 100, false);
break;
}

case 7 : {
// TwinkleRandom - twinkle count, speed delay, only one (true/false)
TwinkleRandom(20, 100, false);
break;
}

case 8 : {
// Sparkle - Color (red, green, blue), speed delay
Sparkle(0xff, 0xff, 0xff, 0);
break;
}

case 9 : {
// SnowSparkle - Color (red, green, blue), sparkle delay, speed delay
SnowSparkle(0x10, 0x10, 0x10, 20, random(100,1000));
break;
}

case 10 : {
// Running Lights - Color (red, green, blue), wave dealy
RunningLights(0xff,0x00,0x00, 50); // red
RunningLights(0xff,0xff,0xff, 50); // white
RunningLights(0x00,0x00,0xff, 50); // blue
break;
}

case 11 : {
// colorWipe - Color (red, green, blue), speed delay
colorWipe(0x00,0xff,0x00, 50);
colorWipe(0x00,0x00,0x00, 50);
break;
}

case 12 : {
// rainbowCycle - speed delay
rainbowCycle(20);
break;
}

case 13 : {
// theatherChase - Color (red, green, blue), speed delay
theaterChase(0xff,0,0,50);
break;
}

case 14 : {
// theaterChaseRainbow - Speed delay
theaterChaseRainbow(50);
break;
}

case 15 : {
// Fire - Cooling rate, Sparking rate, speed delay
Fire(115,120,15,1);
break;
}


// simple bouncingBalls not included, since BouncingColoredBalls can perform this as well as shown below
// BouncingColoredBalls - Number of balls, color (red, green, blue) array, continuous
// CAUTION: If set to continuous then this effect will never stop!!!

case 16 : {
// mimic BouncingBalls
byte onecolor[1][3] = { {0xff, 0x00, 0x00} };
BouncingColoredBalls(1, onecolor, false);
break;
}

case 17 : {
// multiple colored balls
byte colors[5][3] = { {0xff, 0x00, 0x00}, // red
{0x00, 0xff, 0x00}, // green
{0x00, 0x00, 0xff}, // blue
{0xff, 0xff, 0xff}, // white
{0xff, 0xff, 0x00}, // yellow
};
BouncingColoredBalls(5, colors, false);
break;
}

case 18 : {
// meteorRain - Color (red, green, blue), meteor size, trail decay, random trail decay (true/false), speed delay
meteorRain(0xff,0xff,0xff,10, 64, true, 30);
break;
}
}
}

//=====================================================================================================

void changeEffect() {
// if (digitalRead (BUTTON) == HIGH) { // original

// Read from the Bluetooth module and check toggle is sent
if (BTserial.available())
{
c = BTserial.read();
Serial.write(c);

// need to read something and wite what to change. Maybe test sending "100" to go to the next case (++)
// 49 is the ascii code for "1"
// 48 is the ascii code for "0"
// if (c==49) { digitalWrite(LEDpin,HIGH); } i.e.

if (c==49) { selectedEffect++; }
Serial.println(c);
}

// selectedEffect++; // ++ means to increment by 1
EEPROM.put(0, selectedEffect);
SCB_AIRCR = 0x05FA0004; //write value for restart;
}

//=====================================================================================================

// *************************
// ** LEDEffect Functions **
// *************************

void RGBLoop(){
for(int j = 0; j < 3; j++ ) {
// Fade IN
for(int k = 0; k < 256; k++) {
switch(j) {
case 0: setAll(k,0,0); break;
case 1: setAll(0,k,0); break;
case 2: setAll(0,0,k); break;
}
showStrip();
delay(3);
}
// Fade OUT
for(int k = 255; k >= 0; k--) {
switch(j) {
case 0: setAll(k,0,0); break;
case 1: setAll(0,k,0); break;
case 2: setAll(0,0,k); break;
}
showStrip();
delay(3);
}
}
}

void FadeInOut(byte red, byte green, byte blue){
float r, g, b;

for(int k = 0; k < 256; k=k+1) {
r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll(r,g,b);
showStrip();
}

for(int k = 255; k >= 0; k=k-2) {
r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll(r,g,b);
showStrip();
}
}

void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
for(int j = 0; j < StrobeCount; j++) {
setAll(red,green,blue);
showStrip();
delay(FlashDelay);
setAll(0,0,0);
showStrip();
delay(FlashDelay);
}

delay(EndPause);
}

void HalloweenEyes(byte red, byte green, byte blue,
int EyeWidth, int EyeSpace,
boolean Fade, int Steps, int FadeDelay,
int EndPause){
randomSeed(analogRead(0));

int i;
int StartPoint = random( 0, NUM_LEDS - (2*EyeWidth) - EyeSpace );
int Start2ndEye = StartPoint + EyeWidth + EyeSpace;

for(i = 0; i < EyeWidth; i++) {
setPixel(StartPoint + i, red, green, blue);
setPixel(Start2ndEye + i, red, green, blue);
}

showStrip();

if(Fade==true) {
float r, g, b;

for(int j = Steps; j >= 0; j--) {
r = j*(red/Steps);
g = j*(green/Steps);
b = j*(blue/Steps);

for(i = 0; i < EyeWidth; i++) {
setPixel(StartPoint + i, r, g, b);
setPixel(Start2ndEye + i, r, g, b);
}

showStrip();
delay(FadeDelay);
}
}

setAll(0,0,0); // Set all black

delay(EndPause);
}

void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){

for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
setAll(0,0,0);
setPixel(i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(i+j, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);
showStrip();
delay(SpeedDelay);
}

delay(ReturnDelay);

for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
setAll(0,0,0);
setPixel(i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(i+j, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);
showStrip();
delay(SpeedDelay);
}

delay(ReturnDelay);
}

void NewKITT(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
}

// used by NewKITT
void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for(int i =((NUM_LEDS-EyeSize)/2); i>=0; i--) {
setAll(0,0,0);

setPixel(i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(i+j, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);

setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(NUM_LEDS-i-j, red, green, blue);
}
setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);

showStrip();
delay(SpeedDelay);
}
delay(ReturnDelay);
}

// used by NewKITT
void OutsideToCenter(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for(int i = 0; i<=((NUM_LEDS-EyeSize)/2); i++) {
setAll(0,0,0);

setPixel(i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(i+j, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);

setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(NUM_LEDS-i-j, red, green, blue);
}
setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);

showStrip();
delay(SpeedDelay);
}
delay(ReturnDelay);
}

// used by NewKITT
void LeftToRight(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
setAll(0,0,0);
setPixel(i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(i+j, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);
showStrip();
delay(SpeedDelay);
}
delay(ReturnDelay);
}

// used by NewKITT
void RightToLeft(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
setAll(0,0,0);
setPixel(i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(i+j, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);
showStrip();
delay(SpeedDelay);
}
delay(ReturnDelay);
}

void Twinkle(byte red, byte green, byte blue, int Count, int SpeedDelay, boolean OnlyOne) {
setAll(0,0,0);

for (int i=0; i<Count; i++) {
setPixel(random(NUM_LEDS),red,green,blue);
showStrip();
delay(SpeedDelay);
if(OnlyOne) {
setAll(0,0,0);
}
}

delay(SpeedDelay);
}

void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne) {
setAll(0,0,0);

for (int i=0; i<Count; i++) {
setPixel(random(NUM_LEDS),random(0,255),random(0,255),random(0,255));
showStrip();
delay(SpeedDelay);
if(OnlyOne) {
setAll(0,0,0);
}
}

delay(SpeedDelay);
}

void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
int Pixel = random(NUM_LEDS);
setPixel(Pixel,red,green,blue);
showStrip();
delay(SpeedDelay);
setPixel(Pixel,0,0,0);
}

void SnowSparkle(byte red, byte green, byte blue, int SparkleDelay, int SpeedDelay) {
setAll(red,green,blue);

int Pixel = random(NUM_LEDS);
setPixel(Pixel,0xff,0xff,0xff);
showStrip();
delay(SparkleDelay);
setPixel(Pixel,red,green,blue);
showStrip();
delay(SpeedDelay);
}

void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
int Position=0;

for(int i=0; i<NUM_LEDS*2; i++)
{
Position++; // = 0; //Position + Rate;
for(int i=0; i<NUM_LEDS; i++) {
// sine wave, 3 offset waves make a rainbow!
//float level = sin(i+Position) * 127 + 128;
//setPixel(i,level,0,0);
//float level = sin(i+Position) * 127 + 128;
setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
((sin(i+Position) * 127 + 128)/255)*green,
((sin(i+Position) * 127 + 128)/255)*blue);
}

showStrip();
delay(WaveDelay);
}
}

void colorWipe(byte red, byte green, byte blue, int SpeedDelay) {
for(uint16_t i=0; i<NUM_LEDS; i++) {
setPixel(i, red, green, blue);
showStrip();
delay(SpeedDelay);
}
}

void rainbowCycle(int SpeedDelay) {
byte *c;
uint16_t i, j;

for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< NUM_LEDS; i++) {
c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
setPixel(i, *c, *(c+1), *(c+2));
}
showStrip();
delay(SpeedDelay);
}
}

// used by rainbowCycle and theaterChaseRainbow
byte * Wheel(byte WheelPos) {
static byte c[3];

if(WheelPos < 85) {
c[0]=WheelPos * 3;
c[1]=255 - WheelPos * 3;
c[2]=0;
} else if(WheelPos < 170) {
WheelPos -= 85;
c[0]=255 - WheelPos * 3;
c[1]=0;
c[2]=WheelPos * 3;
} else {
WheelPos -= 170;
c[0]=0;
c[1]=WheelPos * 3;
c[2]=255 - WheelPos * 3;
}

return c;
}

void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < NUM_LEDS; i=i+3) {
setPixel(i+q, red, green, blue); //turn every third pixel on
}
showStrip();

delay(SpeedDelay);

for (int i=0; i < NUM_LEDS; i=i+3) {
setPixel(i+q, 0,0,0); //turn every third pixel off
}
}
}
}

void theaterChaseRainbow(int SpeedDelay) {
byte *c;

for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < NUM_LEDS; i=i+3) {
c = Wheel( (i+j) % 255);
setPixel(i+q, *c, *(c+1), *(c+2)); //turn every third pixel on
}
showStrip();

delay(SpeedDelay);

for (int i=0; i < NUM_LEDS; i=i+3) {
setPixel(i+q, 0,0,0); //turn every third pixel off
}
}
}
}

void Fire(int Cooling, int Sparking, int SpeedDelay, int Mirror) {
static byte heat[NUM_LEDS];
int cooldown;

// Step 1. Cool down every cell a little
for( int i = 0; i < NUM_LEDS; i++) {
cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2);

if(cooldown>heat) {
heat=0;
} else {
heat=heat-cooldown;
}
}

// Step 2. Heat from each cell drifts 'up' and diffuses a little
for( int k= NUM_LEDS - 1; k >= 2; k--) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
}

// Step 3. Randomly ignite new 'sparks' near the bottom
if( random(255) < Sparking ) {
int y = random(7);
heat[y] = heat[y] + random(160,255);
//heat[y] = random(160,255);
}

// Step 4. Convert heat to LED colors
for( int j = 0; j < NUM_LEDS - MIRROR; j++) {
setPixelHeatColor(j+MIRROR, heat[j] );
setPixelHeatColor(MIRROR-j, heat[j] );
}

showStrip();
delay(SpeedDelay);
}

void setPixelHeatColor (int Pixel, byte temperature) {
// Scale 'heat' down from 0-255 to 0-191
byte t192 = round((temperature/255.0)*191);

// calculate ramp up from
byte heatramp = t192 & 0x3F; // 0..63
heatramp <<= 2; // scale up to 0..252

// figure out which third of the spectrum we're in:
if( t192 > 0x80) { // hottest
setPixel(Pixel, 255, 255, heatramp);
} else if( t192 > 0x40 ) { // middle
setPixel(Pixel, 255, heatramp, 0);
} else { // coolest
setPixel(Pixel, heatramp, 0, 0);
}
}

void BouncingColoredBalls(int BallCount, byte colors[][3], boolean continuous) {
float Gravity = -9.81;
int StartHeight = 1;

float Height[BallCount];
float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
float ImpactVelocity[BallCount];
float TimeSinceLastBounce[BallCount];
int Position[BallCount];
long ClockTimeSinceLastBounce[BallCount];
float Dampening[BallCount];
boolean ballBouncing[BallCount];
boolean ballsStillBouncing = true;

for (int i = 0 ; i < BallCount ; i++) {
ClockTimeSinceLastBounce = millis();
Height = StartHeight;
Position = 0;
ImpactVelocity = ImpactVelocityStart;
TimeSinceLastBounce = 0;
Dampening = 0.90 - float(i)/pow(BallCount,2);
ballBouncing=true;
}

while (ballsStillBouncing) {
for (int i = 0 ; i < BallCount ; i++) {
TimeSinceLastBounce = millis() - ClockTimeSinceLastBounce;
Height = 0.5 * Gravity * pow( TimeSinceLastBounce/1000 , 2.0 ) + ImpactVelocity * TimeSinceLastBounce/1000;

if ( Height < 0 ) {
Height = 0;
ImpactVelocity = Dampening * ImpactVelocity;
ClockTimeSinceLastBounce = millis();

if ( ImpactVelocity < 0.01 ) {
if (continuous) {
ImpactVelocity = ImpactVelocityStart;
} else {
ballBouncing=false;
}
}
}
Position = round( Height * (NUM_LEDS - 1) / StartHeight);
}

ballsStillBouncing = false; // assume no balls bouncing
for (int i = 0 ; i < BallCount ; i++) {
setPixel(Position,colors[0],colors[1],colors[2]);
if ( ballBouncing ) {
ballsStillBouncing = true;
}
}

showStrip();
setAll(0,0,0);
}
}

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
setAll(0,0,0);

for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {


// fade brightness all LEDs one step
for(int j=0; j<NUM_LEDS; j++) {
if( (!meteorRandomDecay) || (random(10)>5) ) {
fadeToBlack(j, meteorTrailDecay );
}
}

// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
setPixel(i-j, red, green, blue);
}
}

showStrip();
delay(SpeedDelay);
}
}

// used by meteorrain
void fadeToBlack(int ledNo, byte fadeValue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
uint32_t oldColor;
uint8_t r, g, b;
int value;

oldColor = strip_A.getPixelColor(ledNo);
oldColor = strip_B.getPixelColor(ledNo);
oldColor = strip_C.getPixelColor(ledNo);
oldColor = strip_D.getPixelColor(ledNo);
r = (oldColor & 0x00ff0000UL) >> 16;
g = (oldColor & 0x0000ff00UL) >> 8;
b = (oldColor & 0x000000ffUL);

r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
b=(b<=10)? 0 : (int) b-(b*fadeValue/256);

strip_A.setPixelColor(ledNo, r,g,b);
strip_B.setPixelColor(ledNo, r,g,b);
strip_C.setPixelColor(ledNo, r,g,b);
strip_D.setPixelColor(ledNo, r,g,b);

#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[ledNo].fadeToBlackBy( fadeValue );
#endif
}

// *** REPLACE TO HERE ***



// ***************************************
// ** FastLed/NeoPixel Common Functions **
// ***************************************

// Apply LED color changes
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip_A.show();
strip_B.show();
strip_C.show();
strip_D.show();

#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}

// Set a LED color (not yet visible)
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip_A.setPixelColor(Pixel, strip_A.Color(red, green, blue));
strip_B.setPixelColor(Pixel, strip_B.Color(red, green, blue));
strip_C.setPixelColor(Pixel, strip_C.Color(red, green, blue));
strip_D.setPixelColor(Pixel, strip_D.Color(red, green, blue));

#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}

// Set all LEDs to a given color and apply it (visible)
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}
 
Status
Not open for further replies.
Back
Top