forked from antirez/t-watch-s3-micropython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
54 lines (44 loc) · 1.33 KB
/
main.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
# Example program for the T-WATCH S3
import random
from machine import Pin, SoftSPI
import st7789py as st7789
import time
from axp2101 import AXP2101
from haptic_motor import HAPTIC_MOTOR
def main():
# Setup the PMU chip.
twatch_pmu = AXP2101()
twatch_pmu.twatch_s3_poweron()
print("[AXP2101] Battery voltage is", twatch_pmu.get_battery_voltage())
# Power on the display backlight.
bl = Pin(45,Pin.OUT)
bl.on()
sck_pin = Pin(18)
mosi_pin = Pin(13)
# Our display does not have a MISO pin, but the MicroPython
# SoftSPI implementation does not allow to avoid specifying one, so
# we use just a not used pin in the device.
notused_miso_pin = Pin(37)
spi = SoftSPI(baudrate=40000000, polarity=1, sck=sck_pin, mosi=mosi_pin, miso=notused_miso_pin)
display = st7789.ST7789(
spi, 240, 240,
reset=False,
dc=Pin(38, Pin.OUT),
cs=Pin(12, Pin.OUT),
)
display.init()
# vibrate using effect 14
motor = HAPTIC_MOTOR(14)
motor.vibrate()
print("displaying random colors")
while True:
display.fill(
st7789.color565(
random.getrandbits(8),
random.getrandbits(8),
random.getrandbits(8),
),
)
# Pause 2 seconds.
time.sleep(2)
main()