mirror of
https://github.com/pimoroni/st7735-python.git
synced 2025-01-05 22:40:25 +03:00
Merge pull request #5 from pimoroni/chip-select-and-examples
Added CS pin definitions, switched to FRONT
This commit is contained in:
@@ -43,7 +43,7 @@ Running at: {}MHz
|
||||
# Create ST7735 LCD display class.
|
||||
disp = ST7735.ST7735(
|
||||
port=0,
|
||||
cs=0,
|
||||
cs=ST7735.BG_SPI_CS_FRONT,
|
||||
dc=9,
|
||||
backlight=18,
|
||||
rotation=90,
|
||||
|
||||
@@ -39,7 +39,7 @@ else:
|
||||
# Create TFT LCD display class.
|
||||
disp = ST7735.ST7735(
|
||||
port=0,
|
||||
cs=0,
|
||||
cs=ST7735.BG_SPI_CS_FRONT,
|
||||
dc=9,
|
||||
backlight=18,
|
||||
spi_speed_hz=4000000
|
||||
|
||||
@@ -39,7 +39,7 @@ image_file = sys.argv[1]
|
||||
# Create ST7735 LCD display class.
|
||||
disp = ST7735.ST7735(
|
||||
port=0,
|
||||
cs=0,
|
||||
cs=ST7735.BG_SPI_CS_FRONT,
|
||||
dc=9,
|
||||
backlight=18,
|
||||
rotation=90,
|
||||
|
||||
46
examples/scrolling-text.py
Normal file
46
examples/scrolling-text.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from PIL import Image
|
||||
from PIL import ImageDraw
|
||||
from PIL import ImageFont
|
||||
import time
|
||||
|
||||
import ST7735
|
||||
|
||||
|
||||
MESSAGE = "Hello World! How are you today?"
|
||||
|
||||
# Create ST7735 LCD display class.
|
||||
disp = ST7735.ST7735(
|
||||
port=0,
|
||||
cs=ST7735.BG_SPI_CS_FRONT,
|
||||
dc=9,
|
||||
backlight=18,
|
||||
rotation=90,
|
||||
spi_speed_hz=10000000
|
||||
)
|
||||
|
||||
# Initialize display.
|
||||
disp.begin()
|
||||
|
||||
WIDTH = disp.width
|
||||
HEIGHT = disp.height
|
||||
|
||||
|
||||
img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0))
|
||||
|
||||
draw = ImageDraw.Draw(img)
|
||||
|
||||
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 30)
|
||||
|
||||
size_x, size_y = draw.textsize(MESSAGE, font)
|
||||
|
||||
text_x = 160
|
||||
text_y = (80 - size_y) // 2
|
||||
|
||||
t_start = time.time()
|
||||
|
||||
while True:
|
||||
x = (time.time() - t_start) * 100
|
||||
x %= (size_x + 160)
|
||||
draw.rectangle((0, 0, 160, 80), (0, 0, 0))
|
||||
draw.text((int(text_x - x), text_y), MESSAGE, font=font, fill=(255, 255, 255))
|
||||
disp.display(img)
|
||||
@@ -35,7 +35,7 @@ breakout into the rear slot.
|
||||
# Create ST7735 LCD display class.
|
||||
disp = ST7735.ST7735(
|
||||
port=0,
|
||||
cs=0,
|
||||
cs=ST7735.BG_SPI_CS_FRONT,
|
||||
dc=9,
|
||||
backlight=18,
|
||||
rotation=90,
|
||||
|
||||
@@ -26,6 +26,9 @@ import spidev
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
|
||||
BG_SPI_CS_BACK = 0
|
||||
BG_SPI_CS_FRONT = 1
|
||||
|
||||
SPI_CLOCK_HZ = 16000000
|
||||
|
||||
# Constants for interacting with display registers.
|
||||
|
||||
Reference in New Issue
Block a user