Sunday, January 11, 2015

Steampunk Light Dress Part Five: Overloading Sparkle()

By dividing my  arrays of LED's into groups, or arrays, I can fire off a wider array of effects.  Take the example below.  I have three arrays of LED arrays:
  • 12X2 single-colored LED's (1-12.) 
  • An array of 2X12 RGB LED's  (A and B.)
  • Another array of 12X2 single-color LED's (13-24)
Using arrays OF arrays of LED's, I can:
  • Chase sequentially from 1-23, ignoring the RGB LED's.
  • Do a ping-pong effect (chasing back and forth across the panel) on 1-12 and 13-23 simultaneously.
  • Fade the RGB LED's, leaving 1-23 off.
  • Fire off every other or every third single-color LED.
Only thing that remains is to overload the functions to take either arrays of LED's or arrays OF arrays of LED's.  Why?  Because I'd like to allow for applications that use fewer LED's (like the parasol,) to still use the functions without getting overly complicated.

(As of yet untested) example code follows:

void sparkle(Led ledList[], int arraySize, long seconds)
{
  // the intial setting of the potentiometer.
  int initVal=analogRead(potPin);
  
Serial.println(seconds);
// Convert the milliseconds to seconds
Serial.println("Going to sparkle for ");
Serial.println(seconds);
Serial.println("MS!");
// Set the count variable (this will track the MS invested in the run and tell the program when to stop.)
 long count=0;
 do
 {
 // Select a random bulb
 int bulb=random(0,arraySize);  
 // Turn it on (if it's RGB, randomize the color)
 fireLed(ledList[bulb], true);
 // The on sensitivity obtained from the static sense pin
 byte onSensitivity=map(analogRead(staticSensePin),0,1023,1,12); 
 // Select a random pause time
 int inPause=random(20*onSensitivity,50*onSensitivity);
 // Add this to the total count time
 count+=inPause;
 // Pause
 delay(inPause);z
 // Turn off the selected bulb
 turnOffLed(ledListarrayNum[bulb]);
 // break if we've gone beyond the time
 if (analogRead(potPin)>high||analogRead(potPin)<low)
 {
   return;
 }
 // Adds a value calculated from the sensitivity pot
 byte sensitivity=map(analogRead(sensePin),0,1023,1,12); 
 // Select a random pause time
 int outPause=random(50*sensitivity,500*sensitivity);
 // Add this to the total count time.
 count+=outPause;
 // Pause
 delay(outPause);
Serial.println(count);
 }
 while ((seconds)>count);
 // Stop once the alloted number of minutes are done.
}


void sparkle(Led ledList[][], int arraySize, byte noOfArrays, long seconds)
{
  // the intial setting of the potentiometer.
  int initVal=analogRead(potPin);
  
Serial.println(seconds);
// Convert the milliseconds to seconds
Serial.println("Going to sparkle for ");
Serial.println(seconds);
Serial.println("MS!");
// Set the count variable (this will track the MS invested in the run and tell the program when to stop.)
 long count=0;
 do
 {
 // Select a random bulb
 int arrayNum=random(0,noOfArrays);
 int bulb=random(0,arraySize);  
 // Turn it on (if it's RGB, randomize the color)
 fireLed(ledList[arrayNum][bulb], true);
 // The on sensitivity obtained from the static sense pin
 byte onSensitivity=map(analogRead(staticSensePin),0,1023,1,12); 
 // Select a random pause time
 int inPause=random(20*onSensitivity,50*onSensitivity);
 // Add this to the total count time
 count+=inPause;
 // Pause
 delay(inPause);z
 // Turn off the selected bulb
 turnOffLed(ledListarrayNum[bulb]);
 // break if we've gone beyond the time
 if (analogRead(potPin)>high||analogRead(potPin)<low)
 {
   return;
 }
 // Adds a value calculated from the sensitivity pot
 byte sensitivity=map(analogRead(sensePin),0,1023,1,12); 
 // Select a random pause time
 int outPause=random(50*sensitivity,500*sensitivity);
 // Add this to the total count time.
 count+=outPause;
 // Pause
 delay(outPause);
Serial.println(count);
 }
 while ((seconds)>count);
 // Stop once the alloted number of minutes are done.
}


No comments:

Post a Comment