sync
This commit is contained in:
parent
4013d38a31
commit
e37013c219
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
||||
à tester : https://github.com/pimoroni/st7789-python/blob/master/examples/image.py
|
||||
|
||||
comment afficher des images ? https://github.com/devbis/st7789py_mpy/issues/2
|
||||
3
hello/README.md
Normal file
3
hello/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# README.md
|
||||
|
||||
Source: https://github.com/russhughes/st7789_mpy/blob/master/examples/time_trial.py
|
||||
40
hello/main.py
Normal file
40
hello/main.py
Normal file
@ -0,0 +1,40 @@
|
||||
"""
|
||||
Writes "Hello!" at different locations.
|
||||
"""
|
||||
|
||||
import random
|
||||
from machine import Pin, SPI
|
||||
import st7789 as st7789
|
||||
import time
|
||||
import utime
|
||||
|
||||
# Choose a font
|
||||
#from fonts import vga1_8x8 as font
|
||||
#from fonts import vga2_8x8 as font
|
||||
#from fonts import vga1_8x16 as font
|
||||
from fonts import vga2_8x16 as font
|
||||
#from fonts import vga1_16x16 as font
|
||||
#from fonts import vga1_bold_16x16 as font
|
||||
#from fonts import vga2_16x16 as font
|
||||
#from fonts import vga2_bold_16x16 as font
|
||||
|
||||
def main():
|
||||
tft = st7789.ST7789(
|
||||
SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)),
|
||||
135,
|
||||
240,
|
||||
reset=Pin(23, Pin.OUT),
|
||||
cs=Pin(5, Pin.OUT),
|
||||
dc=Pin(16, Pin.OUT),
|
||||
backlight=Pin(4, Pin.OUT),
|
||||
rotation=3
|
||||
)
|
||||
tft.init()
|
||||
|
||||
tft.fill(st7789.BLACK)
|
||||
tft.text(font, "MicroPython", 0, 0, st7789.WHITE)
|
||||
tft.text(font, "MicroPython", 0, 32, st7789.RED)
|
||||
tft.text(font, "MicroPython", 0, 64, st7789.GREEN)
|
||||
tft.text(font, "MicroPython", 0, 96, st7789.BLUE)
|
||||
|
||||
main()
|
||||
4
hello2/README.md
Normal file
4
hello2/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
# README.md
|
||||
|
||||
Source: https://github.com/russhughes/st7789_mpy/blob/master/examples/ttgo_hello.py
|
||||
Exemple youtube: https://www.youtube.com/watch?v=-spQgQPzGO0
|
||||
@ -1,13 +1,24 @@
|
||||
"""
|
||||
Writes "Hello!" in random colors at random locations.
|
||||
"""
|
||||
|
||||
import random
|
||||
from machine import Pin, SPI
|
||||
import st7789
|
||||
|
||||
# Choose a font
|
||||
#from fonts import vga1_8x8 as font
|
||||
from fonts import vga2_bold_16x32 as font
|
||||
#from fonts import vga2_8x8 as font
|
||||
#from fonts import vga1_8x16 as font
|
||||
#from fonts import vga2_8x16 as font
|
||||
#from fonts import vga1_16x16 as font
|
||||
#from fonts import vga1_bold_16x16 as font
|
||||
#from fonts import vga2_16x16 as font
|
||||
from fonts import vga2_bold_16x16 as font
|
||||
|
||||
def main():
|
||||
spi = SPI(2, baudrate=30000000, polarity=1, sck=Pin(18), mosi=Pin(19))
|
||||
tft = st7789.ST7789(
|
||||
spi,
|
||||
SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)),
|
||||
135,
|
||||
240,
|
||||
reset=Pin(23, Pin.OUT),
|
||||
1
rainbow_buttons/README.md
Normal file
1
rainbow_buttons/README.md
Normal file
@ -0,0 +1 @@
|
||||
Source: https://gist.github.com/paulwinex/a65f0a36485ae1dea3de4a82f647949a
|
||||
71
rainbow_buttons/main.py
Normal file
71
rainbow_buttons/main.py
Normal file
@ -0,0 +1,71 @@
|
||||
import time
|
||||
from machine import Pin, SPI
|
||||
import st7789 as st7789
|
||||
from random import randrange, choice
|
||||
|
||||
|
||||
def hsv_to_rgb(h, s, v):
|
||||
if s == 0.0:
|
||||
return v, v, v
|
||||
i = int(h * 6.0) # XXX assume int() truncates!
|
||||
f = (h * 6.0) - i
|
||||
p = v * (1.0 - s)
|
||||
q = v * (1.0 - s * f)
|
||||
t = v * (1.0 - s * (1.0 - f))
|
||||
i = i % 6
|
||||
if i == 0:
|
||||
return int(v * 255), int(t * 255), int(p * 255)
|
||||
if i == 1:
|
||||
return int(q * 255), int(v * 255), int(p * 255)
|
||||
if i == 2:
|
||||
return int(p * 255), int(v * 255), int(t * 255)
|
||||
if i == 3:
|
||||
return int(p * 255), int(q * 255), int(v * 255)
|
||||
if i == 4:
|
||||
return int(t * 255), int(p * 255), int(v * 255)
|
||||
if i == 5:
|
||||
return int(v * 255), int(p * 255), int(q * 255)
|
||||
# Cannot get here
|
||||
|
||||
|
||||
def rainbow():
|
||||
print('RAINBOW')
|
||||
for i in range(240):
|
||||
color = st7789.color565(*hsv_to_rgb(i / 240, 1.0, 1.0))
|
||||
tft.hline(0, i, 135, color)
|
||||
|
||||
|
||||
def fill():
|
||||
print('FILL')
|
||||
tft.fill_rect(0, 0, 135, 240, st7789.color565(
|
||||
randrange(0, 255), randrange(0, 255), randrange(0, 255)
|
||||
))
|
||||
|
||||
|
||||
def main():
|
||||
p1 = Pin(0, Pin.IN)
|
||||
p2 = Pin(35, Pin.IN)
|
||||
|
||||
time.sleep(0.5)
|
||||
tft = st7789.ST7789(
|
||||
SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)),
|
||||
135,
|
||||
240,
|
||||
reset=Pin(23, Pin.OUT),
|
||||
cs=Pin(5, Pin.OUT),
|
||||
dc=Pin(16, Pin.OUT),
|
||||
backlight=Pin(4, Pin.OUT),
|
||||
rotation=0
|
||||
)
|
||||
tft.init()
|
||||
|
||||
time.sleep(0.5)
|
||||
fill()
|
||||
while True:
|
||||
if not p1.value():
|
||||
rainbow()
|
||||
elif not p2.value():
|
||||
fill()
|
||||
time.sleep(0.1)
|
||||
|
||||
main()
|
||||
3
scroll_font/README.md
Normal file
3
scroll_font/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# README.md
|
||||
|
||||
Source: https://github.com/russhughes/st7789_mpy/blob/master/examples/scroll_font.py
|
||||
66
scroll_font/main.py
Normal file
66
scroll_font/main.py
Normal file
@ -0,0 +1,66 @@
|
||||
"""
|
||||
Smoothly scrolls all font characters up the screen.
|
||||
Only works with fonts with heights that are even multiples of the screen height, (i.e. 8 or 16 pixels high)
|
||||
|
||||
Non-functionnal: after some chars the screen is broken
|
||||
"""
|
||||
|
||||
import utime
|
||||
import random
|
||||
from machine import Pin, SPI
|
||||
import st7789
|
||||
|
||||
# Choose a font
|
||||
#from fonts import vga1_8x8 as font
|
||||
#from fonts import vga2_8x8 as font
|
||||
#from fonts import vga1_8x16 as font
|
||||
from fonts import vga2_8x16 as font
|
||||
#from fonts import vga1_16x16 as font
|
||||
#from fonts import vga1_bold_16x16 as font
|
||||
#from fonts import vga2_16x16 as font
|
||||
#from fonts import vga2_bold_16x16 as font
|
||||
|
||||
def main():
|
||||
tft = st7789.ST7789(
|
||||
SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)),
|
||||
135,
|
||||
240,
|
||||
reset=Pin(23, Pin.OUT),
|
||||
cs=Pin(5, Pin.OUT),
|
||||
dc=Pin(16, Pin.OUT),
|
||||
backlight=Pin(4, Pin.OUT),
|
||||
rotation=0
|
||||
)
|
||||
tft.init()
|
||||
|
||||
last_line = tft.height() - font.HEIGHT
|
||||
tfa = 40
|
||||
tfb = 40
|
||||
tft.vscrdef(tfa, 240, tfb)
|
||||
|
||||
tft.fill(st7789.BLUE)
|
||||
scroll = 0
|
||||
character = 0
|
||||
while True:
|
||||
tft.fill_rect(0,scroll, tft.width(), 1, st7789.BLUE)
|
||||
|
||||
if scroll % font.HEIGHT == 0:
|
||||
tft.text(
|
||||
font,
|
||||
'\\x{:02x}= {:s} '.format(character, chr(character)),
|
||||
0,
|
||||
(scroll + last_line) % tft.height(),
|
||||
st7789.WHITE,
|
||||
st7789.BLUE)
|
||||
|
||||
character = character +1 if character < 256 else 0
|
||||
|
||||
tft.vscsad(scroll+tfa)
|
||||
scroll +=1
|
||||
|
||||
if scroll == tft.height:
|
||||
scroll = 0
|
||||
|
||||
utime.sleep(0.01)
|
||||
|
||||
main()
|
||||
69
wifi/main.py
69
wifi/main.py
@ -1,15 +1,66 @@
|
||||
"""
|
||||
Connect to a Wifi Hotspot, creds are stored in 'creds' file.
|
||||
|
||||
"""
|
||||
|
||||
import network
|
||||
|
||||
file = open('creds', 'r')
|
||||
wifi_ssid = file.readline().rstrip("\n")
|
||||
wifi_pass = file.readline().rstrip("\n")
|
||||
file.close()
|
||||
# For display
|
||||
import random
|
||||
from machine import Pin, SPI
|
||||
import st7789 as st7789
|
||||
import time
|
||||
import utime
|
||||
# Choose a font
|
||||
#from fonts import vga1_8x8 as font
|
||||
#from fonts import vga2_8x8 as font
|
||||
#from fonts import vga1_8x16 as font
|
||||
from fonts import vga2_8x16 as font
|
||||
#from fonts import vga1_16x16 as font
|
||||
#from fonts import vga1_bold_16x16 as font
|
||||
#from fonts import vga2_16x16 as font
|
||||
#from fonts import vga2_bold_16x16 as font
|
||||
|
||||
wlan = network.WLAN(network.STA_IF)
|
||||
wlan.active(True)
|
||||
if not wlan.isconnected():
|
||||
print('connecting to network...')
|
||||
def main():
|
||||
tft = st7789.ST7789(
|
||||
SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)),
|
||||
135,
|
||||
240,
|
||||
reset=Pin(23, Pin.OUT),
|
||||
cs=Pin(5, Pin.OUT),
|
||||
dc=Pin(16, Pin.OUT),
|
||||
backlight=Pin(4, Pin.OUT),
|
||||
rotation=3
|
||||
)
|
||||
tft.init()
|
||||
tft.fill(st7789.BLACK)
|
||||
|
||||
file = open('creds', 'r')
|
||||
wifi_ssid = file.readline().rstrip("\n")
|
||||
wifi_pass = file.readline().rstrip("\n")
|
||||
file.close()
|
||||
|
||||
wlan = network.WLAN(network.STA_IF)
|
||||
wlan.active(True)
|
||||
if not wlan.isconnected():
|
||||
tft.text(font, "Init", 0, 0, st7789.WHITE)
|
||||
print('Init connection to Wifi...')
|
||||
wlan.connect(wifi_ssid, wifi_pass)
|
||||
while not wlan.isconnected():
|
||||
tft.text(font, "Connecting ...", 0, 0, st7789.RED)
|
||||
print('connecting...')
|
||||
utime.sleep(1)
|
||||
tft.text(font, "Connecting ...", 0, 0, st7789.BLACK)
|
||||
pass
|
||||
print('network config:', wlan.ifconfig())
|
||||
|
||||
tft.text(font, "Connected", 0, 0, st7789.WHITE)
|
||||
print('Connected')
|
||||
|
||||
wlan_config = wlan.ifconfig()
|
||||
print('network config:', wlan_config)
|
||||
tft.text(font, "IP/network: ", 0, 32, st7789.WHITE)
|
||||
tft.text(font, wlan_config[0] + "/" + wlan_config[1], 10, 53, st7789.GREEN)
|
||||
tft.text(font, "Gw/DNS: ", 0, 75, st7789.WHITE)
|
||||
tft.text(font, wlan_config[2] + "/" + wlan_config[3], 10, 96, st7789.GREEN)
|
||||
|
||||
main()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user