im not understanding this i guess i have a 2 axis joy stick using 2 pots for movement of a arm with only 2 pivot points so far but i want to use the if and else and else if example to do something with my 2 pots
i want it to be setup simply like this not sure if i can do what i want this way i hoping i can
if my pot 1 is 0 to 400 turn on relay 10
else \ pot 1 is 400 to 600 delay 500 milliseconds and this free point in the center of the pots travel i want it to do nothing and remain still
else if pot 1 is 600 to 1000 turn on relay 20
now and the end of this part in the loop i want to repeat this code to have it do same actions but check pot 2 and use relays 30 and 40 this time so i can move my left to right and my up and down..
thes code below has soo meany errors its pathetic but im not any good at this soo the code below is what i want to do but i guess i cant set it up this way soo it Wont work HELP !!!!!!
int sensepinState = 0;
int sensorValue = 1;
void setup() {
pinMode(40, OUTPUT);//relay 10 moves arm up
pinMode(42, OUTPUT); //relay 20 moves arm down
pinMode(44, OUTPUT);//relay 30 moves arm left
pinMode(46, OUTPUT); //relay 40 moves arm right
pinMode(50, OUTPUT); // relay relay 50 for voltage polarity swap to toggle fwd and rev of dc motor
Serial.begin(9600);
}
void loop() {
sensepinState = analogRead(0);// read the input pin: of up down pot
if (sensepinState = 0,400 )// compare the sensepin to its previous state then do some thing 1st delay then print to serial
{
Serial.print("sensor = " );
Serial.print(sensorValue);
digitalWrite(50, HIGH);//FWD POLAITY ON RELAY 50
digitalWrite(42, LOW); //MOTOR 2 RELAY OFF
digitalWrite(40, HIGH);//MOTOR 1 RELAY ON
}
else // if the state has changed, increment the steps to leds with the diffrance
{
Serial.print("sensor = " );
Serial.print(sensorValue);
digitalWrite(50, LOW);//REV POLAITY ON RELAY 50
digitalWrite(40, LOW);//MOTOR 1 RELAY OFF
digitalWrite(42, HIGH);//MOTOR 2 RELAY ON
}
else if
{
// kick off any relays left on
digitalWrite(42, LOW); //MOTOR 2 RELAY OFF
digitalWrite(50, LOW);//REV POLAITY ON RELAY 50
digitalWrite(40, LOW);//MOTOR 1 RELAY OFF
delay(500);
}
delay(500); // start read of second pot
{
sensepinValue = analogRead(1);// read the input pin: left right pot
if (sensorValue = 500 )// compare the sensepin to its previous state then do some thing 1st delay then print to serial
{
Serial.print("sensor = " );
Serial.print(sensorValue);
digitalWrite(50, HIGH);//FWD POLAITY ON RELAY 50
digitalWrite(42, LOW); //MOTOR 2 RELAY OFF
digitalWrite(40, HIGH);//MOTOR 1 RELAY ON
}
else // if the state has changed, increment the steps to leds with the diffrance
{
Serial.print("sensor = " );
Serial.print(sensorValue);
digitalWrite(50, LOW);//REV POLAITY ON RELAY 50
digitalWrite(44, LOW);//MOTOR 1 RELAY OFF
digitalWrite(46, HIGH);//MOTOR 2 RELAY ON
}
else if
{
// kick off any relays left on
digitalWrite(46, LOW); //MOTOR 2 RELAY OFF
digitalWrite(50, LOW);//REV POLAITY ON RELAY 50
digitalWrite(44, LOW);//MOTOR 1 RELAY OFF
delay(500);
}
Moderator edit: All-caps thread subject fixed. (Nick Gammon)