Hello,
I did a DJ's light with a mirror, stepper motor and servo, I'm a beginner, it's my first program so it's not great, I preferred to start simple to not have too much trouble at first.
It's not the code of the century but it works almost as I would like, the almost is that I can not get out of the loop as I would like:
When the sound is detected (digital output) my loop starts well but when I cut the sound it finished all instructions (until that's normal) I tried to put a condition "if" with a "break", it It works too well so if I have a weak sound at some point I leave the loop; but instead of going out of the loop I would like to pause it with a delay that would avoid the false stops so let's not imagine for 1 second, the loop is paused and when it's back the loop restarts and then I stuck so if you have a little trick ...
Another thing is there a way to put all these instructions in a table or even two would be the ideal left and right seen facing the mirror (less than 300 and over 300 stepper) and randomly draw the instructions a shot in table 1 (left) and the next shot in table 2 (right), good for that I think there is a course to be taken that is far from beginners.
my english is very bad sorry
thank you
#include <VarSpeedServo.h>
#include <AccelStepper.h>
VarSpeedServo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
const int servoPin = 10; // the digital pin used for the servo
// Define a stepper and the pines it will use
AccelStepper stepper (1,9,8); // Defaults to AccelStepper :: DRIVER 9, 8
void setup ()
{
myservo.attach (servoPin); // attaches the servo on pin 9 to the servo object
myservo.write (0.255, true); // set the intial position of the servo, as fast as possible, wait until done
stepper.setMaxSpeed (7000.0);
stepper.setAcceleration (7000.0);
stepper.runToNewPosition (-600);
stepper.setCurrentPosition (0);
}
void loop () {
while (digitalRead (2) == 1)
{
stepper.runToNewPosition (10);
myservo.write (10,75, true); // write (0-180 degrees, speed 1-255, wait to complete true-false)
stepper.runToNewPosition (600);
myservo.write (40,75, true);
stepper.runToNewPosition (100);
myservo.write (20,75, true);
stepper.runToNewPosition (50);
myservo.write (10,75, true);
stepper.runToNewPosition (500);
myservo.write (45,75, true);
// if (digitalRead (2) == 0); {break;};
stepper.runToNewPosition (450);
myservo.write (55,75, true);
stepper.runToNewPosition (550);
myservo.write (30,75, true);
stepper.runToNewPosition (150);
myservo.write (15.75, true);
stepper.runToNewPosition (200);
myservo.write (30,75, true);
stepper.runToNewPosition (0);
myservo.write (10,75, true);
// if (digitalRead (2) == 0); {break;};
stepper.runToNewPosition (250);
myservo.write (40,75, true);
stepper.runToNewPosition (420);
myservo.write (20,75, true);
stepper.runToNewPosition (120);
myservo.write (5.75, true);
stepper.runToNewPosition (530);
myservo.write (45,55, true);
stepper.runToNewPosition (120);
myservo.write (10,75, true);
stepper.runToNewPosition (10);
myservo.write (25,75, true);
stepper.runToNewPosition (450);
// if (digitalRead (2) == 0); {break;};
}
if (digitalRead (2) == 0) {
stepper.runToNewPosition (0);
myservo.write (10,55, true);
}
}