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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
michael.divia
HepiaLight3 - RBPi Pico
Commits
7260a848
Commit
7260a848
authored
1 year ago
by
michael.divia
Browse files
Options
Downloads
Patches
Plain Diff
Prep for East & West + Corrections
parent
b3b87f95
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
1 - Code/hl3.py
+102
-83
102 additions, 83 deletions
1 - Code/hl3.py
with
102 additions
and
83 deletions
1 - Code/hl3.py
+
102
−
83
View file @
7260a848
from
machine
import
Pin
,
U
ART
from
machine
import
Pin
,
U
art
from
neopixel
import
NeoPixel
from
neopixel
import
NeoPixel
import
utime
import
utime
...
@@ -139,70 +139,70 @@ __TEXT_DICT = {
...
@@ -139,70 +139,70 @@ __TEXT_DICT = {
def
col
(
r
,
g
,
b
):
def
col
(
r
,
g
,
b
):
return
(
r
,
g
,
b
)
return
(
r
,
g
,
b
)
def
c
olor_convert
(
c
olor
):
def
C
olor_convert
(
C
olor
):
# Handle hex an 0
# Handle hex an 0
if
isinstance
(
c
olor
,
int
):
if
isinstance
(
C
olor
,
int
):
if
c
olor
==
0
:
if
C
olor
==
0
:
c
olor
=
(
0
,
0
,
0
)
C
olor
=
(
0
,
0
,
0
)
else
:
else
:
c
olor
=
((
c
olor
>>
16
)
&
0xFF
,
(
c
olor
>>
8
)
&
0xFF
,
c
olor
&
0xFF
)
C
olor
=
((
C
olor
>>
16
)
&
0xFF
,
(
C
olor
>>
8
)
&
0xFF
,
C
olor
&
0xFF
)
# Handle RGB tuple
# Handle RGB tuple
elif
isinstance
(
c
olor
,
tuple
)
and
len
(
c
olor
)
==
3
:
elif
isinstance
(
C
olor
,
tuple
)
and
len
(
C
olor
)
==
3
:
pass
pass
# Error
# Error
else
:
else
:
raise
ValueError
(
"
Color must be an RGB tuple, a hex value, 0 or a valide
c
olor from the
c
olor class
"
)
raise
ValueError
(
"
Color must be an RGB tuple, a hex value, 0 or a valide
C
olor from the
C
olor class
"
)
return
c
olor
return
C
olor
class
Matrix
:
class
Matrix
:
def
clear
(
c
olor
):
def
clear
(
C
olor
):
# Convert the
c
olor
# Convert the
C
olor
c
olor
=
c
olor_convert
(
c
olor
)
C
olor
=
C
olor_convert
(
C
olor
)
# Set the full screen to the
c
olor
# Set the full screen to the
C
olor
for
i
in
range
(
nb_line
*
nb_row
):
for
i
in
range
(
nb_line
*
nb_row
):
np
[
i
]
=
c
olor
np
[
i
]
=
C
olor
# Apply the array
# Apply the array
np
.
write
()
np
.
write
()
def
set_line
(
line
,
c
olor
):
def
set_line
(
line
,
C
olor
):
# Check line
# Check line
if
line
<
0
or
line
>=
nb_line
:
if
line
<
0
or
line
>=
nb_line
:
raise
ValueError
(
"
Line is out of bound
"
)
raise
ValueError
(
"
Line is out of bound
"
)
# Convert the
c
olor
# Convert the
C
olor
c
olor
=
c
olor_convert
(
c
olor
)
C
olor
=
C
olor_convert
(
C
olor
)
# Set the line to the
c
olor
# Set the line to the
C
olor
for
i
in
range
(
line
*
nb_row
,
(
line
*
nb_row
)
+
nb_row
):
for
i
in
range
(
line
*
nb_row
,
(
line
*
nb_row
)
+
nb_row
):
np
[
i
]
=
c
olor
np
[
i
]
=
C
olor
# Apply the array
# Apply the array
np
.
write
()
np
.
write
()
def
set_column
(
column
,
c
olor
):
def
set_column
(
column
,
C
olor
):
# Check column
# Check column
if
column
<
0
or
column
>=
nb_row
:
if
column
<
0
or
column
>=
nb_row
:
raise
ValueError
(
"
Column is out of bound
"
)
raise
ValueError
(
"
Column is out of bound
"
)
# Convert the
c
olor
# Convert the
C
olor
c
olor
=
c
olor_convert
(
c
olor
)
C
olor
=
C
olor_convert
(
C
olor
)
# Set the line to the
c
olor
# Set the line to the
C
olor
for
i
in
range
(
column
,
nb_row
*
nb_line
,
nb_row
):
for
i
in
range
(
column
,
nb_row
*
nb_line
,
nb_row
):
np
[
i
]
=
c
olor
np
[
i
]
=
C
olor
# Apply the array
# Apply the array
np
.
write
()
np
.
write
()
def
set_led
(
column
,
line
,
c
olor
):
def
set_led
(
column
,
line
,
C
olor
):
# Check bounds
# Check bounds
if
line
<
0
or
line
>=
nb_line
:
if
line
<
0
or
line
>=
nb_line
:
...
@@ -210,11 +210,11 @@ class Matrix:
...
@@ -210,11 +210,11 @@ class Matrix:
if
column
<
0
or
column
>=
nb_row
:
if
column
<
0
or
column
>=
nb_row
:
raise
ValueError
(
"
Column is out of bound
"
)
raise
ValueError
(
"
Column is out of bound
"
)
# Convert the
c
olor
# Convert the
C
olor
c
olor
=
c
olor_convert
(
c
olor
)
C
olor
=
C
olor_convert
(
C
olor
)
# Set the specific LED to the
c
olor
# Set the specific LED to the
C
olor
np
[
line
*
nb_row
+
column
]
=
c
olor
np
[
line
*
nb_row
+
column
]
=
C
olor
# Apply the array
# Apply the array
np
.
write
()
np
.
write
()
...
@@ -227,18 +227,18 @@ class Matrix:
...
@@ -227,18 +227,18 @@ class Matrix:
if
column
<
0
or
column
>=
nb_row
:
if
column
<
0
or
column
>=
nb_row
:
raise
ValueError
(
"
Column is out of bound
"
)
raise
ValueError
(
"
Column is out of bound
"
)
# Get the
c
olor of the specific LED
# Get the
C
olor of the specific LED
r
,
g
,
b
=
np
[
line
*
nb_row
+
column
]
r
,
g
,
b
=
np
[
line
*
nb_row
+
column
]
# Convert to hexadecimal
# Convert to hexadecimal
hex_
c
olor
=
(
r
<<
16
)
|
(
g
<<
8
)
|
b
hex_
C
olor
=
(
r
<<
16
)
|
(
g
<<
8
)
|
b
return
hex_
c
olor
return
hex_
C
olor
def
show_text
(
text
,
c
olor
,
speed
):
def
show_text
(
text
,
C
olor
,
speed
):
# Clear the screen
# Clear the screen
m
atrix
.
clear
(
0
)
M
atrix
.
clear
(
0
)
width
=
5
width
=
5
height
=
8
height
=
8
...
@@ -258,8 +258,8 @@ def show_text(text, color, speed):
...
@@ -258,8 +258,8 @@ def show_text(text, color, speed):
colbit
=
1
<<
col
colbit
=
1
<<
col
charMap
=
__TEXT_DICT
[
char
]
charMap
=
__TEXT_DICT
[
char
]
for
line
in
range
(
height
):
for
line
in
range
(
height
):
c
olored
=
len
(
charMap
)
>
line
and
charMap
[
line
]
&
colbit
C
olored
=
len
(
charMap
)
>
line
and
charMap
[
line
]
&
colbit
m
atrix
.
set_led
(
xpos
,
line
,
c
olor
if
c
olored
else
0
)
M
atrix
.
set_led
(
xpos
,
line
,
C
olor
if
C
olored
else
0
)
for
step
in
range
(
h_offset
+
len
(
text
)
*
(
width
+
spacewidth
)
+
1
):
for
step
in
range
(
h_offset
+
len
(
text
)
*
(
width
+
spacewidth
)
+
1
):
for
i
in
range
(
nb_row
):
for
i
in
range
(
nb_row
):
...
@@ -269,43 +269,62 @@ def show_text(text, color, speed):
...
@@ -269,43 +269,62 @@ def show_text(text, color, speed):
class
Uart
:
class
Uart
:
channel
=
None
channel
=
None
direction
=
None
def
__init__
(
self
,
dir
,
baudrate
=
9600
,
parity
=
None
,
bits
=
8
,
stop
=
1
):
def
__init__
(
self
,
dir
,
baudrate
=
9600
,
parity
=
None
,
bits
=
8
,
stop
=
1
):
if
(
dir
==
d
irection
.
NORTH
):
if
(
dir
==
D
irection
.
NORTH
):
self
.
channel
=
U
ART
(
0
,
baudrate
=
baudrate
,
tx
=
Pin
(
12
),
rx
=
Pin
(
13
),
parity
=
parity
,
bits
=
bits
,
stop
=
stop
)
self
.
channel
=
U
art
(
0
,
baudrate
=
baudrate
,
tx
=
Pin
(
12
),
rx
=
Pin
(
13
),
parity
=
parity
,
bits
=
bits
,
stop
=
stop
)
elif
(
dir
==
d
irection
.
SOUTH
):
elif
(
dir
==
D
irection
.
SOUTH
):
self
.
channel
=
U
ART
(
1
,
baudrate
=
baudrate
,
tx
=
Pin
(
8
),
rx
=
Pin
(
9
),
parity
=
parity
,
bits
=
bits
,
stop
=
stop
)
self
.
channel
=
U
art
(
1
,
baudrate
=
baudrate
,
tx
=
Pin
(
8
),
rx
=
Pin
(
9
),
parity
=
parity
,
bits
=
bits
,
stop
=
stop
)
else
:
else
:
raise
ValueError
(
"
UART direction does not exist
"
)
raise
ValueError
(
"
Uart direction does not exist
"
)
self
.
direction
=
dir
def
send
(
self
,
data
):
def
send
(
self
,
data
):
if
self
.
direction
==
Direction
.
NORTH
or
self
.
direction
==
Direction
.
SOUTH
:
self
.
channel
.
write
(
data
)
self
.
channel
.
write
(
data
)
else
:
i
=
0
def
sendline
(
self
,
data
):
def
sendline
(
self
,
data
):
if
self
.
direction
==
Direction
.
NORTH
or
self
.
direction
==
Direction
.
SOUTH
:
self
.
channel
.
write
(
data
+
'
\n
'
)
self
.
channel
.
write
(
data
+
'
\n
'
)
else
:
i
=
0
def
receive
(
self
,
length
=
1
):
def
receive
(
self
,
length
=
1
):
data
=
None
data
=
None
if
self
.
direction
==
Direction
.
NORTH
or
self
.
direction
==
Direction
.
SOUTH
:
while
data
==
None
or
not
len
(
data
)
==
length
:
while
data
==
None
or
not
len
(
data
)
==
length
:
data
=
self
.
channel
.
read
(
length
)
data
=
self
.
channel
.
read
(
length
)
if
data
is
None
:
if
data
is
None
:
utime
.
sleep
(
0.1
)
utime
.
sleep
(
0.1
)
else
:
i
=
0
return
data
return
data
def
receiveline
(
self
):
def
receiveline
(
self
):
data
=
None
data
=
None
if
self
.
direction
==
Direction
.
NORTH
or
self
.
direction
==
Direction
.
SOUTH
:
while
data
is
None
or
not
data
.
endswith
(
b
'
\n
'
):
while
data
is
None
or
not
data
.
endswith
(
b
'
\n
'
):
data
=
self
.
channel
.
readline
()
data
=
self
.
channel
.
readline
()
if
data
is
None
:
if
data
is
None
:
utime
.
sleep
(
0.1
)
utime
.
sleep
(
0.1
)
else
:
i
=
0
return
data
return
data
def
christmas
():
def
christmas
():
c
olor
=
0x3
C
olor
=
0x3
prime1
=
439
prime1
=
439
prime2
=
17005013
prime2
=
17005013
...
@@ -317,21 +336,21 @@ def christmas():
...
@@ -317,21 +336,21 @@ def christmas():
# Balles glissantes
# Balles glissantes
for
r
in
range
(
100
):
for
r
in
range
(
100
):
c
olor
=
(
c
olor
*
prime1
)
%
prime2
C
olor
=
(
C
olor
*
prime1
)
%
prime2
# horizontale et verticale
# horizontale et verticale
if
c
olor
&
4
==
4
:
if
C
olor
&
4
==
4
:
for
i
in
range
(
8
):
for
i
in
range
(
8
):
temp
=
(
4
-
int
(
abs
(
4.5
-
i
))
+
1
)
temp
=
(
4
-
int
(
abs
(
4.5
-
i
))
+
1
)
temp
=
max
(
3
-
2
*
int
(
temp
/
2
),
0
)
temp
=
max
(
3
-
2
*
int
(
temp
/
2
),
0
)
for
j
in
range
(
temp
,
8
-
temp
):
for
j
in
range
(
temp
,
8
-
temp
):
if
(
c
olor
&
3
==
0
):
if
(
C
olor
&
3
==
0
):
diagonal
=
min
(
int
((
i
+
j
)),
7
)
diagonal
=
min
(
int
((
i
+
j
)),
7
)
elif
(
c
olor
&
3
==
1
):
elif
(
C
olor
&
3
==
1
):
m
atrix
.
set_led
(
i
,
j
,
c
olor
&
masque_blanc
)
M
atrix
.
set_led
(
i
,
j
,
C
olor
&
masque_blanc
)
elif
(
c
olor
&
3
==
2
):
elif
(
C
olor
&
3
==
2
):
m
atrix
.
set_led
(
7
-
i
,
j
,
c
olor
&
masque_blanc
)
M
atrix
.
set_led
(
7
-
i
,
j
,
C
olor
&
masque_blanc
)
else
:
else
:
m
atrix
.
set_led
(
j
,
7
-
i
,
c
olor
&
masque_blanc
)
M
atrix
.
set_led
(
j
,
7
-
i
,
C
olor
&
masque_blanc
)
utime
.
sleep
(
period
)
utime
.
sleep
(
period
)
# Diagonale
# Diagonale
...
@@ -339,67 +358,67 @@ def christmas():
...
@@ -339,67 +358,67 @@ def christmas():
for
k
in
range
(
2
,
9
):
for
k
in
range
(
2
,
9
):
for
i
in
range
(
k
+
1
):
for
i
in
range
(
k
+
1
):
if
(
4.5
-
(
k
-
i
))
**
2
+
(
4.5
-
i
)
**
2
<
5
**
2
:
if
(
4.5
-
(
k
-
i
))
**
2
+
(
4.5
-
i
)
**
2
<
5
**
2
:
if
(
c
olor
&
3
==
0
):
if
(
C
olor
&
3
==
0
):
m
atrix
.
set_led
((
k
-
i
),(
i
),
c
olor
&
masque_blanc
)
M
atrix
.
set_led
((
k
-
i
),(
i
),
C
olor
&
masque_blanc
)
elif
(
c
olor
&
3
==
1
):
elif
(
C
olor
&
3
==
1
):
m
atrix
.
set_led
((
i
),(
k
-
i
),
c
olor
&
masque_blanc
)
M
atrix
.
set_led
((
i
),(
k
-
i
),
C
olor
&
masque_blanc
)
elif
(
c
olor
&
3
==
2
):
elif
(
C
olor
&
3
==
2
):
m
atrix
.
set_led
((
7
-
(
k
-
i
)),(
i
),
c
olor
&
masque_blanc
)
M
atrix
.
set_led
((
7
-
(
k
-
i
)),(
i
),
C
olor
&
masque_blanc
)
else
:
else
:
m
atrix
.
set_led
((
i
),
7
-
(
k
-
i
),
c
olor
&
masque_blanc
)
M
atrix
.
set_led
((
i
),
7
-
(
k
-
i
),
C
olor
&
masque_blanc
)
utime
.
sleep
(
period
)
utime
.
sleep
(
period
)
# Clear the
m
atrix
# Clear the
M
atrix
m
atrix
.
clear
(
0
)
M
atrix
.
clear
(
0
)
# Couleurs clignote
# Couleurs clignote
period
=
.
5
period
=
.
5
for
r
in
range
(
20
):
for
r
in
range
(
20
):
c
olor
=
(
c
olor
*
prime1
)
%
prime2
C
olor
=
(
C
olor
*
prime1
)
%
prime2
for
i
in
range
(
8
):
for
i
in
range
(
8
):
for
j
in
range
(
8
):
for
j
in
range
(
8
):
m
atrix
.
set_led
(
j
,
i
,
c
olor
*
(
i
+
1
)
*
(
j
+
11
)
&
masque_blanc
)
M
atrix
.
set_led
(
j
,
i
,
C
olor
*
(
i
+
1
)
*
(
j
+
11
)
&
masque_blanc
)
utime
.
sleep
(
period
)
utime
.
sleep
(
period
)
m
atrix
.
clear
(
0
)
M
atrix
.
clear
(
0
)
utime
.
sleep
(
period
/
10
)
utime
.
sleep
(
period
/
10
)
# Bleu aléatoire
# Bleu aléatoire
period
=
.
05
period
=
.
05
for
r
in
range
(
20
):
for
r
in
range
(
20
):
c
olor
=
(
c
olor
*
prime1
)
%
prime2
C
olor
=
(
C
olor
*
prime1
)
%
prime2
for
i
in
range
(
8
):
for
i
in
range
(
8
):
for
j
in
range
(
8
):
for
j
in
range
(
8
):
m
atrix
.
set_led
(
j
,
i
,
c
olor
*
(
i
+
1
)
*
(
j
+
11
)
>>
4
&
masque_bleu
)
M
atrix
.
set_led
(
j
,
i
,
C
olor
*
(
i
+
1
)
*
(
j
+
11
)
>>
4
&
masque_bleu
)
utime
.
sleep
(
period
)
utime
.
sleep
(
period
)
# Couleurs aleatoire
# Couleurs aleatoire
period
=
.
05
period
=
.
05
for
r
in
range
(
20
):
for
r
in
range
(
20
):
c
olor
=
(
c
olor
*
prime1
)
%
prime2
C
olor
=
(
C
olor
*
prime1
)
%
prime2
for
i
in
range
(
8
):
for
i
in
range
(
8
):
for
j
in
range
(
8
):
for
j
in
range
(
8
):
m
atrix
.
set_led
(
j
,
i
,
c
olor
*
(
i
+
1
)
*
(
j
+
11
)
&
masque_blanc
)
M
atrix
.
set_led
(
j
,
i
,
C
olor
*
(
i
+
1
)
*
(
j
+
11
)
&
masque_blanc
)
utime
.
sleep
(
period
)
utime
.
sleep
(
period
)
# Rouge aléatoire
# Rouge aléatoire
period
=
.
05
period
=
.
05
for
r
in
range
(
20
):
for
r
in
range
(
20
):
c
olor
=
(
c
olor
*
prime1
)
%
prime2
C
olor
=
(
C
olor
*
prime1
)
%
prime2
for
i
in
range
(
8
):
for
i
in
range
(
8
):
for
j
in
range
(
8
):
for
j
in
range
(
8
):
m
atrix
.
set_led
(
j
,
i
,
c
olor
*
(
i
+
1
)
*
(
j
+
11
)
&
masque_rouge
)
M
atrix
.
set_led
(
j
,
i
,
C
olor
*
(
i
+
1
)
*
(
j
+
11
)
&
masque_rouge
)
utime
.
sleep
(
period
)
utime
.
sleep
(
period
)
# Lignes
# Lignes
period
=
.
05
period
=
.
05
for
r
in
range
(
20
):
for
r
in
range
(
20
):
c
olor
=
(
c
olor
*
prime1
)
%
prime2
C
olor
=
(
C
olor
*
prime1
)
%
prime2
for
i
in
range
(
8
):
for
i
in
range
(
8
):
m
atrix
.
set_led
(
c
olor
%
8
,
i
,
c
olor
*
(
i
+
1
)
*
(
j
+
11
)
&
masque_blanc
)
M
atrix
.
set_led
(
C
olor
%
8
,
i
,
C
olor
*
(
i
+
1
)
*
(
j
+
11
)
&
masque_blanc
)
utime
.
sleep
(
period
)
utime
.
sleep
(
period
)
m
atrix
.
clear
(
0
)
M
atrix
.
clear
(
0
)
for
i
in
range
(
8
):
for
i
in
range
(
8
):
m
atrix
.
set_led
(
i
,
c
olor
%
8
,
c
olor
*
(
i
+
1
)
*
(
j
+
11
)
&
masque_blanc
)
M
atrix
.
set_led
(
i
,
C
olor
%
8
,
C
olor
*
(
i
+
1
)
*
(
j
+
11
)
&
masque_blanc
)
utime
.
sleep
(
period
)
utime
.
sleep
(
period
)
m
atrix
.
clear
(
0
)
M
atrix
.
clear
(
0
)
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