switches and relays and delays but not delays!
hello
i'm relatively new arduino , coding.
i creating interface between 2 pieces of equipment , thought arduino perfect solution.
here's problem. have 16 switched inputs operated externally. these switches connect arduino mega. once switch has been triggered, arduino, stops taking input switch next few seconds. output 16 relays need pulsed.
the code have sort of put books , web works great.
but… relay 16 needs pulsed 20 seconds after switch has been pressed not others.
how do this? where code fit? know can't use delay functoiun!
any gratefully received.
thanks
bob
i'm relatively new arduino , coding.
i creating interface between 2 pieces of equipment , thought arduino perfect solution.
here's problem. have 16 switched inputs operated externally. these switches connect arduino mega. once switch has been triggered, arduino, stops taking input switch next few seconds. output 16 relays need pulsed.
the code have sort of put books , web works great.
but… relay 16 needs pulsed 20 seconds after switch has been pressed not others.
how do this? where code fit? know can't use delay functoiun!
any gratefully received.
thanks
bob
code: [select]
const int inputpins[] = {38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53}; // create array of pins 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 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 output
pinmode(inputpins[index], input); // switch 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 relay 1
if (index ==1)
deltim = 3000; //release time relay 2
if (index ==2)
deltim = 3000; //release time relay 3
if (index ==3)
deltim = 3000; //release time relay 4
if (index ==4)
deltim = 3000; //release time relay 5
if (index ==5)
deltim = 3000; //release time relay 6
if (index ==6)
deltim = 3000; //release time relay 7
if (index ==7)
deltim = 3000; //release time relay 8
if (index ==8)
deltim = 3000; //release time relay 9
if (index ==9)
deltim = 3000; //release time relay 10
if (index ==10)
deltim = 3000; //release time relay 11
if (index ==11)
deltim = 3000; //release time relay 12
if (index ==12)
deltim = 3000; //release time relay 13
if (index ==13)
deltim = 3000; //release time relay 14
if (index ==14)
deltim = 3000; //release time relay 15
if (index ==15)
deltim = 3000; //release time 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 switch pressed
{
if (butpress[index]==0)
{
digitalwrite(relaypins[index], low); // turn relay on if switch pressed
butpress[index]=1;
timthen[index]=timnow[index];
}
}
else
{
digitalwrite(relaypins[index], high); // turn relay off
}
}
}
a loop iterates 16 times, doing 16 different things, wrong.
i don't understand timthen , timnow arrays. difficult spell out time? 3 letter abbreviation 4 letter word lazy.
neither array appears hold time, since there no calls millis(), micros(), or rtc.
millis() , micros() return unsigned longs, since in our universe times not move backwards. move forwards , backwards in yours?
i don't understand timthen , timnow arrays. difficult spell out time? 3 letter abbreviation 4 letter word lazy.
neither array appears hold time, since there no calls millis(), micros(), or rtc.
millis() , micros() return unsigned longs, since in our universe times not move backwards. move forwards , backwards in yours?
Arduino Forum > Using Arduino > Programming Questions > switches and relays and delays but not delays!
arduino
Comments
Post a Comment