help with powering solenoids

Hi all,

I have this code (courtesy of larryd) which will monitor the input pins 2,4,6 and if it sees the input, it’ll turn on the output pin 8,10,12 respectively… As of now it’ll make sure only one output is on at a time and it’ll WAIT on the current input pin to turn LOW before it monitors the next input and turns on the respective output. Now there is a small change and I want to make sure it doesn’t wait for the current input to turn low before it switches, instead e.g if input pin 2 is high and input pin 4 gets the signal, output pin 10 should immediately turn high after making output pin 8 low. How can I edit the current code to do that. Thanks

// code courtesy larryd

#define materialNeeded LOW
#define disable true
#define enable false
#define solenoidON HIGH
#define solenoidOFF LOW

const byte Press1 = 2;
const byte Press2 = 4;
const byte Press3 = 6;

const byte Lim1 = 8;
const byte Lim2 = 10;
const byte Lim3 = 12;

const byte heartBeatLED = 13;

byte lastPress1;
byte lastPress2;
byte lastPress3;

bool checkPress1 = enable;
bool checkPress2 = enable;
bool checkPress3 = enable;

//timing stuff
unsigned long switchMillis;
unsigned long heartBeatMillis;

//********************************************************************
void setup()
{
pinMode(Press1, INPUT_PULLUP);
pinMode(Press2, INPUT_PULLUP);
pinMode(Press3, INPUT_PULLUP);

pinMode(Lim1, OUTPUT);
pinMode(Lim2, OUTPUT);
pinMode(Lim3, OUTPUT);

pinMode(heartBeatLED, OUTPUT);

} //END of setup()

//********************************************************************
void loop()
{
//************************
//toggle the Heart Beat LED every 500ms to show the sketch is running
if (millis() - heartBeatMillis >= 500)
{
//restart timer
heartBeatMillis = millis();

//toggle Heart Beat LED
digitalWrite(heartBeatLED, !digitalRead(heartBeatLED));
}

//************************
//time to check the switches?
if (millis() - switchMillis >= 50)
{
//restart timer
switchMillis = millis();

checkSwitches();
}

//************************

} //END of loop()

//********************************************************************
void checkSwitches()
{
byte switchState = 0;

//************************
//Press1 Switch
switchState = digitalRead(Press1);

if (checkPress1 == enable && lastPress1 != switchState)
{
//update to the new state
lastPress1 = switchState;

if (switchState == materialNeeded)
{
digitalWrite(Lim1, solenoidON);

checkPress2 = disable;
checkPress3 = disable;
}

else
{
digitalWrite(Lim1, solenoidOFF);

checkPress2 = enable;
checkPress3 = enable;
}
}

//************************
//Press2 Switch
switchState = digitalRead(Press2);

if (checkPress2 == enable && lastPress2 != switchState)
{
//update to the new state
lastPress2 = switchState;

if (switchState == materialNeeded)
{
digitalWrite(Lim2, solenoidON);

checkPress1 = disable;
checkPress3 = disable;
}

else
{
digitalWrite(Lim2, solenoidOFF);

checkPress1 = enable;
checkPress3 = enable;
}
}

//************************
//Press3 Switch
switchState = digitalRead(Press3);

if (checkPress3 == enable && lastPress3 != switchState)
{
//update to the new state
lastPress3 = switchState;

if (switchState == materialNeeded)
{
digitalWrite(Lim3, solenoidON);

checkPress1 = disable;
checkPress2 = disable;
}

else
{
digitalWrite(Lim3, solenoidOFF);

checkPress1 = enable;
checkPress2 = enable;
}
}
//************************

} //END of checkSwitches

//********************************************************************

This is a duplicate of your topic in the Programming section

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.