Adds an LED_pulse feature using ISR to devices/grid_maze.py
#150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi everyone,
Thanks for maintaining this great ecosystem!
For an experiment we're running these days, I needed a feature to dim LEDs in a
grid_maze
setup. I'm doing this with PWM using a MicroPython timer and a callback that turns the LED on and off at the requiredduty_cycle
(fraction of the time on), at the requiredfreq
ency. The code is heavily inspired fromcode/source/pyControl/hardware.py
Lines 420 to 450 in a54bdca
LED_on
andLED_off
are allocating new memory withto_byte
code/devices/grid_maze.py
Line 162 in a54bdca
Instead, I pre-allocate buffers for on and off, and write those in a tight loop: this works, is as computationally light as I could think of, but makes pulsing incompatible with turning on/off other LEDs or delivering rewards. Feel free to merge, or otherwise leave here should anyone else need this feature! Happy to take the maintainers' input of course.
This is currently being tested in an experiment, so far we have not had any trouble but I will keep upstreaming fixes if need be. Thanks to @ThomasAkam for his input; some of this code was developed together with Arya Bhomick.
Cheers,
Mathias.