![]() In 'State 2', you check the time, and if it goes beyond X seconds, you go to 'State 3'. One suggestion here is to use a "state machine", so that upon a switch transition, you get 'State 1' in that state, a timer starts, and puts you in 'State 2'. PinMode(RELAY2_SHUTS_DOWN_BLINDS, OUTPUT) ĮlapsedMillis timeElapsedSinceCloseButtonPush = 0 ĮlapsedMillis timeElapsedSinceOpenButtonPush = 0 ĭigitalWrite(RELAY2_SHUTS_DOWN_BLINDS, RELAY_ON) ĭigitalWrite(RELAY1_TURNS_ON_BLINDS, RELAY_ON) Here is my current code: #include ĭigitalWrite(RELAY1_TURNS_ON_BLINDS, RELAY_OFF) ĭigitalWrite(RELAY2_SHUTS_DOWN_BLINDS, RELAY_OFF) ![]() However even though I could work the relays without the 30 second limitation, I couldn't figure out the code to end working of the relays. I have been trying to use elapsedMillis library for this, which is a nice library that helps me avoid using Delays: Similarly I want to turn on Relay#2 for exactly 30 seconds if I toggle the switch up from centerĪnd when I switch back to center, I would like the timer to reset. In other words, relay turns on when I switch, and when timer reaches 30 seconds relay turns off. I want to turn on Relay#1 for a maximum of 30 seconds if I toggle the switch down from center. I have a simple ON-OFF-ON switch, attached to an Arduino connected to Relays. I'm trying to do a blinds automation at home. Function to disable a TIMER, ex: myTimer.Briefly: I would like to turn on a relay for 30 seconds, after I toggle a switch on. initialize lastTime to current millis() or micros() Function to enable and initialize a TIMER, ex: myTimer.EnableTimer() this TIMER did not expire or it is disabled If (EnableFlag = true & currentTime - StartTime >= Interval) is the TIMER enabled and has the TIMER expired? TimerType = use ms or us timing, MILLIS/true = millis(), MICROS/false = micros() EnableFlag = is TIMER enabled/allowed to be accessed Restart = do we restart TIMER automatically Interval = interval/delay we are looking for StartTime = the time TIMER was (re)started Delay time expired function "CheckTime()" MakeTimer(unsigned long ST, unsigned long INT, bool RES, bool ENA, bool TT) myTimer.CheckTime() and myTimer.EnableTimer() and myTimer.DisableTimer() You have the following class functions: myTimer.StartTime, myTimer.Interval, myTimer.Restart, myTimer.EnableFlag and myTimer.TimerType Each TIMER object is made up of 5 variables: 0, 200UL, true, true, MILLIS //StartTime, Interval, Restart, EnableFlag, TimerType (MILLIS/MICROS) makeTimer myTimer = //create a Timer named "myTimer" TimerType = true/MILLIS = millis(), false/MICROS = micros() EnableFlag = is "this TIMER" enabled/allowed to be accessed ![]() Restart = do we start "this TIMER" again and again Interval = Interval/delay time we are looking for StartTime = the time this "TIMER" was (re)started Note: since code takes time to execute, precise micro second timing is difficult. #define isRELEASED HIGH //INPUT_PULLUP-pin-GND #define isPUSHED LOW // ~50k normally open #define noCHANGE -1 //there was no change in switch state It does not use an RTC, it just uses the millis() technique BWD for timing. Here is a skeleton sketch I often use when a new sketch is started. Lots of volunteers will help, but you need to put effort into learning.Īn RTC (ex: DS3231) is something that is needed for accurate time of day operations. ![]() ![]() Could you please help.Ĭonst unsigned long eigth = 8UL 36001000 I had written a code but I'm unable to retrieve the required output, I figure it might be the Delay function and I should refer the Blink without Delay but I'm unable to get it. Then from 16:00:00 to 24:00:00 Rela圓 and Relay1 should be HIGH and Relay2 should be LOW and so on for about 999 Days. Then from 08:00:00 to 16:00:00 Relay2 and Rela圓 should be HIGH and Relay1 should be LOW and Now, beginning at 00:00:00 Relay1 and Relay2 should be HIGH for eight hours i.e. For clear understanding naming relays as Relay1, Relay2 and Rela圓 I have three 5v relays which I want to operate in 8 hours interval daily which means any two out of the three would be active at any point of time in a day. I very recently have started tinkering around and am unaware of most of the technicalities, ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |