Here is a simple 'KIT' with a variable rate.
And the sketch...
/*Remember Knight Rider's 'KIT'? Well this code gives
the same effect and adds the ability to control the
rate of the 'scan'.
This uses 12 LEDs attached to digital pins 2~13 and
a potentiometer (I used 1k) across power pins 5V and
GND, with the wiper attached to analog pin 0.
Enjoy - Clark Buckley 2012
*/
float rate; //Reads value from A0
void setup()
{
//Sets output pins
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
}
void loop()
{
for (int x=2; x<14; x++) //Scan loop, pin 2->13
{ digitalWrite(x, HIGH); //LED 'On'
rate = analogRead(0); //Read potentiometer
delay((rate/1023)*100); //Leaves LED 'On'
digitalWrite(x, LOW); //LED 'Off'
}
for (int y=12; y>2; y--) //Scan loop, pin 12->3
{ digitalWrite(y, HIGH); //LED 'On'
rate = analogRead(0); //Read potentiometer
delay((rate/1023)*100); //Leaves LED 'On'
digitalWrite(y, LOW); //LED 'Off'
}
}
No comments:
Post a Comment