Skip to content

Commit 8fe347d

Browse files
asterix24danieledapo
authored andcommitted
ports: esp32: buttons: add simple class to manage user buttons.
1 parent 42b0606 commit 8fe347d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

ports/esp32/modules/buttons.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from hw_cfg import *
2+
import machine
3+
import utime
4+
import icons
5+
6+
class Buttons:
7+
def __init__(self, d):
8+
self.display = d
9+
self.flag = True
10+
self.pulse = False
11+
user_btn_pin.irq(self.__pulse, trigger=machine.Pin.IRQ_RISING)
12+
print("init buttons module")
13+
self.welcome()
14+
15+
def __pulse(self, b):
16+
print(b)
17+
if not self.pulse:
18+
self.pulse = True
19+
self.show_time()
20+
21+
def welcome(self):
22+
self.display.blit(icons.logo, 0, 0)
23+
self.display.show()
24+
utime.sleep_ms(2000)
25+
self.display.fill(0)
26+
self.display.text('Hello Otto!', 20, 30)
27+
self.display.show()
28+
utime.sleep_ms(1000)
29+
self.display.fill(0)
30+
self.display.show()
31+
32+
def show_time(self):
33+
utime.sleep_ms(100)
34+
self.display.fill(0)
35+
if self.flag:
36+
self.display.blit(icons.logo, 0, 0)
37+
self.display.show()
38+
utime.sleep_ms(1000)
39+
self.display.fill(0)
40+
year, month, day, hour, minute, second, _, _ = utime.localtime()
41+
month if len(str(month)) > 1 else "0" + str(month)
42+
day if len(str(day)) > 1 else "0" + str(day)
43+
hour if len(str(hour)) > 1 else "0" + str(hour)
44+
minute if len(str(minute)) > 1 else "0" + str(minute)
45+
second if len(str(second)) > 1 else "0" + str(second)
46+
self.display.text("%s/%s/%s" % (day, month, year), 20, 20)
47+
self.display.text("%s:%s:%s" % (hour, minute, second), 20, 30)
48+
self.display.show()
49+
self.flag = not self.flag
50+
self.pulse = False
51+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy