I am new to programming and need some some help getting started with a project.
I need to control 6 outputs on the Photon using a cloud function (no problem).
But, when a output is activated (high), a timer shall set it low.
The timer needs to work independently on all 6 outputs.
Can anyone give me some hints ?
Thank you @ScruffR At the moment I have no clue how to implement the code described in the link.
I will keep searching for some code examples.
@skibsradio, if you search this forum you will find examples of multiple timed events. I recall a sprinkler system for example.
If you are new to programming, you may need to learn some basics before trying a more advanced project. Using @ScruffR’s advice, your project would need the following I believe:
- An array of six unsigned integer values to store time (in seconds) values for each of the 6 outputs you want to control. Using a two-dimensional array you could store the GPIO pin number and its corresponding timer value together.
- Create a free-running Software Timer with a one second interval, assuming the minimum time for keeping an output “active” is one second.
- In your Particle.function() you would parse the passed command string (eg. using
sscanf()) to get the output number and the time it needs to remain “active” after which it is set “inactive”. That time value would be stored in the corresponding array value (for that output).
- In the Software Timer callback and using a
for() loop, check if all timer array entries for a non-zero value and decrement it. If it reaches zero, set the corresponding output to “inactive”, otherwise continue checking the other timer values. Any timers with zero value will be ignored.
Basically, the Particle.function() sets an output and its corresponding timer value (in seconds) while the Software Timer callback will, at one second intervals, check if any output needs to be set to “inactive”.
@peekay123 Thank you for your answer.