/********************************************************************
* Ultimate Arduino Chaser by Joe Larson
* http://3dpprofessor.com
*
* Want to make a simple chaser, known as a "Larson Scanner" for your
* project? But you don't want to over engineer it with fancy LED
* strips because you don't need color changing or fades? Just wire
* the LEDs directly to a simple programmable circut board and run
* this code.
* Optionally, you can hook up potentiometers to the read-only pins
* A6 and A7 to be able to adjust the width of the scanner and the
* speed on the fly without re-uploading the code.
* You can, just with editing a few variables here at the beginning
* of the code, customize this scanner to your need. Don't need so
* many LEDs? Change numLEDs and the pins[] you've put them on. Don't
* want both or either of the potentiometers in your project? SEt
* useSpeedPot or useWidthPot to False and it will use the generic
* values of 2 for the cursor width and 60ms delay for the speed.
* (You can edit these values in the functions getDelaySpeed() and
* getCursorWidth() at the bottom of the code.)
* A totally customiable and lightweight Larson scanner for all your
* WOOSH WOOSH projects!
********************************************************************/
int numLEDs=16;
int pins[] = {2,3,4,5,6,7,8,9,10,11,12,A1,A2,A3,A4,A5};
int SpeedPotPin = A6;
int WidthPotPin = A7;
bool useSpeedPot = true;
bool useWidthPot = true;
void setup()
{
for (int pin=0; pin < numLEDs; pin++)
{
pinMode(pins[pin], OUTPUT);
}
}
void loop() {
for (int location = 0; location < numLEDs + getCursorWidth() - 1; location++) // chasing up
{
drawWithDelayAt(location);
}
for (int location = numLEDs + getCursorWidth() - 2; location>=0; location--) // chasing down
{
drawWithDelayAt(location);
}
}
void drawWithDelayAt(int loc)
{
drawScannerAt(loc, HIGH);
delay(getDelaySpeed());
drawScannerAt(loc, LOW);
}
void drawScannerAt(int loc, int value)
{
for (int j = 0; j < getCursorWidth(); j++)
{
if (((loc-j) < numLEDs) && ((loc-j) >= 0)) // Bounds checking
digitalWrite(pins[loc-j], value);
}
}
int getDelaySpeed()
{
if (!useSpeedPot)
return 60;
int speedvalue = analogRead(SpeedPotPin);
return map(speedvalue, 0, 1024, 20,400);
}
int getCursorWidth()
{
if (!useWidthPot)
return 2;
int widthvalue = analogRead(WidthPotPin);
return map(widthvalue, 0, 1024, 1,numLEDs);
}