Portfolio. BHSAD Arduino Prototyping | L4, Harduino: Drawing light | Page 25
void theaterChaseRainbow
(int SpeedDelay) {
byte *c; byte * Wheel(byte
WheelPos) {
static byte c[3];
for (int j=0; j < 256; j++) {
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));
}
showStrip();
delay(SpeedDelay);
for (int i=0; i < NUM_
LEDS; i=i+3) {
setPixel(i+q, 0,0,0);
}
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 loop() {
BouncingBalls (0xff,0x24,0xd3, 3);
}
void BouncingBalls (byte red, byte green, byte blue, int
BallCount) {
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];
for (int i = 0 ; i < BallCount ; i++) {
ClockTimeSinceLastBounce [i] = millis();
Height[i] = StartHeight;
Position[i] = 0;
ImpactVelocity[i] = ImpactVelocityStart;
TimeSinceLastBounce[i] = 0;
Dampening[i] = 0.90 - float(i)/pow (BallCount,2);
}
while (true) {
for (int i = 0 ; i < BallCount ; i++) {
TimeSinceLastBounce[i] = millis() -
ClockTimeSinceLastBounce[i];
Height[i] = 0.5 * Gravity * pow (
TimeSinceLastBounc