Skip to content

Commit

Permalink
Array experiment
Browse files Browse the repository at this point in the history
Experimenting with replacing sequentially numbered variables of many values for each LED with arrays. 

Initialized fadeTimer as an array. Replaced all instances of fadeTimerX with it's associated array.
  • Loading branch information
DeadBranches authored Oct 13, 2022
1 parent cb3718a commit 7ce89ce
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions Firmware/LilyTwinkle/LilyTwinkle.ino
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ boolean celebrate = false; // Are we celebrating right now?
int celebrationRoll = 0; // Holds the magic number to match for celebrations.


const int numberOfLEDs = 5;
int fadeTimer[numberOfLEDs] = { 10, 10, 10, 10, 10 };

long delayTime = 50;
long startTime = 0;

Expand Down Expand Up @@ -137,11 +140,11 @@ void loop()
celebrate = true;
waitingToCelebrate = false;

fadeTimer0 = 500; // Set every LED to have a very slow next fade.
fadeTimer1 = 500;
fadeTimer2 = 500;
fadeTimer3 = 500;
fadeTimer4 = 500;
fadeTimer[0] = 500; // Set every LED to have a very slow next fade.
fadeTimer[1] = 500;
fadeTimer[2] = 500;
fadeTimer[3] = 500;
fadeTimer[4] = 500;
// Reset all counters so that everyone fades from the start.
onTime0 = 0; // reset pwm counter.
onTime1 = 0;
Expand Down Expand Up @@ -184,7 +187,7 @@ void loop()
onCounter0++;
fadeCounter0++;

if (fadeCounter0 == fadeTimer0)
if (fadeCounter0 == fadeTimer[0])
{
fadeCounter0 = 0;
onTime0 += dir0;
Expand All @@ -193,7 +196,7 @@ void loop()
if ((onTime0 == 0) && (dir0 = 1))
{
limit0 = random(LIMITMIN0,LIMITMAX0); // pin-specific brightness values
fadeTimer0 = random(fadeMinDynamic0,fadeMaxDynamic0); // pin specific dynamic-fade speed variables
fadeTimer[0] = random(fadeMinDynamic0,fadeMaxDynamic0); // pin specific dynamic-fade speed variables

if (waitingToCelebrate) {
enable0 = false;
Expand All @@ -216,15 +219,15 @@ void loop()
else digitalWrite(LED1, HIGH);
onCounter1++;
fadeCounter1++;
if (fadeCounter1 == fadeTimer1)
if (fadeCounter1 == fadeTimer[1])
{
fadeCounter1 = 0;
onTime1 += dir1;
if ((onTime1 == limit1) || (onTime1 == 0)) dir1 *= -1;
if ((onTime1 == 0) && (dir1 = 1))
{
limit1 = random(LIMITMIN1,LIMITMAX1); // pin-specific brightness values
fadeTimer1 = random(fadeMinDynamic,fadeMaxDynamic);
fadeTimer[1] = random(fadeMinDynamic,fadeMaxDynamic);


if (waitingToCelebrate) {
Expand Down Expand Up @@ -256,7 +259,7 @@ void loop()
fadeMaxDynamic0 = FADEMAXFAST;
fadeFalseDynamic0 = FADEFALSEFAST; // pin-specific dynamic dice roll
fadeTrueDynamic0 = FADETRUEFAST;
fadeTimer0 = random(fadeMinDynamic,fadeMaxDynamic); // Hijack LED0's fade timer just in case it's
fadeTimer[0] = random(fadeMinDynamic,fadeMaxDynamic); // Hijack LED0's fade timer just in case it's
// in the middle of a really long fade. Replace it with something short. That way it
// will coffee too!!!!
enable0 = true;
Expand Down Expand Up @@ -293,15 +296,15 @@ void loop()
else digitalWrite(LED2, HIGH);
onCounter2++;
fadeCounter2++;
if (fadeCounter2 == fadeTimer2)
if (fadeCounter2 == fadeTimer[2])
{
fadeCounter2 = 0;
onTime2 += dir2;
if ((onTime2 == limit2) || (onTime2 == 0)) dir2 *= -1;
if ((onTime2 == 0) && (dir2 = 1))
{
limit2 = random(LIMITMIN,LIMITMAX);
fadeTimer2 = random(fadeMinDynamic,fadeMaxDynamic);
fadeTimer[2] = random(fadeMinDynamic,fadeMaxDynamic);

if (waitingToCelebrate) {
enable2 = false;
Expand Down Expand Up @@ -330,7 +333,7 @@ void loop()
if ((onTime3 == 0) && (dir3 = 1))
{
limit3 = random(LIMITMIN,LIMITMAX);
fadeTimer3 = random(fadeMinDynamic,fadeMaxDynamic);
fadeTimer[3] = random(fadeMinDynamic,fadeMaxDynamic);

if (waitingToCelebrate) {
enable3 = false;
Expand All @@ -351,15 +354,15 @@ void loop()
else digitalWrite(LED4, HIGH);
onCounter4++;
fadeCounter4++;
if (fadeCounter4 == fadeTimer4)
if (fadeCounter4 == fadeTimer[4])
{
fadeCounter4 = 0;
onTime4 += dir4;
if ((onTime4 == limit4) || (onTime4 == 0)) dir4 *= -1;
if ((onTime4 == 0) && (dir4 = 1))
{
limit4 = random(LIMITMIN,LIMITMAX);
fadeTimer4 = random(fadeMinDynamic,fadeMaxDynamic);
fadeTimer[4] = random(fadeMinDynamic,fadeMaxDynamic);

if (waitingToCelebrate) {
enable4 = false;
Expand Down

0 comments on commit 7ce89ce

Please sign in to comment.