need a bit of help please

hi nearly done writing my first code but got stuck at the end trying to work out how i can make the second if statement only blip the mossfet pin once and not reset again until analog values return to the fired state

const int linearChipsPin = A0; // declaring in put for linear actuator to be arduinoA going to ao on arduinoB

const int mossfetPin = 9; // declaring mossfet out put pin from arduino b to be pin d9

const int hallbPin = A2; // declaring in put for hallback sens from trigger of controller

const int autoPin = A4; // declaring rotary switch auto pos to pin a4

const int semPin = A6; // declaring semi auto pin for rotary switch a5

void setup() {

pinMode(mossfetPin, OUTPUT);
Serial.begin(115200);

}

void loop() {

int hallValue = analogRead(hallbPin); // declaring hallValue = analog read of hallback sensor on pin 9

analogRead(hallbPin); // declaring analog read of hallPin

int linValue = analogRead(linearChipsPin); // declaring linvalue = analog read off linear actuator on pin a0

analogRead(linearChipsPin); // declaring analog read of linearChipsPin A0

int autoValue = analogRead(autoPin); // declaring autoPin = AutoValue

analogRead(autoPin); // declaring analog read off Auto pin

int semValue = analogRead(semPin); // declaring semValue = analog read of semPin

analogRead(semPin); // declaring analog read of sem pin

if ( hallValue < 180 && (autoValue > 500) && (linValue > 250) )
{
digitalWrite(mossfetPin, HIGH);
delay(50);
digitalWrite(mossfetPin,LOW);
delay(50);
} else {
digitalWrite(mossfetPin, LOW);
}

if ( hallValue < 180 && (semValue > 500) && (linValue > 250) )
{
digitalWrite(mossfetPin, HIGH);
delay(50);
digitalWrite(mossfetPin,LOW);
delay(10000);
} else {
digitalWrite(mossfetPin, LOW);
}

Serial.println(semValue);
delay(1);
}

Your codes are slightly revised and posted below; compare these codes with your original codes and judge if the changes make sense.

const int linearChipsPin = A0;  // declaring in put for linear actuator to be arduinoA going to ao on arduinoB

const int mossfetPin = 9;   //  declaring mossfet out put pin from arduino b to be pin d9

const int hallbPin = A2;   //  declaring in put for hallback sens from trigger of controller

const int autoPin = A4;  // declaring rotary switch auto pos to pin a4

const int semPin = A6; // declaring semi auto pin for rotary switch a5

void setup()
{

  pinMode(mossfetPin, OUTPUT);
  Serial.begin(115200);

}

void loop()
{

  int hallValue = analogRead(hallbPin);   // declaring hallValue = analog read of hallback sensor on pin 9

 // analogRead(hallbPin);                 // declaring analog read of hallPin

  int linValue = analogRead(linearChipsPin);  // declaring linvalue = analog read off linear actuator on pin a0

 // analogRead(linearChipsPin);           // declaring analog read of linearChipsPin A0

  int autoValue = analogRead(autoPin);   // declaring autoPin = AutoValue

  //analogRead(autoPin);    // declaring analog read off Auto pin

  int semValue = analogRead(semPin); // declaring semValue = analog read of semPin

 // analogRead(semPin);  // declaring analog read of sem pin




  if ( hallValue  < 180 && (autoValue > 500) && (linValue  > 250) )
  {
    digitalWrite(mossfetPin, HIGH);
    delay(50);
   // digitalWrite(mossfetPin, LOW);
   // delay(50);
  } 
  else 
  {
    digitalWrite(mossfetPin, LOW);
  }

  if ( hallValue  < 180 && (semValue > 500) && (linValue  > 250) )
  {
    digitalWrite(mossfetPin, HIGH);
    delay(50);
    //digitalWrite(mossfetPin, LOW);
    //delay(10000);
  } 

  else 
  {
    digitalWrite(mossfetPin, LOW);
  }

  
  Serial.println(semValue);
  delay(1);
}

thanks for the reply, not to sure i do understand still isnt doing my program intent tho in the firs if if the varibles are met it should blip the mossfet until the retern back to there normal state and in the second if , if the varibles are met im trying to get it to only bllip once apoligies for the spelling school wasnt my thing.

Imagine you have a variable:

boolean shouldBlipMosfetThisTime = false;

and you can set it to true or false at any point in your code. And you can test it in an if statement wherever. Can you envision how to use that to get what you want?

jordo22233: school wasnt my thing.

A piss poor excuse...

Delta_G: boolean shouldBlipMosfetThisTime = false;

Is there any good reason to prefer boolean to bool when both can be used interchangeably in Arduino IDE?

thanks :slight_smile:

const int linearChipsPin = A0; // declaring in put for linear actuator to be arduinoA going to ao on arduinoB

const int mossfetPin = 9; // declaring mossfet out put pin from arduino b to be pin d9

const int hallbPin = A2; // declaring in put for hallback sens from trigger of controller

const int autoPin = A5; // declaring rotary switch auto pos to pin a4

const int semPin = A6; // declaring semi auto pin for rotary switch a5

int currVal = 0;
int prevVal = 0;
bool setPinHigh = false;
unsigned long startTime = 0;
unsigned long onTime = 0;

void setup() {

pinMode(mossfetPin, OUTPUT);
Serial.begin(115200);

}

void loop() {

int hallValue = analogRead(hallbPin); // declaring hallValue = analog read of hallback sensor on pin 9

analogRead(hallbPin); // declaring analog read of hallPin

int linValue = analogRead(linearChipsPin); // declaring linvalue = analog read off linear actuator on pin a0

analogRead(linearChipsPin); // declaring analog read of linearChipsPin A0

int autoValue = analogRead(autoPin); // declaring autoPin = AutoValue

analogRead(autoPin); // declaring analog read off Auto pin

int semValue = analogRead(semPin); // declaring semValue = analog read of semPin

analogRead(semPin); // declaring analog read of sem pin

//(linValue > 250

if ( hallValue < 180 && autoValue > 500 && linValue > 500)
{
digitalWrite(mossfetPin, HIGH);
delay(50);
digitalWrite(mossfetPin,LOW);
delay(50);
} else {
digitalWrite(mossfetPin, LOW);
}

if(semValue > 500 && linValue > 300 && prevVal <= 300 && hallValue < 180)
{
digitalWrite(mossfetPin, HIGH);
setPinHigh = true;
delay(50);
}
else
{
setPinHigh = false;
}

if(setPinHigh && millis() - startTime < onTime)
{
digitalWrite(mossfetPin, HIGH);
}
else
{
digitalWrite(mossfetPin, LOW);
setPinHigh = false;
}

prevVal = linValue;

Serial.println(semValue);
delay(1);
}

Please use code tags. Read the forum rules if you don't know what that means. You should have read that before you started posting.