René's URL Explorer Experiment


Title: Adds an LED_pulse feature using ISR to `devices/grid_maze.py` by mathias-sm · Pull Request #150 · pyControl/code · GitHub

Open Graph Title: Adds an LED_pulse feature using ISR to `devices/grid_maze.py` by mathias-sm · Pull Request #150 · pyControl/code

X Title: Adds an LED_pulse feature using ISR to `devices/grid_maze.py` by mathias-sm · Pull Request #150 · pyControl/code

Description: 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 required duty_cycle (fraction of the time on), at the required freqency. The code is heavily inspired from code/source/pyControl/hardware.py Lines 420 to 450 in a54bdca def pulse(self, freq, duty_cycle=50, n_pulses=False, load_warning=True): # Turn on pulsed output with specified frequency and duty cycle. assert duty_cycle % 5 == 0, "duty cycle must be a multiple of 5 between 5 and 95%" if not self.timer: self.timer = pyb.Timer(available_timers.pop()) self.fm = int(100 / next(x for x in (50, 25, 20, 10, 5) if duty_cycle % x == 0)) self.off_ind = int(duty_cycle / 100 * self.fm) self.i = 0 self.n_pulses = n_pulses if self.n_pulses: self.pulse_n = 0 int_freq = freq * self.fm if load_warning and int_freq > 2000: warning("This pulse freq and duty_cycle will use > 10% of pyboard processor resources.") self.timer.init(freq=int_freq) self.timer.callback(self._ISR) self.on() @micropython.native def _ISR(self, t): self.i += 1 if self.i == self.off_ind: if self.n_pulses: self.pulse_n += 1 if self.pulse_n == self.n_pulses: self.off() return self.toggle() elif self.i == self.fm: self.i = 0 self.toggle() but as they are currently written, this maze's LED_on and LED_off are allocating new memory with to_byte code/devices/grid_maze.py Line 162 in a54bdca self.I2C[i2c].mem_write(values.to_bytes(n_bytes, "little"), self.addr[exp_n], self.reg_addr[register], timeout=5) which is incompatible with ISRs (see https://docs.micropython.org/en/latest/reference/isr_rules.html). 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.

Open Graph Description: 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 Mi...

X Description: 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 us...

Opengraph URL: https://github.com/pyControl/code/pull/150

X: @github

direct link

Domain: patch-diff.githubusercontent.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:8378b873-d058-3900-7619-4000ae7a1a66
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idDD2C:15CF6:E03FC:11784A:698FBADA
html-safe-nonceff4f5de24fc60dc5724dccab2be96d96b284dbfec5a5d944ded51fb12ac961d4
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDJDOjE1Q0Y2OkUwM0ZDOjExNzg0QTo2OThGQkFEQSIsInZpc2l0b3JfaWQiOiI3MTYzOTA0OTIzNDk0NDk2OTg2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac11cd215536b743c1a6bfb873e9a719571bc80fb7bf684cc430bcea019ac70748
hovercard-subject-tagpull_request:2524557611
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/pyControl/code/pull/150/files
twitter:imagehttps://avatars.githubusercontent.com/u/7687623?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/7687623?s=400&v=4
og:image:altHi 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 Mi...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/pyControl/code git https://github.com/pyControl/code.git
octolytics-dimension-user_id58780920
octolytics-dimension-user_loginpyControl
octolytics-dimension-repository_id219033872
octolytics-dimension-repository_nwopyControl/code
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id219033872
octolytics-dimension-repository_network_root_nwopyControl/code
turbo-body-classeslogged-out env-production page-responsive
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release4084c47bba08e7ba5fab63cb1dd485a339910ed7
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/pyControl/code/pull/150/files#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2FpyControl%2Fcode%2Fpull%2F150%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2FpyControl%2Fcode%2Fpull%2F150%2Ffiles
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=pyControl%2Fcode
Reloadhttps://patch-diff.githubusercontent.com/pyControl/code/pull/150/files
Reloadhttps://patch-diff.githubusercontent.com/pyControl/code/pull/150/files
Reloadhttps://patch-diff.githubusercontent.com/pyControl/code/pull/150/files
pyControl https://patch-diff.githubusercontent.com/pyControl
codehttps://patch-diff.githubusercontent.com/pyControl/code
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2FpyControl%2Fcode
Fork 27 https://patch-diff.githubusercontent.com/login?return_to=%2FpyControl%2Fcode
Star 29 https://patch-diff.githubusercontent.com/login?return_to=%2FpyControl%2Fcode
Code https://patch-diff.githubusercontent.com/pyControl/code
Issues 2 https://patch-diff.githubusercontent.com/pyControl/code/issues
Pull requests 2 https://patch-diff.githubusercontent.com/pyControl/code/pulls
Discussions https://patch-diff.githubusercontent.com/pyControl/code/discussions
Actions https://patch-diff.githubusercontent.com/pyControl/code/actions
Projects 0 https://patch-diff.githubusercontent.com/pyControl/code/projects
Security 0 https://patch-diff.githubusercontent.com/pyControl/code/security
Insights https://patch-diff.githubusercontent.com/pyControl/code/pulse
Code https://patch-diff.githubusercontent.com/pyControl/code
Issues https://patch-diff.githubusercontent.com/pyControl/code/issues
Pull requests https://patch-diff.githubusercontent.com/pyControl/code/pulls
Discussions https://patch-diff.githubusercontent.com/pyControl/code/discussions
Actions https://patch-diff.githubusercontent.com/pyControl/code/actions
Projects https://patch-diff.githubusercontent.com/pyControl/code/projects
Security https://patch-diff.githubusercontent.com/pyControl/code/security
Insights https://patch-diff.githubusercontent.com/pyControl/code/pulse
Sign up for GitHub https://patch-diff.githubusercontent.com/signup?return_to=%2FpyControl%2Fcode%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://patch-diff.githubusercontent.com/login?return_to=%2FpyControl%2Fcode%2Fissues%2Fnew%2Fchoose
mathias-smhttps://patch-diff.githubusercontent.com/mathias-sm
pyControl:masterhttps://patch-diff.githubusercontent.com/pyControl/code/tree/master
mathias-sm:masterhttps://patch-diff.githubusercontent.com/mathias-sm/pyControl/tree/master
Conversation 2 https://patch-diff.githubusercontent.com/pyControl/code/pull/150
Commits 1 https://patch-diff.githubusercontent.com/pyControl/code/pull/150/commits
Checks 0 https://patch-diff.githubusercontent.com/pyControl/code/pull/150/checks
Files changed https://patch-diff.githubusercontent.com/pyControl/code/pull/150/files
Please reload this pagehttps://patch-diff.githubusercontent.com/pyControl/code/pull/150/files
Adds an LED_pulse feature using ISR to devices/grid_maze.py https://patch-diff.githubusercontent.com/pyControl/code/pull/150/files#top
Show all changes 1 commit https://patch-diff.githubusercontent.com/pyControl/code/pull/150/files
8b638b1 Adds an LED_pulse feature using ISR mathias-sm May 16, 2025 https://patch-diff.githubusercontent.com/pyControl/code/pull/150/commits/8b638b10e4d071254c33c3d1d1420b141d201b8f
Clear filters https://patch-diff.githubusercontent.com/pyControl/code/pull/150/files
Please reload this pagehttps://patch-diff.githubusercontent.com/pyControl/code/pull/150/files
Please reload this pagehttps://patch-diff.githubusercontent.com/pyControl/code/pull/150/files
devices/grid_maze.pyhttps://patch-diff.githubusercontent.com/pyControl/code/pull/150/files#diff-6f07ecd8f8f6673856fb885ee62581fac9c9898e32b4ea3f07b21d3d3ec3e151
View file https://patch-diff.githubusercontent.com/pyControl/code/blob/8b638b10e4d071254c33c3d1d1420b141d201b8f/devices/grid_maze.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://patch-diff.githubusercontent.com/pyControl/code/pull/150/{{ revealButtonHref }}
https://patch-diff.githubusercontent.com/pyControl/code/pull/150/files#diff-6f07ecd8f8f6673856fb885ee62581fac9c9898e32b4ea3f07b21d3d3ec3e151
https://patch-diff.githubusercontent.com/pyControl/code/pull/150/files#diff-6f07ecd8f8f6673856fb885ee62581fac9c9898e32b4ea3f07b21d3d3ec3e151
https://patch-diff.githubusercontent.com/pyControl/code/pull/150/files#diff-6f07ecd8f8f6673856fb885ee62581fac9c9898e32b4ea3f07b21d3d3ec3e151
https://patch-diff.githubusercontent.com/pyControl/code/pull/150/files#diff-6f07ecd8f8f6673856fb885ee62581fac9c9898e32b4ea3f07b21d3d3ec3e151
https://patch-diff.githubusercontent.com/pyControl/code/pull/150/files#diff-6f07ecd8f8f6673856fb885ee62581fac9c9898e32b4ea3f07b21d3d3ec3e151
https://patch-diff.githubusercontent.com/pyControl/code/pull/150/files#diff-6f07ecd8f8f6673856fb885ee62581fac9c9898e32b4ea3f07b21d3d3ec3e151
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.