Beruflich Dokumente
Kultur Dokumente
// mode I could have done 1 through 10, but I wasn't sure if port 1 would
// work correctly
{
for (int pin = 2; pin <= 11; pin++)
{
pinMode(pin,OUTPUT);
}
}
// the 'march' function marches a lit LED back and forth across the
// LED line array
void march(int delaytime)
{
for(int pin = 2; pin <=11; pin++)
{
clearall();
digitalWrite(pin, HIGH);
delay(delaytime);
}
for(int pin = 10; pin >= 2; pin--)
{
clearall();
digitalWrite(pin, HIGH);
delay(delaytime);
}
}
// this function is the same as march, but insead an unlit LED marches
// across a lit LED line array
void negmarch(int delaytime)
{
for(int pin = 2; pin <=11; pin++)
{
fillall();
digitalWrite(pin, LOW);
delay(delaytime);
}
for(int pin = 10; pin >= 2; pin--)
{
fillall();
digitalWrite(pin, LOW);
delay(delaytime);
}
}
// this alternates between all lit and all off, used to show reading
// across the analog ports
void flash(int delaytime)
{
for(int i = 1; i <=5; i++)
{
clearall();
delay(delaytime);
fillall();
delay(delaytime);
}
}
// this is the same as the fadeflash function, but every other LED
// either dims or brightens
void fadealter(int delaytime)
{
clearall();
int newdelay = delaytime / 5;
for(int fade = 0; fade <= 255; fade += 5)
{
for(int i = 2; i <= 10; i+=2)
{
analogWrite(i, fade);
}
for (int j = 3; j <= 11; j += 2)
{
analogWrite(j, 255-fade);
}
delay(newdelay);
}
for(int fade = 255; fade >= 0; fade -= 5)
{
for(int i = 2; i <= 10; i+=2)
{
analogWrite(i, fade);
}
for (int j = 3; j <= 11; j += 2)
{
analogWrite(j, 255-fade);
}
delay(newdelay);
}
}
// This is the same as the flash function, but every other LED either
// turns on or off alternately
void alternate(int delaytime)
{
for (int n = 1; n <= 5; n++)
{
clearall();
for (int i = 2; i <= 10; i += 2)
{
digitalWrite(i, HIGH);
}
delay(delaytime);
clearall();
for (int j = 3; j <= 11; j += 2)
{
digitalWrite(j, HIGH);
}
delay(delaytime);
}
}
// This functions marches a series of "bullets" across the LED line array
void bullets(int delaytime)
{
for (int n = 2; n <= 26; n++)
{
clearall();
if (n < 13)
{
drawbullet(n);
}
if (n >= 8 && n < 21)
{
drawbullet(n - 6);
}
if (n >= 14 && n < 29)
{
drawbullet(n - 12);
}
delay(delaytime);
if (n >= 22)
{
drawbullet(n - 18);
}
}
}
// this is a sub function of the bullets function to minimize code.
void drawbullet(int pos)
{
switch(pos)
{
case 2:
digitalWrite(2, HIGH);
break;
case 3:
digitalWrite(2, HIGH);
analogWrite(3, round(255/10));
break;
case 12:
digitalWrite(10, HIGH);
analogWrite(11, round(255/10));
break;
case 13:
digitalWrite(11, HIGH);
break;
default:
digitalWrite(pos, HIGH);
analogWrite(pos-1, round(255/10));
analogWrite(pos-2, round(255/20));
break;
}
}
// This makes a "radiating" pattern of LEDS eminate from the center and
// they dim as they approach the ends
void radiate(int delaytime)
{
for(int n = 7; n < 28; n++)
{
clearall();
if(n < 12)
{
drawray(n);
}
if(n >= 10 && n <= 14)
{
drawray(n - 3);
}
if(n >= 13 && n <= 17)
{
drawray(n - 6);
}
if(n >= 16 && n <= 20)
{
drawray(n - 9);
}
if(n >= 19 && n <= 23)
{
drawray(n - 12);
}
if(n >= 22 && n <= 26)
{
drawray(n - 15);
}
delay(delaytime);
}
}
// This function is like the march, except the marching LEDs appear to
// stack up at the end of the array one by one.
void stackdots(int delaytime)
{
int stack = 0;
while(stack < 10)
{
for(int pos = 2; pos <= (11 - stack); pos++)
{
clearall();
digitalWrite(pos, HIGH);
drawstack(stack);
delay(delaytime);
}
stack++;
}
}