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/checks(.:format)
route-controllerpull_requests
route-actionchecks
fetch-noncev2:ba30d2f5-7490-115b-65fa-47dfecfabc17
current-catalog-service-hash87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a
request-id95E4:37A505:92373:BC4A4:698EB641
html-safe-nonce26e9f46c51a8790cb53ea127ab3ddc74401554cafbda9872ead03b538d706438
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUU0OjM3QTUwNTo5MjM3MzpCQzRBNDo2OThFQjY0MSIsInZpc2l0b3JfaWQiOiI1OTk1Nzc5MjczMzE0NDQ4OTYxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacda9cc983f3bfa392118b3328345e3096b41c4bd9a47f1ddf67c36ed23ad32297
hovercard-subject-tagpull_request:2524557611
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/checks
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/pyControl/code/pull/150/checks
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
Nonecb2828a801ee6b7be618f3ac76fbf55def35bbc30f053a9c41bf90210b8b72ba
turbo-cache-controlno-preview
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 full-width full-width-p-0
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasee6b91a7e6e46287d26887e3fb7a4161657bab8f7
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/pyControl/code/pull/150/checks#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%2Fchecks
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%2Fchecks
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%2Fchecks&source=header-repo&source_repo=pyControl%2Fcode
Reloadhttps://patch-diff.githubusercontent.com/pyControl/code/pull/150/checks
Reloadhttps://patch-diff.githubusercontent.com/pyControl/code/pull/150/checks
Reloadhttps://patch-diff.githubusercontent.com/pyControl/code/pull/150/checks
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/checks
Learn more about GitHub Actionshttps://docs.github.com/categories/automating-your-workflow-with-github-actions
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.