-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f080380
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- Pull micropython for rp2350 (not yet merged to micropython repo) https://github.com/dpgeorge/micropython/tree/rp2-add-rp2350 | ||
- Pull st7789_mpy from https://github.com/russhughes/st7789_mpy | ||
- Install tools for building micropython | ||
- Build micropython for rp2350 with st7789_mpy `make BOARD=RPI_PICO2 USER_C_MODULES=path/to/st7789_mpy/st7789/micropython.cmake` | ||
- Flash firmware.u2f | ||
- Run python code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
""" | ||
ST7789 example for DC32 badge | ||
""" | ||
import st7789 | ||
import tft_config | ||
from machine import Pin | ||
import neopixel | ||
import time | ||
|
||
|
||
num_pixels = 9 | ||
np = neopixel.NeoPixel(machine.Pin(4), num_pixels) | ||
tft = tft_config.config(3, buffer_size=4096) #rotation 3 for normal orientation, 1 for upside down | ||
|
||
def wheel(pos): | ||
# Input a value 0 to 255 to get a color value. | ||
# The colours are a transition r - g - b - back to r. | ||
if pos < 0 or pos > 255: | ||
return (0, 0, 0) | ||
if pos < 85: | ||
return (255 - pos * 3, pos * 3, 0) | ||
if pos < 170: | ||
pos -= 85 | ||
return (0, 255 - pos * 3, pos * 3) | ||
pos -= 170 | ||
return (pos * 3, 0, 255 - pos * 3) | ||
|
||
def rainbow_cycle(wait): | ||
for j in range(255): | ||
for i in range(num_pixels): | ||
rc_index = (i * 256 // num_pixels) + j | ||
np[i] = wheel(rc_index & 255) | ||
np.write() | ||
time.sleep(0.01) | ||
|
||
RED = (255, 0, 0) | ||
YELLOW = (255, 150, 0) | ||
GREEN = (0, 255, 0) | ||
CYAN = (0, 255, 255) | ||
BLUE = (0, 0, 255) | ||
PURPLE = (180, 0, 255) | ||
|
||
|
||
|
||
def demo(np): | ||
n = np.n | ||
|
||
for i in range(0, 4 * 256, 8): | ||
for j in range(n): | ||
if (i // 256) % 2 == 0: | ||
val = i & 0xff | ||
else: | ||
val = 255 - (i & 0xff) | ||
np[j] = (val, 0, 0) | ||
np.write() | ||
|
||
def main(): | ||
|
||
# Initial colors | ||
|
||
np[0] = (255, 0, 0) | ||
np[1] = (0, 128, 0) | ||
np[2] = (0, 0, 64) | ||
np[3] = (255, 0, 0) | ||
np[4] = (0, 128, 0) | ||
np[5] = (0, 0, 64) | ||
np[6] = (255, 0, 0) | ||
np[7] = (0, 128, 0) | ||
np[8] = (0, 0, 64) | ||
|
||
np.write() | ||
|
||
png_file_name = f'lhc-320x240.png' | ||
tft.init() | ||
print(f'Displaying {png_file_name}') | ||
tft.png(png_file_name, 0, 0) | ||
|
||
while(True): | ||
rainbow_cycle(0) # Increase the number to slow down the rainbow | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""DC32 Badge display config""" | ||
|
||
from machine import Pin, SoftSPI | ||
from time import sleep | ||
import st7789 | ||
|
||
TFA = 40 # top free area when scrolling | ||
BFA = 40 # bottom free area when scrolling | ||
|
||
def config(rotation=0, buffer_size=0, options=0): | ||
spi = SoftSPI(baudrate=62500000, | ||
polarity=0, | ||
phase=0, | ||
sck=Pin(8), | ||
mosi=Pin(6), | ||
miso=Pin(28)) #SoftSPI needs a MISO pin, used one of the gpio on the SAO | ||
|
||
return st7789.ST7789( | ||
spi, | ||
240, | ||
320, | ||
cs=Pin(9, Pin.OUT), | ||
dc=Pin(5, Pin.OUT), | ||
backlight=Pin(10, Pin.OUT), | ||
rotation=rotation, | ||
options=options, | ||
buffer_size=buffer_size, | ||
color_order=st7789.RGB, | ||
inversion=False) |