Hi all
I am puilding my current Arduino project and Ive only got one more thing to add (before the hardware interfacing :-[ )
I have a set of contacts and once they are open I want a counter to start and when it reaches a predetermined level, change an existing state
I know I can change the state using Digitalwrite but the thing im struggling with is that I will have an input going low and I need this to;
a) reset any previous value in the counter (it will be dedicated to this function though)
b) start the counter (capeable of up to 5 min)
c) process a digitalwrite command to change a state.
i.e. If pinX == LOW for y ammount of time then digitalwrite stateZ to LOW
Im already using the debounce function with Millis but I fear that using millis will create huge values and slow the board down.
What do you suggest.
Im still very green so any advice would be appriciated.
I fear that using millis will create huge values and slow the board down.
It doesn't matter if the value is huge or small, millis always returns 4 bytes of data. The affect millis has on performance is always a (very small) constant.
It might help if you have a simplified understanding of what millis() does.
In the micro there is a counter that counts clock cycles. It is always running. When the counter reaches its capacity and overflows a quick calculation is made and if one millisecond has passed another (software) counter is incremented. This counter keeps track of how many milliseconds has passed since power-up. This occurs in the background no matter what your code is doing.
Now when you call millis() what the software does is disable interrupts (so that the millisecond counter won't change in the middle of getting its value) retreive the number in the millisecond counter, reenable interrupts, and return the number to you.
The counter size is 4 bytes (32 bits). It doesn't matter how large the number in the counter is - the result is always 4 bytes and retrieval of the number will always take on the order of microseconds.
In short - not to worry. The kind of thing you are wanting to do is what millis() is for.