Hello
I’m relatively new to the Arduino and its coding.
I am creating an interface between two pieces of equipment and thought an Arduino would be a perfect solution.
Here’s my problem. I have 16 switched inputs which are operated externally. These switches connect to an Arduino Mega. Once the switch has been triggered, the Arduino, stops taking an input from that switch for the next few seconds. The output is 16 relays which only need to be pulsed.
The code I have sort of put together with help from books and the web works great.
BUT… Relay 16 needs to be pulsed 20 seconds AFTER the switch has been pressed not immediately like the others.
How do I do this? Where does the code fit? I know I can’t use the delay functoiun!
Any help will be gratefully received.
Thanks
Bob
const int inputPins[] = {38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53}; // create an array of pins for switch inputs
const int relayPins[] = {22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37}; // create array of output pins for relays
int butpress[16];
int timnow[16];
int timthen[16];
int deltim;
void setup()
{
deltim=5000;
for(int index = 0; index < 16; index++)
{
pinMode(relayPins[index], OUTPUT); // relay as output
pinMode(inputPins[index], INPUT); // switch as input
digitalWrite(inputPins[index],HIGH);
butpress[index]= 0;
timnow[index]=0;
timthen[index]=0;
}
}
void loop(){
for(int index = 0; index < 16; index++)
{
timnow[index]=millis();
if (index ==0)
deltim = 3000; //release time for relay 1
if (index ==1)
deltim = 3000; //release time for relay 2
if (index ==2)
deltim = 3000; //release time for relay 3
if (index ==3)
deltim = 3000; //release time for relay 4
if (index ==4)
deltim = 3000; //release time for relay 5
if (index ==5)
deltim = 3000; //release time for relay 6
if (index ==6)
deltim = 3000; //release time for relay 7
if (index ==7)
deltim = 3000; //release time for relay 8
if (index ==8)
deltim = 3000; //release time for relay 9
if (index ==9)
deltim = 3000; //release time for relay 10
if (index ==10)
deltim = 3000; //release time for relay 11
if (index ==11)
deltim = 3000; //release time for relay 12
if (index ==12)
deltim = 3000; //release time for relay 13
if (index ==13)
deltim = 3000; //release time for relay 14
if (index ==14)
deltim = 3000; //release time for relay 15
if (index ==15)
deltim = 3000; //release time for relay 16
if (timnow[index]-timthen[index]>deltim)
{
butpress[index]=0;
timthen[index]=timnow[index];
}
int val = digitalRead(inputPins[index]); // read input value
if (val == LOW) // check if the switch is pressed
{
if (butpress[index]==0)
{
digitalWrite(relayPins[index], LOW); // turn relay on if switch is pressed
butpress[index]=1;
timthen[index]=timnow[index];
}
}
else
{
digitalWrite(relayPins[index], HIGH); // turn relay off
}
}
}