forked from MTN-RowinAndruscavage/STEM4T-Display-ESP32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_mood.py
104 lines (87 loc) · 1.92 KB
/
_mood.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
emoticon mood pendant using large chango_64 font
"""
import utime, gc
import st7789
import button2
import chango_64 as font
from machine import Pin
TMOMAGENTA = 0xE00E
emoticons = [
':-]',
':-?',
':-)',
':-D',
':-|',
':-O',
':-('
]
colors = [
TMOMAGENTA,
st7789.WHITE,
st7789.RED,
st7789.MAGENTA,
st7789.YELLOW,
st7789.CYAN,
st7789.GREEN,
st7789.BLUE
]
changed = 1
colored = 0
def nextEmoticon(button):
global changed
changed = 1
def prevEmoticon(button):
global changed
changed = -1
def nextColor(button):
global colored
colored = 1
def prevColor(button):
global colored
colored = -1
btn1 = button2.Button2(0)
btn1.setClickHandler(nextColor)
btn1.setDoubleClickHandler(prevColor)
btn2 = button2.Button2(35)
btn2.setClickHandler(nextEmoticon)
btn2.setDoubleClickHandler(prevEmoticon)
def display_emote(text, color):
TD.tft.rotation(3)
TD.tft.fill(st7789.BLACK)
column = 64
row = 32
# Print one character at a time
for char in text:
width = TD.tft.write_len(font, char) # get the width of the character
TD.tft.write(
font,
char,
column,
row,
color,
st7789.BLACK)
column += width
def main():
global changed, colored
timer = 0
i = 0
j = 0
while True:
btn1.loop()
btn2.loop()
if changed or colored:
if (changed != 0):
i = (i + changed) % len(emoticons)
if (colored != 0):
j = (j + colored) % len(colors)
display_emote(emoticons[i], colors[j])
changed = 0
colored = 0
timer = 0
TD.tft.rotation(2)
TD.typeset("{} felt".format(userpronoun['xe']))
TD.typeset("for %.1f s" % timer, 0, 14)
utime.sleep(0.1)
timer += 0.1
main()