1

I'm writing a garage door opener and monitor.

The monitor receives the door status via another Arduino over RF (315 MHz). The code below works, but I feel that I shouldn't need to check the status every time I make a request to the server to open the door. Is there a way to split the code out so that I check the door status every 20 seconds, and the opening and closing of the garage are on demand?

Here is the code: https://github.com/dhysong/ArduinoGarageOpener/blob/master/src/GarageDoorOpener/GarageDoorOpener.ino

5
  • 2 down votes with now comment. Does no one else think this might be a valid question? I guess I must have offended the SO gods! Commented Sep 30, 2012 at 18:51
  • Don't you think you should ask the author of the project? Commented Sep 30, 2012 at 19:00
  • 1
    I don't understand, I am the author. I didn't downvote my own post. Commented Sep 30, 2012 at 19:05
  • Oups, my bad, I didn't notice that! I didn't vote down your post, though... Commented Sep 30, 2012 at 19:13
  • You might be better off posting to the arduino forums (arduino.cc/forum). That community is huge + very friendly. Commented Oct 2, 2012 at 0:04

1 Answer 1

2

Based on this post: http://arduino.cc/forum/index.php/topic,5686.0.html

I was able to add a mult-threading like capability to my app. Source code has been updated to reflect the change.

Here's the pertinent piece:

boolean cycleCheck(unsigned long *lastMillis, unsigned int cycle) 
{
  unsigned long currentMillis = millis();
  if(currentMillis - *lastMillis >= cycle)
{
  *lastMillis = currentMillis;
  return true;
 }
else
  return false;
}

Here's the github code for anyone that might benefit: https://github.com/dhysong/ArduinoGarageOpener/blob/master/src/GarageDoorOpener/GarageDoorOpener.ino

Sign up to request clarification or add additional context in comments.

4 Comments

I just looked at: arduino.cc/playground/Code/Interrupts, and I'm not clear on how this would solve my problem. Could you please elaborate or provide some example source code? thanks, Drew
Take a look at a blog post I wrote some time ago: blog.3d-logic.com/2012/08/26/… In the project I use interrupts to get correct timing for my clock. The source is on github - you can find the link in the post.
Thanks Pawel. I'll take a look when I get a chance (this is all hobby) and see if I can't improve on this thread.
So did you end up using interrupts drew?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.