3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Arduino Larson/Cylon Scanner

Arduino Larson/Cylon Scanner
In this instructable I will show you how to make a Larson a.k.a Cylon scanner with an optional speed control on Arduino. 



 
Remove these adsRemove these ads by Signing Up
 

Step 1Things you will need

Things you will need
«
  • Photo 2.jpg
  • Photo 3.jpg
  • Photo 4.jpg
  • Photo 5.jpg
  • Photo 6.jpg
  • Photo 7.jpg
  • Photo 8.jpg
  • Photo 12.jpg
  • last photo ←
»
Arduino Duemilanove
Mini Breadboard
3 Breadboard Jumpers
6 LED's
Solid Core Wire
8 Pin Header
Perf Board
Potentiometer (optional) 
« Previous StepDownload PDFView All StepsNext Step »
2 comments
Jul 5, 2010. 12:39 PMVick Jr says:
I made some new code for it to use logarithmic PWM for fading and some other stuff for smooth movement. It's still a work in progress. I haven't actually seen how it looks very well because I don't have enough of the right size/color LEDs right now, but even with different colors and sizes it looks pretty cool. Don't mind the serial.write comments. those are for debugging. Eventually I hope to make it for charlieplexing so it can fit more than 6 leds. that's a different story.

great 'ible btw!

*hope this code formats correctly*

//Cylon_Scanner_with_PotControl
//Created by: Zachary Gehrken

//Heavily Modified by Vick Jr to use logarithmic PWM and smooth eye movement interpolation (fancy *&%&!)

//led stuff
/***make vertualSize larger for smoother but slower movement***/
const unsigned int vertualSize = 80; //the eye will move along a vertual track with this many units. Ideally the logarithmic lookup table would have the same amount
const unsigned int ledPins[] = {3,5,6,9,10,11}; //array of LED pins used with PWM
const unsigned int lastIndex=5; //last index of the led array (total pins-1)
unsigned int ledPositions[6]; //vertual positions of the LEDs along the vertual track
int index=0; //index for looping through arrays

//input stuff
const float speedCalibrator=0.2; //the input of the POT (range 0->255) is multiplied by this to get a reasonable delay amount between updates
const unsigned int analogPin = 2; //input pin for potentiometer
unsigned int sensorValue = 0; //value of the analog speed potentiometer

//eye and movement stuff
/***CHANGE eyeRadius TO ADJUST EYE SIZE***/
const int eyeRadius=40; //LEDs more than this many vertual units away from the center will be off.
boolean moveRight; //specifies if the eye is moving right (may be left. whatever)
int eyePosition; //the current position of the center of the eye along vertual track
int dist; //vertudistance from a given led to the eye center

//PWM stuff
int dutyCycle; //PWM dutyCycle for a given pin (inversly related to distance)
float scaler =(16.0/eyeRadius); //maps brightness values in the range [0, eyeRadius] to values in the range [0, 16]
int brightness; //brightness of led on a scale from 0 to 15
//logarithmic look-up table to convert desired brightness to pwm dudy cycle. 17 values. last index=16
int PWMDC[] = {0,1,2,3,4,6,8,12,16,23,32,45,64,90,128,180,255};

void setup() {
// Serial.begin(9600); // initialize serial communications at 9600 bps:
float space=vertualSize/(lastIndex); // vertual space between LEDs
for (index=0;index<=lastIndex;index++){//loop though pins
pinMode(ledPins[index], OUTPUT); // set them for output
ledPositions[index]=space*index; // calculate the vertual positions along vertual track
}
}

void loop() {

//get input from POT and delay accordingly
sensorValue = speedCalibrator*analogRead(analogPin);//update the speed if neccisary
delay(sensorValue);//delay according to the speed
/*
Serial.print("\ndelay:" );
Serial.print(sensorValue);
*/
//update eye position by 1 step along vertual track
// Serial.print("\tMOVING:" );
if (moveRight){//if the eye is moving right
if (eyePosition<vertualSize){//and it's not past the last led on the right
eyePosition++;//add to the position
// Serial.print("R");
}else{//but if it's at or past that position
moveRight=false;//start moving left next time. stay put this time
// Serial.print("L");
}
}
else{//if the eye is moving left
if (eyePosition>0){//and it's not past the last led on the left
eyePosition--;//subtract from the position
// Serial.print("L");
}else{//but if it's at or past that position
moveRight=true;//start moving right
// Serial.print("R");
}
}
/*
Serial.print("\tEYE:" );
Serial.print(eyePosition);
*/
//make the LEDs light up appropriatly for the position of the eye
for (index=0;index<=lastIndex;index++){//loop though leds
dist=eyePosition-ledPositions[index]; //vertual distance from the eye to the LED (range 0 through vertualSize)
dist=abs(dist);//distance cannot be negative
//Serial.print("\t" );
//Serial.print(index);
if (dist<=eyeRadius){ //if this LED is within the eye
brightness=eyeRadius-dist; //as distance decreases, brightness increases (range [0, eyeRadius])

brightness*=scaler;
brightness+=0.5;
//map(brightness,0,eyeRadius,0,16);
//dutyIndex=int((brightness*scaler)+0.5);//calc the closes index to use
dutyCycle=PWMDC[brightness/*dutyIndex*/];//scale the brightness to get a value range [0,16]. use this as index to get corresponding logarithmic duty cycle
/*
Serial.print(":D:");
Serial.print(dist);

Serial.print("\tB:");
Serial.print(brightness);

//Serial.print("\tI:");
//Serial.print(dutyIndex);

Serial.print("\tC:");
Serial.print(dutyCycle);
*/
}else{
dutyCycle=0;
// Serial.print(":NA\t\t");
}
analogWrite(ledPins[index],dutyCycle);//set that pin at that brightness
}
}





*nope. didn't format. oh well. arduino ide has an auto-format tool.*






Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
0
Followers
3
Author:zgr95