Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
Unicorn-HAT-HD-CPU-Temperature
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Griefed
Unicorn-HAT-HD-CPU-Temperature
Commits
f48493bb
Unverified
Commit
f48493bb
authored
5 years ago
by
Griefed
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Text colour depends on temperature
Text colour depends on temperature
parent
3450de9e
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
cpu.py
+69
-0
69 additions, 0 deletions
cpu.py
with
69 additions
and
0 deletions
cpu.py
0 → 100644
+
69
−
0
View file @
f48493bb
#!/usr/bin/env python
import
colorsys
import
time
from
gpiozero
import
CPUTemperature
from
PIL
import
Image
,
ImageDraw
,
ImageFont
import
unicornhathd
import
sys
print
(
"""
Unicorn HAT HD: CPU Temperature
Displays the CPU Temperature on your Unicorn HAT HD!
"""
)
FONT
=
(
'
/usr/share/fonts/truetype/piboto/PibotoCondensed-Regular.ttf
'
,
12
)
unicornhathd
.
rotation
(
270
)
unicornhathd
.
brightness
(
0.3
)
width
,
height
=
unicornhathd
.
get_shape
()
text_x
=
0
text_y
=
0
font_file
,
font_size
=
FONT
font
=
ImageFont
.
truetype
(
font_file
,
font_size
)
degree_sign
=
u
'
\N{DEGREE SIGN}
'
#warning = 55
try
:
while
True
:
cpu
=
CPUTemperature
()
TEXT
=
(
str
(
int
(
cpu
.
temperature
))
+
degree_sign
)
text_width
,
text_height
=
font
.
getsize
(
TEXT
)
text_width
+=
width
+
text_x
image
=
Image
.
new
(
'
RGB
'
,
(
text_width
,
max
(
height
,
text_height
)),
(
0
,
0
,
0
))
draw
=
ImageDraw
.
Draw
(
image
)
draw
.
text
((
text_x
,
text_y
),
TEXT
,
fill
=
(
255
,
255
,
255
),
font
=
font
)
check
=
int
(
cpu
.
temperature
)
for
scroll
in
range
(
text_width
-
width
+
90
):
for
x
in
range
(
width
):
if
check
<
30
:
hue
=
0.5
if
30
<=
check
and
check
<
35
:
hue
=
0.4
if
35
<=
check
and
check
<
40
:
hue
=
0.3
if
40
<=
check
and
check
<
45
:
hue
=
0.2
if
45
<=
check
and
check
<
50
:
hue
=
0.1
if
50
<=
check
and
check
<
55
:
hue
=
0.08333333
if
check
>=
55
:
hue
=
0.0
#else:
# hue = (x + scroll) / float(text_width)
br
,
bg
,
bb
=
[
int
(
n
*
255
)
for
n
in
colorsys
.
hsv_to_rgb
(
hue
,
1.0
,
1.0
)]
for
y
in
range
(
height
):
pixel
=
image
.
getpixel
((
x
,
y
))
r
,
g
,
b
=
[
float
(
n
/
255.0
)
for
n
in
pixel
]
r
=
int
(
br
*
r
)
g
=
int
(
bg
*
g
)
b
=
int
(
bb
*
b
)
unicornhathd
.
set_pixel
(
width
-
1
-
x
,
y
,
r
,
g
,
b
)
unicornhathd
.
show
()
time
.
sleep
(
0.02
)
except
KeyboardInterrupt
:
unicornhathd
.
off
()
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