if(mode > 0) {
switch (currentProgram) {
//Beat
case PROGRAM_VU_FIXED:
case PROGRAM_VU_CYCLE:
{
if(currentProgram==PROGRAM_VU_CYCLE)
{
effectDuration = progs.param1();
color = color + effectDuration;
}
else if(currentProgram==PROGRAM_VU_FIXED)
{
color = progs.param1();
}
if(color>PALETTEARRAY) {
color = 0;
}
//holy nuts i hate these strongly typed variables
float vu = (float)shifty.adcAvg() / (float)1023;
double temp = ((double)vu*(double)100);
double vuRatio = temp * temp * temp * temp / 100000000;
colorFrom = InttoRGB(palette[color]);
colorFrom.r = int((double)colorFrom.r * vuRatio);
colorFrom.g = int((double)colorFrom.g * vuRatio);
colorFrom.b = int((double)colorFrom.b * vuRatio);
for (int i = 0; i < NUMLEDS; i++) {
megaBrite.ledChannels(i, COLORCURRENT, colorFrom);
}
break;
}
//Sine Plasma
case PROGRAM_PLASMA_FIXED:
case PROGRAM_PLASMA_CYCLE:
{
if(color != progs.param1() && currentProgram==PROGRAM_PLASMA_FIXED)
{
color = progs.param1();
//generate the palette
ColorRGB rgb;
ColorHSV hsv;
for(int x = 0; x < 256; x++)
{
//use HSVtoRGB to vary the Hue of the color through the palette
ColorHSV hsv = {color, 255, x};
rgb = HSVtoRGB(hsv);
palette[x] = RGBtoInt(rgb);
}
}
effectDuration = progs.param2();
//the parameter to shift the palette varies with time
long paletteShift;
paletteShift = (long)(millis() / (double)effectDuration);
ColorRGB current;
//draw every pixel again, with the shifted palette color
for(int x = 0; x < SCREENHEIGHT; x++)
{
for(int y = 0; y < SCREENWIDTH; y++)
{
current = InttoRGB(palette[((long)plasma[x][y] + paletteShift) % 256]);
megaBrite.ledChannels(screen.pixel[x][y], COLORCURRENT, current);
}
}
//shows the LED in the panel
megaBrite.ledChannels(NUMLEDS - 1, COLORCURRENT, current);
break;
}
//Chaser
case PROGRAM_CHASER_CYCLE:
case PROGRAM_CHASER_FIXED:
{
if(currentProgram==PROGRAM_CHASER_CYCLE)
{
color = color + progs.param1();
if(color>PALETTEARRAY) {
color = 0;
}
}
else
{
color = progs.param1();
}
effectDuration = (millisecondsPerBeat) * beatSegments[progs.param2()];
pulseDuration = (millisecondsPerBeat) * beatSegments[progs.param3()];
timer = millis();
effectTime = timer - ms;
if(effectTime>effectDuration) {
ms = millis();
currentLED++;
if(currentLED>=SCREENWIDTH)
currentLED = 0;
for(int x = 0; x < SCREENHEIGHT; x++)
{
for(int y = 0; y < SCREENWIDTH; y++)
{
if(y==currentLED)
{
fadeArray[screen.pixel[x][y]] = 0;
megaBrite.ledChannels(screen.pixel[x][y], COLORFROM, InttoRGB(palette[color]));
}
}
}
}
for (int i = 0; i < NUMLEDS; i++) {
if(fadeArray[i]>-1) {
if(fadeArray[i]>pulseDuration) {
fadeArray[i] = pulseDuration;
}
if(fadeArray[i]<=pulseDuration) {
ColorRGB current;
current.r = quadraticEaseOut((long)(pulseDuration - fadeArray[i]), megaBrite.ledChannels(i, COLORFROM).r, colorOff.r, (long)pulseDuration);
current.g = quadraticEaseOut((long)(pulseDuration - fadeArray[i]), megaBrite.ledChannels(i, COLORFROM).g, colorOff.g, (long)pulseDuration);
current.b = quadraticEaseOut((long)(pulseDuration - fadeArray[i]), megaBrite.ledChannels(i, COLORFROM).b, colorOff.b, (long)pulseDuration);
megaBrite.ledChannels(i, COLORCURRENT, current);
}
if(fadeArray[i]==pulseDuration) {
fadeArray[i] = -1;
} else {
fadeArray[i] += refreshDif;
}
}
}
break;
}
//Random Colour
case PROGRAM_RANDOM_FIXED:
case PROGRAM_RANDOM_CYCLE:
case PROGRAM_RANDOM_RAND:
{
currentLED = progs.param1();
if(currentProgram==PROGRAM_RANDOM_FIXED)
{
color = currentLED;
currentLED = 2;
}
else if(currentProgram==PROGRAM_RANDOM_CYCLE)
{
color = color + (currentLED);
currentLED = 2;
if(color>PALETTEARRAY) {
color = 0;
}
}
else {
color = random(256);
}
effectDuration = (millisecondsPerBeat) * beatSegments[progs.param2()];
pulseDuration = (millisecondsPerBeat) * beatSegments[progs.param3()];
timer = millis();
effectTime = timer - ms;
if(effectTime>effectDuration) {
ms = millis();
for (int i = 0; i < currentLED; i++)
{
int newRandom = random(NUMLEDS);
fadeArray[newRandom] = 0;
megaBrite.ledChannels(newRandom, COLORFROM, InttoRGB(palette[color]));
}
}
for (int i = 0; i < NUMLEDS; i++) {
if(fadeArray[i]>-1) {
if(fadeArray[i]>pulseDuration) {
fadeArray[i] = pulseDuration;
}
if(fadeArray[i]<=pulseDuration) {
ColorRGB current;
current.r = quadraticEaseOut((long)(pulseDuration - fadeArray[i]), megaBrite.ledChannels(i, COLORFROM).r, colorOff.r, (long)pulseDuration);
current.g = quadraticEaseOut((long)(pulseDuration - fadeArray[i]), megaBrite.ledChannels(i, COLORFROM).g, colorOff.g, (long)pulseDuration);
current.b = quadraticEaseOut((long)(pulseDuration - fadeArray[i]), megaBrite.ledChannels(i, COLORFROM).b, colorOff.b, (long)pulseDuration);
megaBrite.ledChannels(i, COLORCURRENT, current);
}
if(fadeArray[i]==pulseDuration) {
fadeArray[i] = -1;
} else {
fadeArray[i] += refreshDif;
}
}
}
break;
}
//Nothing - Program Not Found - This shouldn't happen
default:
{
break;
}
}
}
//None/Off
else
{
if(effecting) {
timer = millis();
effectTime = timer - ms;
if(effectTime>effectDuration) {
effecting = false;
effectTime = effectDuration;
}
for (int i = 0; i < NUMLEDS; i++) {
ColorRGB current;
current.r = quadraticEaseOut((long)(effectDuration - effectTime), megaBrite.ledChannels(i, COLORFROM).r, 0, (long)pulseDuration);
current.g = quadraticEaseOut((long)(effectDuration - effectTime), megaBrite.ledChannels(i, COLORFROM).g, 0, (long)pulseDuration);
current.b = quadraticEaseOut((long)(effectDuration - effectTime), megaBrite.ledChannels(i, COLORFROM).b, 0, (long)pulseDuration);
megaBrite.ledChannels(i, COLORCURRENT, current);
}
}
}
megaBrite.writeLEDArray();
//delayMicroseconds(50);
}