Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
HepiaLight3 - RBPi Pico
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
michael.divia
HepiaLight3 - RBPi Pico
Commits
4dbb77ec
Commit
4dbb77ec
authored
10 months ago
by
Gaspard Le Gouic
Browse files
Options
Downloads
Patches
Plain Diff
added Accel class and accel_test
parent
91ed6d01
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
1 - Code/hl3.py
+92
-2
92 additions, 2 deletions
1 - Code/hl3.py
1 - Code/main.py
+6
-0
6 additions, 0 deletions
1 - Code/main.py
with
98 additions
and
2 deletions
1 - Code/hl3.py
+
92
−
2
View file @
4dbb77ec
from
machine
import
Pin
,
UART
from
machine
import
Pin
,
UART
,
I2C
from
neopixel
import
NeoPixel
from
neopixel
import
NeoPixel
from
rp2
import
PIO
,
StateMachine
,
asm_pio
from
rp2
import
PIO
,
StateMachine
,
asm_pio
import
utime
import
utime
...
@@ -11,6 +11,7 @@ gpio_neopixel = 0
...
@@ -11,6 +11,7 @@ gpio_neopixel = 0
np
=
NeoPixel
(
Pin
(
gpio_neopixel
,
Pin
.
OUT
),
nb_line
*
nb_row
)
np
=
NeoPixel
(
Pin
(
gpio_neopixel
,
Pin
.
OUT
),
nb_line
*
nb_row
)
fb
=
framebuf
.
FrameBuffer
(
bytearray
(
nb_line
*
nb_row
*
2
),
nb_row
,
nb_line
,
framebuf
.
RGB565
)
fb
=
framebuf
.
FrameBuffer
(
bytearray
(
nb_line
*
nb_row
*
2
),
nb_row
,
nb_line
,
framebuf
.
RGB565
)
i2c
=
I2C
(
1
,
scl
=
Pin
(
3
),
sda
=
Pin
(
2
),
freq
=
400_000
)
class
Color
:
class
Color
:
BLACK
=
(
0
,
0
,
0
)
BLACK
=
(
0
,
0
,
0
)
...
@@ -63,6 +64,8 @@ class Direction:
...
@@ -63,6 +64,8 @@ class Direction:
SOUTH
=
2
SOUTH
=
2
EAST
=
4
EAST
=
4
WEST
=
8
WEST
=
8
FRONT
=
16
BACK
=
32
def
Color_convert
(
color
):
def
Color_convert
(
color
):
"""
Convert an input color into a RGB tuple
"""
Convert an input color into a RGB tuple
...
@@ -439,6 +442,92 @@ class Uart:
...
@@ -439,6 +442,92 @@ class Uart:
data
+=
chr
(
self
.
rx
.
get
()
>>
24
)
data
+=
chr
(
self
.
rx
.
get
()
>>
24
)
return
data
.
rstrip
()
return
data
.
rstrip
()
class
Accel
:
def
init
():
i2c
.
writeto_mem
(
0x1d
,
0x20
,
b
'
\x57
'
)
def
get_x
():
buf
=
i2c
.
readfrom_mem
(
0x1d
,
0xa8
,
2
)
x
=
((
buf
[
0
]
&
0xff
)
|
((
buf
[
1
]
&
0xff
)
<<
8
))
/
16384
if
x
>
2
:
x
=
x
-
4
return
x
def
get_y
():
buf
=
i2c
.
readfrom_mem
(
0x1d
,
0xaa
,
2
)
y
=
((
buf
[
0
]
&
0xff
)
|
((
buf
[
1
]
&
0xff
)
<<
8
))
/
16384
if
y
>
2
:
y
=
y
-
4
return
y
def
get_z
():
buf
=
i2c
.
readfrom_mem
(
0x1d
,
0xac
,
2
)
z
=
((
buf
[
0
]
&
0xff
)
|
((
buf
[
1
]
&
0xff
)
<<
8
))
/
16384
if
z
>
2
:
z
=
z
-
4
return
z
def
facing
(
side
):
z
=
Accel
.
get_z
()
if
side
==
Direction
.
FRONT
:
if
z
<
0
:
return
True
else
:
return
False
elif
side
==
Direction
.
BACK
:
if
z
<
0
:
return
False
else
:
return
True
else
:
return
False
def
tilting
(
dir
):
if
dir
==
Direction
.
NORTH
or
dir
==
Direction
.
SOUTH
:
x
=
Accel
.
get_x
()
if
dir
==
Direction
.
NORTH
:
if
x
>
0.03
:
return
False
elif
x
<
-
0.03
:
return
True
else
:
if
x
>
0.03
:
return
True
elif
x
<
-
0.03
:
return
False
elif
dir
==
Direction
.
EAST
or
dir
==
Direction
.
WEST
:
y
=
Accel
.
get_y
()
if
dir
==
Direction
.
EAST
:
if
y
>
0.03
:
return
False
elif
y
<
-
0.03
:
return
True
else
:
if
y
>
0.03
:
return
True
elif
y
<
-
0.03
:
return
False
def
accel_test
():
if
Accel
.
tilting
(
Direction
.
NORTH
):
print
(
'
Tilting North !
'
)
if
Accel
.
tilting
(
Direction
.
SOUTH
):
print
(
'
Tilting South !
'
)
if
Accel
.
tilting
(
Direction
.
WEST
):
print
(
'
Tilting West !
'
)
if
Accel
.
tilting
(
Direction
.
EAST
):
print
(
'
Tilting East !
'
)
if
Accel
.
facing
(
Direction
.
FRONT
):
print
(
'
Facing front !
'
)
if
Accel
.
facing
(
Direction
.
BACK
):
print
(
'
Facing back !
'
)
x
=
Accel
.
get_x
()
y
=
Accel
.
get_y
()
z
=
Accel
.
get_z
()
print
(
'
Gravity [x, y ,z] = [{}, {}, {}]
'
.
format
(
x
,
y
,
z
))
def
christmas
():
def
christmas
():
"""
Christmas demo code
"""
Christmas demo code
...
@@ -516,4 +605,5 @@ def christmas():
...
@@ -516,4 +605,5 @@ def christmas():
for
i
in
range
(
8
):
for
i
in
range
(
8
):
Matrix
.
set_led
(
i
,
Color
%
8
,
Color
*
(
i
+
1
)
*
(
j
+
11
))
Matrix
.
set_led
(
i
,
Color
%
8
,
Color
*
(
i
+
1
)
*
(
j
+
11
))
utime
.
sleep
(
period
)
utime
.
sleep
(
period
)
Matrix
.
clear
(
0
)
Matrix
.
clear
(
0
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
1 - Code/main.py
+
6
−
0
View file @
4dbb77ec
from
hl3
import
*
from
hl3
import
*
Accel
.
init
()
while
True
:
while
True
:
set_img
(
"""
set_img
(
"""
.RR..RR.
.RR..RR.
...
@@ -81,3 +83,7 @@ while True:
...
@@ -81,3 +83,7 @@ while True:
show_text
(
"
This is Text
"
,
Color
.
BLUE
,
0.02
)
show_text
(
"
This is Text
"
,
Color
.
BLUE
,
0.02
)
utime
.
sleep
(
0.2
)
utime
.
sleep
(
0.2
)
christmas
()
christmas
()
utime
.
sleep
(
0.2
)
accel_test
()
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