Micro LASER Show with a CD Lens Mechanism

Step 7Connect the signal source

Connect the signal source
If you haven't yet, get your hands on an Arduino board. Download the Arduino software and run some examples to get comfortable with the process. Then program the Arduino board with the code below.

Stick the wires coming from the lens head into sockets 8,9,10 and 11 on the Arduino.
It is important to put the pair of wires connected to one coil into sockets 8 and 9 and the wires from other pair in sockets 10 and 11.

These are chosen because the pins 9,10 and 11 on the Arduino have PWM capability, used by the analogWrite command in the code.

Apply power and hopefully your mirror will happily wiggle around!

For first test you don't need to fix the Arduino to the housing. You should have made the wires long enough for it to sit comfortably beside the box.

If you've used the Arduino, you can add a 9V battery like shown here to make your device portable. You can safely power it from your computer's USB power if you don't have a battery.

The Arduino source code follows:

/* LASER TAGS - CD LENS MICRO LASERSHOW (Copyleft) 2006 by linefeed @ Ljudmila.org GRL */ int t=0;int inc=4;int pause=1000;int x,y,x0,y0,x1,y1;int pt,phase,loopcnt;int nshapes=6;int shape=0;int shapes[20]={0,4,7,9,11,20, 24};int ptsx[50]={-250,250,250,-250,  -250,250,0,    -250,250,    -250,250,    -230, -230 ,-15, -11, 220, -17, -17, -15, 150,   -250,250,-250,250  };int ptsy[50]={-250,-250,250,250,  -250,-250,250, -250,250,    250,-250,    -220, 200,  200, -200, -200, -210, -210, -35, -40,    -250,-250,250,250  };//pins //  8,9 - vertical // 10,11-horizontal void setup(void) {  // initialize inputs/outputs  pinMode(8,OUTPUT);  pinMode(9,OUTPUT);  pinMode(10,OUTPUT);  pinMode(11,OUTPUT);    digitalWrite(8,LOW);  digitalWrite(10,LOW);  }void setPos(int x, int y) {   if (x>=0) {     digitalWrite(10,LOW);     analogWrite(11,x);   } else {     digitalWrite(11,LOW);     analogWrite(10,-x);   }   if (y>=0) {     digitalWrite(8,LOW);     analogWrite(9,y);   } else {     digitalWrite(8,HIGH);     analogWrite(9,255+y);   }}void loop(void) {  //next shape     if (loopcnt>100) {    shape=(shape+1)%nshapes;    loopcnt=0;  }    //tick phase  phase+=inc;    //next point  if (phase>=100) {     phase=0;     pt=pt++;      //loop points in shape    if (pt>shapes[shape+1]) {      pt=shapes[shape];      t=pt*100;      loopcnt++;    }        x0=x1;    y0=y1;        x1=ptsx[pt];     y1=ptsy[pt];   }      //current coordinate  x=((x0*(100-phase))+(x1*phase))/100;  y=((y0*(100-phase))+(y1*phase))/100;      setPos(x,y);  delayMicroseconds(pause);   }
« Previous StepDownload PDFView All StepsNext Step »
1 comment
Aug 18, 2011. 9:58 PMUncleMike says:
the code is one run on line that wont auto format due to too many syntax errors.

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!
4
Followers
1
Author:linefeed