Skip to content

Commit 7f7590b

Browse files
committed
Add prints to end of Example 1
1 parent 3cca6b0 commit 7f7590b

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

examples/ex01_hello_opencv.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,8 @@
5353
#
5454
# Note - Some MicroPython IDEs (like Thonny) don't actually send any key presses
5555
# until you hit Enter on your keyboard
56+
print("Press any key to continue")
5657
key = cv2.waitKey(0) # Not necessary to display image, can remove if desired
58+
59+
# Print the key pressed
60+
print("Key pressed:", chr(key))

examples/main.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import cv2
2+
from ulab import numpy as np
3+
from st7789_spi import ST7789_SPI
4+
import time
5+
6+
display = ST7789_SPI(width=240,
7+
height=320,
8+
spi_id=0,
9+
pin_cs=17,
10+
pin_dc=16,
11+
rotation=1)
12+
13+
x = 0
14+
y = 0
15+
vx = 10
16+
vy = 10
17+
18+
while True:
19+
img = np.zeros((240, 320, 3), dtype=np.uint8)
20+
img[0:50, :] = (255, 0, 0)
21+
img = cv2.ellipse(img, (160, 120), (100, 50), 0, 0, 360, (0, 255, 0), -1)
22+
img = cv2.putText(img, "Hello OpenCV!", (50, 200), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
23+
cv2.imshow(display, img)
24+
key = cv2.waitKey(1000)
25+
26+
edge_img = cv2.Canny(img, 100, 200)
27+
cv2.imshow(display, edge_img)
28+
key = cv2.waitKey(2000)
29+
30+
img = np.zeros((240, 320, 3), dtype=np.uint8)
31+
t0 = time.time()
32+
while time.time() - t0 < 5:
33+
# Update position
34+
x += vx
35+
y += vy
36+
if x <= 0 or x >= 320 - 50:
37+
vx = -vx # Reverse direction on x-axis
38+
if y <= 0 or y >= 240 - 50:
39+
vy = -vy # Reverse direction on y-axis
40+
41+
# Draw a square
42+
img[y:y+50, x:x+50] = (0, 0, 255)
43+
44+
cv2.imshow(display, img)
45+
46+
# Clear the square area for the next frame
47+
img[y:y+50, x:x+50] = (0, 0, 0)

0 commit comments

Comments
 (0)