Hi,
This may be fairly simple for some of you, but not for me. I have two kinetic virus sculptures that are very similar, each uses 15 servos, but one has continuous rotation servos, and the one I am trying to program now does not. They both have Cds sensors that are attached to a servo motor, and should move a part of the sculpture when a light shines on the particular sensor. Here is a video of the sculpture I am trying to program now: Bacteriophage - YouTube I have spent days wiring it up, but there are so many wires it’s hard to see what’s going on. I think I wired it all right. My question is about the program. If I want to change this program which works for continuous rotation servos, to one that works with standard servos, how could I do that? I just want to make the servo wiggle back and forth when the light shines on it. How do I tell it to wiggle back and forth instead of go full speed clockwise in this program?
#include <Servo.h> // include the servo library
Servo servoMotor; // creates an instance of the servo object to control a servo
int analogPin = 0; // the analog pin that the sensor is on
int analogValue = 0; // the value returned from the analog sensor
int servoPin = 9; // Control pin for servo motor. As of Arduino 0017, can be any pin
void setup() {
servoMotor.attach(servoPin); // attaches the servo on pin 2 to the servo object
}
void loop()
{
analogValue = analogRead(analogPin); // read the analog input (value between 0 and 1023)
if(analogValue > 700) {
servoMotor.write(0); // Spin servo at max speed clockwise
} else {
servoMotor.write(93); // Stop the servo
}
delay(15); // waits for the servo to get there
}
Below is what I have done on my own, to try and combine my original program with a sweep program: It verified ok, but I can’t see anything working, not sure what the problem is.
#include <Servo.h> // include the servo library
Servo servoMotor; // creates an instance of the servo object to control a servo
int analogPin = A0; // the analog pin that the sensor is on
int analogValue = 0; // the value returned from the analog sensor
int pos = 0; // variable to store the servo position
int servoPin = 13; // Control pin for servo motor. As of Arduino 0017, can be any pin
void setup() {
servoMotor.attach(servoPin); // attaches the servo on pin 2 to the servo object
}
void loop() {
analogValue = analogRead(analogPin); // read the analog input (value between 0 and 1023)
if(analogValue > 700)
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
servoMotor.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
servoMotor.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Thanks so much for your advice.