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?
#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.