I am trying to make a laser toy for my cat. i have everything working except that the servos are running too fast. I know the if() statement to slow them down however i am using random number and having both servos move simultaneously. my code i have so far is...
#include <Servo.h>
Servo vert;
Servo hori; // create servo object to control a servo
int pos = 0; // variable to store the servo position
int laser = A1;
void setup() {
hori.attach(9);
vert.attach(11); // attaches the servo on pin 9 to the servo object
pinMode(laser,OUTPUT);
}
void loop() {
digitalWrite(laser,HIGH);
int timeBetweenShots = random(50,200);
int vertStart = random(45,90);
int vertEnd = random(45,90);
int horiStart = random(35,145);
int horiEnd = random(30,145);
int vertChange = (vertEnd - vertStart) / 1; //how much to move vertical axis by each shot
int horiChange = (horiEnd - horiStart) / 1;
vert.write(vertStart);//let it get to start position first, wait a little
hori.write(horiStart);
delay(300);
vert.write(vertStart);
hori.write(horiStart);
vertStart += vertChange;//increment the vert value for next time
horiStart += horiChange;
}
I may have extra unneeded programming in here but this is due to using another code and tweeking it. Please halp me code this to make it run slower than it is but still move the servos simultaneously and randomly.
thanks
justin