jilowalker.blogg.se

Arduino millis inside interrupt
Arduino millis inside interrupt






attachInterrupt(digitalPinToInterrupt(2), countBounce, RISING) Enable External Interrupt Request 0 on pin 2

arduino millis inside interrupt

Arduino millis inside interrupt code#

Any help would be greatly appreciated.OP's code where folks can see it and he might actually get a response. I am not interested in debouncing buttons etc at the minute I really am trying to focus on having the wait and run part working. Basicallly trying to run the fan on and off for set peroids of time selected by button inputs and displayed on the LCD. I am at a stage now where I believe the code will be a bit easier to follow. Work to get your buttons working correctly (printing little things) in an easy-to-understand, logical sequence then add in the other stuff. If(millis() - lastMillis > pressInterval and nowState = HIGH) If(millis() - lastMillis pressInterval) // a long press SimplePress::SimplePress(int _pin, uint32_t _pressInterval, uint32_t _debouncePeriod) SimplePress(int _pin, uint32_t _pressInterval, uint32_t _debouncePeriod = 200) Header "SimplePress.h" #ifndef SIMPLEPRESS_H abstract the button presses into a single function that returns a bool or use a simple library. Is that it doesn't account for a change in state, and it will likely react poorly in case of bounce. Total beginner at this obviously I would like to get this working though #include ĪttachInterrupt(digitalPinToInterrupt(2),stopSequence, RISING) If ((fanSpeed>0) & (currentMillis - previousMillis2 >= onTimer))Įlse if((fanSpeed=0) & (currentMillis - previousMillis2 >= offTimer))ĪnalogWrite(fan,fanSpeed) //run the fan continuously if no time is selectedĪm I heading in the right direction now before I go any further? If (offHours 0) & (currentMillis - previousMillis >= waitTime)) WaitTime=600000 //wait 1 minute before begining cycle Long waitTime=5000 //wait until user has selected an on off cycle before carrying it outĪttachInterrupt(digitalPinToInterrupt(3),button2_ISR, RISING) Int offHours=0 //to convert to hours for lcd Int onHours=0 //to convert to hours for lcd

arduino millis inside interrupt

Volatile int timerCount = 0 //is the timer in use Volatile int onCount = 0 //used to switch between hours and minutes

arduino millis inside interrupt

Unsigned long previousMillis = 0 //remember millis Volatile int offTime = 15 //off time in mins Volatile int onTime = 0 //on time in mins Volatile int percent = 0 //percentage of fan speed to show on lcd Int onOff = 0 //if the fan is running or not Int fanStart = 220 //start up cyclespeed for motor

arduino millis inside interrupt

I posted yesterday and took the comments on board and changed from minutes and hours to just minutes which seems to be easier to handle.Ĭan anyone enlighten me as to why this wont cycle on and off? #include The code works fine (except where it reaches 60mins on or off then jumps to 135 which I cannot figure out for the life of me). I am trying to get this fan to loop in a cycled on/off depending on the values input by the buttons.






Arduino millis inside interrupt