Go Down

Topic: HiTec Dig. Servo - Example works, My code doesn't (Read 484 times) previous topic - next topic

Dillard

Hi,
I tried the example sweep and my servo works great, I tried my own example and it doesn't.  I am assuming it is related to the timing.  I have a sensor that when it goes low, I want the servo to swap where it was (180 to 0, 0 to 180).  The LCD shows the updated sense count, so I know the sensor is working.  The example sweep works, so I know the servo is working.  Where am I going wrong?

Code: [Select]
#include <LiquidCrystal.h>
#include <Servo.h>

LiquidCrystal lcd(22, 23, 31, 32, 33, 34);
Servo myservo;

int inPin = 43;
int outPin = 13;

int reading;                // the current reading from the input pin/sensor
int sense_count=0;     // sensor count
int servo_val=0;         // servo value

void setup()
{
 pinMode(inPin, INPUT);
 pinMode(outPin, OUTPUT);
 
 lcd.begin(20, 4);
 lcd.clear();
 lcd.print("Servo Test v0.1");

 myservo.attach(52);
 myservo.write(0);
 delay(15);
}

void loop()
{
 reading = digitalRead(inPin);
 
 lcd.setCursor(14, 3);
 
 if (reading == LOW) {
   sense_count++;
   lcd.print(sense_count);
   delay(15);
   
   if (servo_val == 0) {
     servo_val = 180;
   } else {
     servo_val = 0;
   }
   
   myservo.write(servo_val);
   delay (15);
 }
 
}


I am aware that the default min/max for the servo in the Servo.h library are not the HiTec recommended values of 900 and 2100.  But, when I try to pass those initially in myservo.attach(52, 900, 2100), my servo goes crazy.

AWOL

15ms for a 180 degree sweep?
That's a fast servo.

Quote
my servo works great, I tried my own example and it doesn't

But what does it do?

Your idea of "works" isn't clear.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Dillard

With the Example code for Sweep, it works.
With this code, the servo doesn't move a bit.

Is 15ms per a degree the actual calculation?  So that is 2700ms for a 180 degree swap?

Thanks.

AWOL

15ms is the time you're allowing the servo to travel 180 degrees, before you're reading the input pin again.
There is no "calculation".
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up