This Arduino library allows non-smart roller-shutters to be percentage-controlled using time. Using relays, it is easy to make shutters go up and down. But I wanted to be able to make the shutters go halfway (50%) for example. So I built this library.
- Ability to set aperture percentage
- Power outage safe
- Shutters state saved using 20 bytes
- Store in EEPROM, SPIFFS, etc. using callbacks
- Automatic calibration on extremes (0% and 100%)
- Flexible control method (might use relays, RF, etc.) using callbacks
- Support for multiple shutters
- Measure as precisely as possible the time of a full shutters course
- The initial state callback must return a zeroed char array
- Download the latest version
- Load the
.zip
with Sketch → Include Library → Add .ZIP Library
See examples folder for examples.
Instantiate a Shutters instance.
Setup the shutters.
Must be called once in setup()
, after setCourseTime()
, otherwise it won't have any effect.
Handle the shutters.
Must be called in loop()
. Don't call delay()
in loop() as it will block the loop, so Shutters will malfunction.
Returns the up course time or 0
if not yet begin()
.
Returns the down course time or 0
if not yet begin()
.
Set the operation handler.
Must be called at least one time, before setCourseTime()
.
handler
: Operation handler
Return the state length.
Restore the shutters state.
Must be called before setCourseTime()
.
state
: Latest stored state
Set the write state handler.
Must be called at least one time, before setCourseTime()
.
handler
: Write state handler
Set the course time. If downCourseTime
is not set, it will be the same as upCourseTime
.
Must be called at least one time, before setup()
and after setOperationHandler(), setReadStateHandler() and setWriteStateHandler()
. Calling it after setup()
will have no effect (unless reset()
has been called).
upCourseTime
: Up course time, in milliseconds. Must be max 67108864, otherwise it will have no effectdownCourseTime
: Down course time, in milliseconds. Must be max 67108864, otherwise it will have no effect
Returns the calibration ration.
Set the course time. If downCourseTime
is not set, it will be the same as upCourseTime
.
Can be called anytime, takes effect immediately.
calibrationRatio
: Calibration ratio. E.g.0.5
means "50% of the course time". For example, if your course time is10000
, and the calibration ratio is0.2
, then, when wesetLevel()
to0
or100
, the shutters will move for0.2 * 10000 = 2000
ms more than normal. That way, we can ensure we are actually at0
or100
and thus, that we are calibrated.
Set the level reached handler. This handler will be called whenever a new level is reached, along with intermediary levels. E.g. if the levels are at 10% and you request 15%, the callback will be called for 11, 12, 13, 14 and 15%.
Can be called anytime, takes effect immediately.
levelReachedCallback
: Level reached callback
Put the shutters in the given position.
Note that if percentage
== 0 || percentage
== 100, the shutters will recalibrate (relays will stay active a bit longer than it should to ensure the shutters are really at their minimum or maximum position).
Can only be called after begin()
, otherwise it won't have any effect.
percentage
: Percentage the shutters must go to. If not 0 <=percentage
<= 100, nothing will be done
Stop the shutters.
Can only be called after begin()
, otherwise it won't have any effect.
Return whether the shutters are currently idle or not.
Return the current level of the shutters. Might be +/- 1% if the shutters are moving.
Erase saved state, for example for a reset routine. This disables the library, until you call setCourseTime()
and begin()
again.
Return whether the shutters is currently in a reset state or not (e.g. before having called setCourseTime()
and begin()
, or after a reset()
).
The stored state does contain the up and down course time, along with whether or not the current level is known, and if so, along with the current level. This means that if you change the course time after boot (or after reset()
) with a course time that is not the same as the last known one, the shutters will auto-reset. In other words: you don't have to reset the state if you change the course time, everything is handled internally.