Here's his sketch:
#include "FastLED.h"
// the milliseconds to give each letter
#define MILLIS_PER_LETTER 1750
// number of LEDs in the strip
#define NUM_LEDS 50
// the data pin
#define DATA_PIN 11
// an array to keep track of the LEDs
CRGB leds[NUM_LEDS];
// the message we will display
String message;
// the time we received the message
unsigned long received;
// we"ll use all 26 letters of the alphabet
#define NUM_LETTERS 26
// the LED number (start counting from 0) that we light up to show our message
const int LETTER_LEDS[NUM_LETTERS] = {
/*A*/ 7
,/*B*/ 8
,/*C*/ 9
,/*D*/ 10
,/*E*/ 11
,/*F*/ 12
,/*G*/ 13
,/*H*/ 14
,/*I*/ 32
,/*J*/ 31
,/*K*/ 30
,/*L*/ 29
,/*M*/ 28
,/*N*/ 26
,/*O*/ 25
,/*P*/ 24
,/*Q*/ 23
,/*R*/ 38
,/*S*/ 39
,/*T*/ 40
,/*U*/ 41
,/*V*/ 42
,/*W*/ 44
,/*X*/ 45
,/*Y*/ 46
,/*Z*/ 47
};
// how many colors to cycle through for the lights
#define NUM_COLORS 4
void setup() {
// send print statements at 9600 baud
Serial.begin(9600);
// initialize the LEDS
FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
// set them all to be off
fill_solid(leds, NUM_LEDS, CRGB::Black);
FastLED.show();
// connect to wifi.
// this message will show until it is overwritten from Firebase and shown if Firebase fails
message = "welcome to specs";
received = millis();
}
void loop() {
// how many milliseconds have elapsed since the last message came in
unsigned long elapsed = millis() - received;
// assuming MILLIS_PER_LETTER, what letter (index) ofthe message should we be on?
int index = elapsed/MILLIS_PER_LETTER;
// if the letter we should technically be on is within the bounds of the message
if(index < message.length()) {
// get the character letter we should print
char letter = message.charAt(index);
// if the character is between 'a' and ‘z" (no numbers, spaces, or punctuations)
if(letter >= 'a' && letter <= 'z'){
// how bright to make this LED from 0 to 1, this is what makes them fade in and out
// it calculates what percent we are completed with the letter, and makes it fade in from 0–50% and fade out from 50–100%
// the formula can be visualized here: https://www.desmos.com/calculator/5qk8imeny4
float brightness = 1-abs((2*(elapsed%MILLIS_PER_LETTER)/((float)MILLIS_PER_LETTER))-1);
uint8_t value = 255 * brightness;
// get the LED number the letter should be in, assuming our array starts at ‘a" and ends at ‘z"
int letter_index = letter-'a';
int led = LETTER_LEDS[letter_index];
// get a rotation of colors, so that every NUM_COLORS lights, it loops
// e.g. red, yellow, green, blue, red, yellow green blue
uint8_t hue = (letter_index%NUM_COLORS*255)/NUM_COLORS;
// set that LED to the color
leds[led] = CHSV(hue, 255, value);
FastLED.show();
// set it to black so we don’t have to remember the last LED we turned on
leds[led] = CRGB::Black;
Serial.print(letter);
Serial.print("\t!");
Serial.print(led);
Serial.print("\t=");
Serial.print(brightness);
Serial.print("\t@");
Serial.print(elapsed);
Serial.println();
} else {
// if the letter wasn’t a-z then, we just turn off all the leds
FastLED.show();
}
} else {
// if the letter is beyond the bounds of the message, we just turn off all the leds
FastLED.show();
}
}
I hate it when there is no white space or indenting, but ... :rolleyes:
Try modifying the loop() function by encasing all it's code with a looping structure, just use a delay here, since it's gonna be short, and there is nothing going on then anyway:
// ...
void loop() {
while (1) { // loop indefinitely
/**** put all the stuff from your loop() function here ******/
delay(3000); // pause 3 seconds between runs
}
}
If the original program is nicely written, then my mod should run, wait 3 seconds, then run again. If it doesn't run correctly the second time, then some of the statements in the set up routine need to be executed between the delay() function and the end of the while loop. Try this and then figure out how to do that mod.
If you want to do 'existing code modification' you should learn enough programming your machine in order to understand what the code does.