Hi guys
I have made a 3 axis joystick controller, attached to an UNO board and an 8x relay board to operate my tractor mounted hedge cutter.
I previously had help from here on setting up the IF function and that has got me able to use it, however, there is a random glitch that I cant seem to get to the bottom of.
so the joystick controls 7 functions:
6 hydraulic directional valves
1 hydraulic lock/dump valve
when ever 1 or more of the 6 directional valves open, I also need to open the lock/dump vale simultaneously
there is also provision in the code for a push button to operate a separate function but I have not set that up yet, so we can ignore that for now.
the problem is - randomly - the lock/dump is not activated. This might happen 1 in 30 joystick movements, or it might happen 4 times in a row - either way it is a problem as the machine doesn't function when it happens.
it does appear to get worse with time - the longer I work the machine, the more frequently the problem occurs
I have adjusted the switching positions of the joystick and also the loop rate to see if that makes a difference, but it hasn't.
I have marked the code that I think is the issue with // notes - its at the bottom of the code.
#define joyX A0;
#define joyY A2;
#define joyZ A5;
int pbuttonPin = 2;
int relayPin = 12;
int val = 0;
int lightON = 0;
int pushed = 0;
void setup() {
Serial.begin(9600);
pinMode(pbuttonPin, INPUT_PULLUP);
pinMode(relayPin, OUTPUT); //diverter valve to swap to swing control
pinMode (11, OUTPUT); // hydraulic boom down
pinMode (10, OUTPUT); // hydraulic boom up
pinMode (9, OUTPUT); // hydraulic boom in
pinMode (8, OUTPUT); // hydraulic boom out
pinMode (7, OUTPUT); // rotor head rotate
pinMode (6, OUTPUT); // rotor head rotate
pinMode (4, OUTPUT); // hydraulic oil dump valve - must be open when any other function is in use
}
void loop() {
val = digitalRead(pbuttonPin);
if(val == HIGH && lightON == LOW){
pushed = 1-pushed;
delay(100); }
lightON = val;
if(pushed == HIGH){
Serial.println("Light ON");
digitalWrite(relayPin, LOW);
}else{
Serial.println("Light OFF");
digitalWrite(relayPin, HIGH);
}
int xValue = analogRead(A0);
int yValue = analogRead(A2);
int zValue = analogRead(A5);
if ( xValue > 550)
{digitalWrite(11, HIGH);}
else{digitalWrite(11, LOW);}
if ( xValue < 470)
{digitalWrite(10, HIGH);}
else{digitalWrite(10, LOW);}
if ( yValue > 550)
{digitalWrite(9, HIGH);}
else{digitalWrite(9, LOW);}
if ( yValue < 470)
{digitalWrite(8, HIGH);}
else{digitalWrite(8, LOW);}
if ( zValue > 550)
{digitalWrite(6, HIGH);}
else{digitalWrite(6, LOW);}
if ( zValue < 470)
{digitalWrite(7, HIGH);}
else{digitalWrite(7, LOW);}
if (digitalRead(6) || digitalRead(7) || digitalRead(8) || digitalRead(9) || digitalRead(10) || digitalRead(11)) {
digitalWrite(4, LOW);} // This is the part that I think is causing the issue.
else {
digitalWrite(4, HIGH);} // would anyone know a better way of coding it?
delay(50);
}
thanks in advance guys