Hey Forum,
I'm trying to control two servos in my loop. One of the servos may be better suited as a stepper motor, though the trouble i'm having is to do with the 'if' statement not appearing to work as I expected.
Basically, I don't want the servo to go through it's movements until a switch it flicked bringing a pin (pin10) to either HIGH or LOW (doesn't matter to me - just a change in state). The speed is controlled by a pot - I didnt think this had anything to do with the problem so I've omitted it from the drawing.
The problem I'm having is that the servo just goes through its motions regardless if the pin is HIGH or LOW value. I added the pull up resistor to ensure that i was getting a known voltage, though it hasn't changed the process.
Any tips or advice?
Attached are the drawings and code
Thank you
#include <Servo.h>
Servo feedRoller; //Feed Roller servo, continuous rotation
Servo ticker; //Servo to control the mecahnical arm
int feedRollerPin = 10;
int feedRollerPos = 0;
int speedControl = A0;
int servoSpeed = 0;
int tickerPin = 3;
int tickerPos = 0;
int startTicker = A4;
void setup() {
feedRoller.attach(feedRollerPin);
ticker.attach(tickerPin);
//Step1 take value from potentiometer and map to speed control values
servoSpeed = map(analogRead(speedControl), 0, 1023, 0, 6);
pinMode(speedControl, INPUT);
pinMode(feedRollerPin, OUTPUT);
pinMode(tickerPin, OUTPUT);
pinMode(startTicker, INPUT);
}
void loop()
{
if (startTicker == LOW) {
for (feedRollerPos = 0; feedRollerPos <= 180; feedRollerPos += servoSpeed) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
feedRoller.write(feedRollerPos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (feedRollerPos = 180; feedRollerPos >= 0; feedRollerPos -= servoSpeed) { // goes from 180 degrees to 0 degrees
feedRoller.write(feedRollerPos); // tell servo to go to position in variable 'pos'
}
}
}
