ok ill try this again. the set up is a 5 position position filter wheel driven by a continuous run servo(pin9) with a switch that goes LOW (pin2)when it is at filter one. what i am trying to get is
at power up (only!)
run servo motor till HomePin (pin2) goes low
then set CurrentFilter to 1
i have removed all my code that tried to do this so you can see the bassic code. and maybe come up with something that will work. thanks.
// ducks filter wheel
#include <Servo.h>
Servo myservo;
int CurrentFilter = 0; //current filter pisition
int HomePin = 2; //home position switch
int PositionPin = 3; //position switch for changing filters
void setup()
{
Serial.begin(19200);
Serial.flush();
pinMode(HomePin, INPUT);
pinMode(PositionPin, INPUT);
myservo.attach(9);
myservo.writeMicroseconds(1498);
}
void loop()
{
String cmd;
if (Serial.available() >0) {
cmd = Serial.readStringUntil('#');
if (cmd=="GETFILTER") {
Serial.print(CurrentFilter);
Serial.println("#");
}
else if (cmd=="FILTER1") MoveFilter(1);
else if (cmd=="FILTER2") MoveFilter(2);
else if (cmd=="FILTER3") MoveFilter(3);
else if (cmd=="FILTER4") MoveFilter(4);
else if (cmd=="FILTER5") MoveFilter(5);
}
}
void MoveFilter(int pos)
{
delay(2000);
CurrentFilter = pos;
Serial.println("0#");
}
void homeset()
{
}