Go Down

Topic: speed control of two servos (Read 385 times) previous topic - next topic

Barfly9823

I am trying to control the speed of two servos operating at the same time.  Right now they operate at max speed, one counter clockwise, the other clockwise.  Code so far is a follows.

const int sensorPin = A0;
int lightLevel = 0;
#include <Servo.h>  // servo library
Servo servoFLCW, servoFLCCW;  // servo control object
 
void setup() {
    Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
    servoFLCW.attach(2);
    servoFLCCW.attach(3);

 
void loop(){
 
  lightLevel = analogRead(sensorPin);
   Serial.print("Light level Bay 1: ");
   Serial.println(lightLevel);
 
  if ((lightLevel) > 2);
 
   {
      delay(2000);
      doorFLCW();
   } 


void doorFLCW() {
 
  if ((lightLevel) < 300) {
 
    servoFLCW.write(135);
    servoFLCCW.write(5);

     
     else

{   

  servoFLCW.write(5);
  servoFLCCW.write(135);
}   


Any constructive help would be appreciated.

groundFungus

You will save everyone's time if you read and follow the forum guidelines.  :)          
https://forum.arduino.cc/index.php/topic,148850.0.html
and
https://forum.arduino.cc/index.php?topic=97455.0

Barfly9823


Robin2

Look at how the servo is controlled in the demo several things at a time. It would be very simple to add another servo.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Barfly9823

It does what I need it to .  It is operating the two doors for a roundhouse bay.  Took the true statement at the end out so that they operate at the same time.

AWOL

Code: [Select]
if ((lightLevel) > 2);
Did you fix that one?

Go Up