So i'm trying to set the state of and actuator "SurfLeftDeployed" i'm setting it to false to start the code but in my loop at the bottom when i trigger the input it just keeps cycling thru the same sequence when the input is high and when the input(SurfLeft) is low. Am i not setting the state of SurfLeftDeployed properly.
thanks in advance.
////variable declaration
// selection pins on which are connected to the Selector
//int pinsSelectorPosAuto = 28;
//int pinsSelectorPosManu = 29;
const int pinSurfRight = 4;
const int pinSurfLeft = 5;
const int RelayGateRight = 6;
const int RelayGateRetRight = 7;
const int RelayGateLeft = 8;
const int RelayGateRetLeft = 9;
//int relayAlimFeuStar = 33;
//int relayAlimFiresUnderMarin = 34;
//int pinsremotecontrolLight = 35;
//int pinsMaliviewLightTour = 36;
//int pinsMaliviewLightUnderMarin = 37;
//int pinsremotecontrolSurfgate = 39; // probably a wiring error when the 2 inputs are inverted so that it matches the good buttons on the remotecontrol.
//int pinsremotecontrolCoteSurfgate = 38; // probably a wiring error when the 2 inputs are inverted so that it matches the good buttons on the remotecontrol.
int SurfRight = 0;
int SurfLeft = 0;
int SurfLeftOn = 0;
int SurfRigthOn = 0;
int SurfLeftDeploy = 0;
int SurfRightDeploy = 0;
bool SurfLeftDeployed = false;
//const int SurfRightDeployed = 11;
int speedhigh = 0;
int speedlow = 0;
void setup() {
gpsSerial.begin(9600);
delay(1000);
pinMode(pinSurfRight, INPUT);
pinMode(pinSurfLeft, INPUT);
pinMode(RelayGateRight, OUTPUT);
pinMode(RelayGateRetRight, OUTPUT);
pinMode(RelayGateLeft, OUTPUT);
pinMode(RelayGateRetLeft, OUTPUT);
//pinMode(SurfLeftDeployed, OUTPUT);
//pinMode(SurfRightDeployed, OUTPUT);
}
void displayGPS( gps_fix & fix )
{
int mph = 0;
int speedhigh = 0;
int speedlow = 0;
// Print speed
if (fix.valid.speed && (fix.spd.whole > 5)) {
mph = (fix.spd.whole * 115) / 100;
}
Serial.print( mph );
Serial.print( (" mph ") );
if (mph < 15)
speedhigh = 1;
else
speedhigh = 0;
if (mph > 7)
speedlow = 1;
else
speedlow = 0;
} // displayGPS
void loop()
{
SurfRight=digitalRead(pinSurfRight);
SurfLeft=digitalRead(pinSurfLeft);
/*while (gps.available( gpsSerial )) { // if there is data coming from the GPS shield
gps_fix fix = gps.read(); // get the complete fix structure
displayGPS( fix ); // Show pieces of the fix on Serial
}*/
//SURF LEFT LOGIC
//if (speedhigh = true) && (speedlow == true)
if (SurfLeft == HIGH)
{
if (SurfLeftDeployed == false);{
digitalWrite(RelayGateRight, HIGH);
delay(3000);
digitalWrite(RelayGateRight, LOW);
SurfLeftDeployed = true;}
}
if (SurfLeft == LOW)// or speedhigh == 0 or speedlow == 0)
{
if(SurfLeftDeployed == true);
{digitalWrite(RelayGateRight, HIGH);
digitalWrite(RelayGateRetRight, HIGH);
delay(3000);
digitalWrite(RelayGateRight, LOW);
digitalWrite(RelayGateRetRight, LOW);
SurfLeftDeployed = false;}}
so now the issue appears to be that it constantly cycles thru both of the bottom rungs when SURFLEFT is off when SURFLEFT is on it deploys and stops after 3 seconds but if i take power off the pin it just constantly moves in for 3 seconds then out for 3 seconds.
so i just did a test and swapped the low and high in the if statements. and it acts the same way if there is no power on pin 5 it cycles in and out like there is noise on it or something. Is there an easy way to debounce it when its low or to make sure its really 0 or make sure its fully 5v before arduino does a step.
inverted the input to pull it up and will just ground it to turn it on and it now functions properly. Likely was noise on the input when "low" is all i can come up with thoughts?
////variable declaration
// selection pins on which are connected to the Selector
//int pinsSelectorPosAuto = 28;
//int pinsSelectorPosManu = 29;
const int pinSurfRight = 4;
const int pinSurfLeft = 5;
const int RelayGateRight = 6;
const int RelayGateRetRight = 7;
const int RelayGateLeft = 8;
const int RelayGateRetLeft = 9;
//int relayAlimFeuStar = 33;
//int relayAlimFiresUnderMarin = 34;
//int pinsremotecontrolLight = 35;
//int pinsMaliviewLightTour = 36;
//int pinsMaliviewLightUnderMarin = 37;
//int pinsremotecontrolSurfgate = 39; // probably a wiring error when the 2 inputs are inverted so that it matches the good buttons on the remotecontrol.
//int pinsremotecontrolCoteSurfgate = 38; // probably a wiring error when the 2 inputs are inverted so that it matches the good buttons on the remotecontrol.
int SurfRight = 0;
int SurfLeft = 0;
int SurfLeftOn = 0;
int SurfRigthOn = 0;
int SurfLeftDeploy = 0;
int SurfRightDeploy = 0;
bool SurfLeftDeployed = false;
//const int SurfRightDeployed = 11;
int speedhigh = 0;
int speedlow = 0;
void setup() {
gpsSerial.begin(9600);
delay(1000);
pinMode(pinSurfRight, INPUT);
pinMode(pinSurfLeft, INPUT_PULLUP);
pinMode(RelayGateRight, OUTPUT);
pinMode(RelayGateRetRight, OUTPUT);
pinMode(RelayGateLeft, OUTPUT);
pinMode(RelayGateRetLeft, OUTPUT);
//pinMode(SurfLeftDeployed, OUTPUT);
//pinMode(SurfRightDeployed, OUTPUT);
}
void displayGPS( gps_fix & fix )
{
int mph = 0;
int speedhigh = 0;
int speedlow = 0;
// Print speed
if (fix.valid.speed && (fix.spd.whole > 5)) {
mph = (fix.spd.whole * 115) / 100;
}
Serial.print( mph );
Serial.print( (" mph ") );
if (mph < 15)
speedhigh = 1;
else
speedhigh = 0;
if (mph > 7)
speedlow = 1;
else
speedlow = 0;
} // displayGPS
void loop()
{
SurfRight=digitalRead(pinSurfRight);
SurfLeft=digitalRead(pinSurfLeft);
/*while (gps.available( gpsSerial )) { // if there is data coming from the GPS shield
gps_fix fix = gps.read(); // get the complete fix structure
displayGPS( fix ); // Show pieces of the fix on Serial
}*/
//SURF LEFT LOGIC
//if (speedhigh = true) && (speedlow == true)
if (SurfLeft == LOW){
if (SurfLeftDeployed == false){
digitalWrite(RelayGateRight, HIGH);
delay(4000);
digitalWrite(RelayGateRight, LOW);
SurfLeftDeployed = true;}
}
if (SurfLeft == HIGH) {
if (SurfLeftDeployed == true) {
digitalWrite(RelayGateRight, HIGH);
digitalWrite(RelayGateRetRight, HIGH);
delay(4500);
digitalWrite(RelayGateRight, LOW);
digitalWrite(RelayGateRetRight, LOW);
SurfLeftDeployed = false;}}
they were different b/c i was just testing using the left side ... they are both the same now. thanks for your help it works amazingly well just took it for a spin the car to test the speed deployment with GPS and it works great. no issues anymore now that i'm pulling that up to 5V and then grounding it for the input.