Originally Posted by
wotnot
I find it's always a contradiction to try and help someone 'learn' something like 'arduino programming', by giving them the answers directly -- it's like solving a rubik cube for someone, they don't learn how to do it.
So I try to be 'helpful' instead - a realistic statement would be, that what you are trying to do here with an arduino, has already been done before by somebodies out there on the 'net, and just to be real here for a moment, your question has little to do with arduino as such, and everything to do with C/C++ coding....and to make matters even more real, all it takes is the correct google search string to find what others have done out there, very similar to what you want to achieve.
Nanos Gigantium Humeris Insidentes -- standing on the shoulders of giants - or with arduino/software in mind, "discovering truth by building on previous discoveries" ; this is the most useful philosophy to embrace with things arduino IMHO, as aligned with a "don't reinvent the wheel" when it comes coding, use (pre-existing) library routines already written by others. This is especially so when it comes to the arduino IDE and the plethora of support libraries (both hardware and software supports) available for it. Perhaps it depends on the individual, I'm not sure...but with the arduino/maker scene, it doesn't make sense to me to start with 'nothing' and have to write the sketch (code) from scratch, when you can find existing code examples and/or library objects, which you can alter to suit your purpose.
I have the idea of what you want to do based on your description, and my brain thinks 'store magic number in eeprom, evaluate keypad input, if = magic number do something, else if * key undo something, else if # key do something different' ...but then my mind says 'stop wasting time, google it', and I end up seeing ....and I think that's close sans the LCD stuff which is easily removed, and pretty much everything's done except the hash key handling (which in that sketch is doing the changecode() function) ...but in any event, it's a good (working) example of how to do this. In practice, you'd just remap that function to a different keypress, and add another handler for the # key detection, which would be the function to blink the 3rd LED and de-energize the relay after 60seconds.
Regarding timers...I recently had a boofle with esp8266 calling millis() inside of loop() for reasons unknown (but I'm not alone), and ended up finding/using the BlockNot library () for timing events. It has a nonblocking LED example you can use to blink the LED. You could stuff that into the # key handler function.... ie; initialize a blocknot 1 second timer in setup(), in a while{} condition, count the blocknot 'ticks' and blink the LED until count reaches 60, then you could use getpinstate(relaypin) to determine if it's on or not, and turn it off if it's on.
That's just me though, lazy as, determined to use code objects that already exist, and use them like templates, lego blocks, to build what I want. Also, there's some pretty groovy arduino simulator software out there, where you can drag&drop block functions (like in that program flowchart in the link above), assign the values, and it generates the code for you, which you can then simulate and/or upload the the arduino, cool stuff.
End of the day though, I can get the above code, strip out the LCD stuff, do the above mumbojumbo for hash key handling and paste it here, and it'll likely work, but how useful is that? You should want to do this -- I don't want to 'spoil' your learning curve by proffering a solution based upon others' examples, when you might be more interested in learning this stuff 'from the ground up' kinda thing, and there's absolutely nothing wrong with that at all, that's a good thing, but I'm not a good teacher, I'm more of a doer, hackityhack 8)
Bookmarks