Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sound 2 Light Workshop
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Werner Jarmatz
Sound 2 Light Workshop
Commits
f870aba7
Commit
f870aba7
authored
8 months ago
by
Werner Jarmatz
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
07f8f31f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
micropython/main.py
+54
-0
54 additions, 0 deletions
micropython/main.py
with
54 additions
and
0 deletions
micropython/main.py
0 → 100644
+
54
−
0
View file @
f870aba7
'''
Example program for use in the soldering workshop.
Should work on a WS2812 strip of any length.
The variable
"
softgain
"
controls the sensitivity in selfcalibrating mode and
the length of the strip is entered in
"
number_pixels
"
.
Works with a MAX4466 microphone amplifier module.
Version: 0.2 from 26.05.2024
License: CC-BY Weja/HoFaLab
'''
number_pixels
=
10
brightness
=
0.4
# value between 0 and 1
import
WS2812onRP2040
import
time
from
machine
import
ADC
,
Pin
,
Timer
softgain
,
mode
,
average
=
0
,
0
,
0
#init values
mic
=
ADC
(
Pin
(
28
))
# create ADC object on ADC pin
pixels
=
WS2812onRP2040
.
strip
(
number_pixels
,
29
,
brightness
)
timer1
=
Timer
(
period
=
10000
,
mode
=
Timer
.
PERIODIC
,
callback
=
lambda
t
:
changemode
())
def
changemode
():
#0-left,1-right,2-center lights
global
mode
mode
=
(
mode
+
1
)
%
3
def
vu_meter
():
vu
=
0
for
r
in
range
(
500
):
vu
+=
abs
(
mic
.
read_u16
()
-
32767
)
return
(
vu
/
500
)
/
32767
time
.
sleep
(
5
)
# wait 5 sec. before start
while
True
:
sound
=
vu_meter
()
average
=
average
/
50
*
49
+
sound
/
50
softgain
=
4
/
average
# selfcalibrating
if
sound
<
0.03
:
#mute - depending on the microphone and ambient noise
softgain
=
1
hue
=
min
(
int
(
sound
*
softgain
*
50
),
359
)
#print(sound,softgain,hue) #debug info
col
=
WS2812onRP2040
.
hue2col
(
hue
)
anz
=
min
(
int
(
sound
*
softgain
),
number_pixels
)
pixels
.
fill
((
0
,
0
,
0
))
for
p
in
range
(
anz
):
if
mode
==
0
:
#left to right
pixels
.
pset
(
number_pixels
-
1
-
p
,(
col
))
if
mode
==
1
:
#right to left
pixels
.
pset
(
p
,(
col
))
if
mode
==
2
:
# left/right to center
pixels
.
pset
(
p
,(
col
))
pixels
.
pset
(
number_pixels
-
1
-
p
,(
col
))
pixels
.
show
()
time
.
sleep
(
0.125
)
# refresh time for the lights.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment