Pages: [1]   Go Down
Author Topic: relay activation  (Read 513 times)
0 Members and 1 Guest are viewing this topic.
Scotland
Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all, firstly, im glad to be part of the site

So here is my question,

if i am trying to close a relay when i recieve a digital pulse but keep it closed if i recieve the pulse again <= 1 second how would i go about that???


cheers
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

fast and dirty do a 
delay (1000);
after you close it, just remember your arduino will pause during that 1000ms (1sec)


Logged

Scotland
Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, will give it a go!!!
Logged

Scotland
Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey it worked, great , thanks

rgds
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
fast and dirty do a
delay (1000);
Even better, of course, is to use millis() to record when you turned the relay on, and ignore any requests to turn the relay on again unless the time between the new request and the old (successful) request is greater than the threshold. Look at the blink without delay example.

For why, suppose that the time was 1 hour, instead of 1 second, and the Arduino was displaying the time, too.

Using millis(), the Arduino would continue to display the time. Using delay() it would not.
Logged

Scotland
Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK ill try that aswell, seems a bit more refined, but to be honest, the timing is fine at the mo and its giving the results,though getting the feeling that could be problems later on,

thx
Logged

Pages: [1]   Go Up
Jump to: