G+_Sean Miller Posted February 1, 2018 Share Posted February 1, 2018 Arduino 20 minute Script I want to design an Arduino (maybe a Raspberry Pi, but I want it to be more robust and fast booting) that will run a script over 20 minutes. At 1 minute activate these relays, at 2 minutes activate these other relays, etc. The script would be activated by pressing a start button, so not based on time-of-day. I'd need the script to be pausable, resettable, etc. My question is what is the best way to walk through a script over twenty minutes and still keep it interruptible and pausable. Would a RTC jerry rigged to not keep time-of-day work? How would I pause it? Thank you very much for your time. Sean Link to comment Share on other sites More sharing options...
G+_Jason Perry Posted February 1, 2018 Share Posted February 1, 2018 I have always wondered how to make a full system with the fastest boot time possible. An Arduino would be the fastest; but, I have thought about a light weight full system with a display for a while. Link to comment Share on other sites More sharing options...
G+_Matt Koglin Posted February 1, 2018 Share Posted February 1, 2018 Check out Arduino interrupts. They allow you to specify a pin or pins that, when changed, interrupt the main loop and perform a specific operation, after which looping continues. playground.arduino.cc - Arduino Playground - Interrupts There are likely some examples published code that does most of what you need! Good luck! Link to comment Share on other sites More sharing options...
G+_Sean Miller Posted February 1, 2018 Author Share Posted February 1, 2018 But I have a lot of interesting side ideas about hooking up an lcd display to display the time, etc. If I use an ESP8266, then I could link to it via webpage and edit the script, but that's a whole other ball of wax I'm not ready to dive into yet. Link to comment Share on other sites More sharing options...
G+_Jim Hofmann Posted February 1, 2018 Share Posted February 1, 2018 If I don't have a clear understanding of what's needed, I usually start with pseudo code. Then add real code. define/init variables & constants if a Button Pushed then startTime = millis() if millis() - startTime > 1000 then relay1 = on else relay1 off or maybe relay1 = millis() - startTime > 1000 So this is where I'd start but the best thing is just jump in, the water's fine. :) Link to comment Share on other sites More sharing options...
G+_Sean Miller Posted February 1, 2018 Author Share Posted February 1, 2018 millis()...that sounds very promising. THank you very much. Link to comment Share on other sites More sharing options...
G+_Matt Koglin Posted February 1, 2018 Share Posted February 1, 2018 Start small and increase in difficulty as your frustration decreases :) If this is all new, you will certainly run into difficulties but know that Google is always there to help! Link to comment Share on other sites More sharing options...
G+_Ben Reese Posted February 2, 2018 Share Posted February 2, 2018 The Arduino's built in clock may be accurate enough for your needs. I haven't done too much testing, but in the little bit that I have done it seemed adequate. I used an nRF24L01 chip to talk to a Pi and get the time, then used AES encryption to send the time back to the Pi. All just proof of concept stuff and I only let it run for a few days. But it worked! I agree that using variables to store your times and letting the loop keep running is better than pausing for 20 minutes, or whatever. I used that method a few years ago for a refrigerator door alarm (tones at 30 and 45 seconds open then constant beep at 60). Link to comment Share on other sites More sharing options...
G+_Paul Hutchinson Posted February 2, 2018 Share Posted February 2, 2018 Ben Reese the built-in oscillator is almost certainly accurate enough for such short period time keeping. A resonator will typically be within 0.5% and a crystal within to 0.01%. It's only long run timing that needs a more accurate clock e.g. 0.0002% = 1 minute/year. Link to comment Share on other sites More sharing options...
G+_Sean Miller Posted February 2, 2018 Author Share Posted February 2, 2018 Thank you very much. I think millis() combined with interrupt functions should work okay. Now that I have an idea of what I'm doing, I'm off to the races. Link to comment Share on other sites More sharing options...
Recommended Posts