Timer?
anybody can help?
i'm trying program timer function on button hold relay.
so when push button, relay should hold for, 3 seconds , release.
i not want use delay(); because nead other things while program runs!
i'm trying program timer function on button hold relay.
so when push button, relay should hold for, 3 seconds , release.
i not want use delay(); because nead other things while program runs!
code: [select]
#define relaypin 9
#define buttonpin 10
void setup()
{
pinmode(relaypin,output);
pinmode(buttonpin,input_pullup);
}
unsigned long triggertime=0;
void loop()
{
unsigned long t=millis();
//assume relay active low
//(most are)
if ((t-triggertime) > 3000)
digitalwrite(relaypin,high);
if ( digitalread(buttonpin)==low)
{
triggertime=t;
digitalwrite(relaypin,low);
}
}
Arduino Forum > Using Arduino > Programming Questions > Timer?
arduino
Comments
Post a Comment