Merge pull request #4 from pimoroni/backlight-fix

Fix fix backlight pin state, add `set_backlight`
This commit is contained in:
Philip Howard
2019-02-21 10:21:33 +00:00
committed by GitHub
5 changed files with 45 additions and 4 deletions

View File

@@ -20,6 +20,7 @@
# THE SOFTWARE.
import time
import math
import sys
from PIL import Image
from PIL import ImageDraw
@@ -27,6 +28,18 @@ import ST7735 as ST7735
SPI_SPEED_MHZ = 10 # Higher speed = higher framerate
if len(sys.argv) > 1:
SPI_SPEED_MHZ = int(sys.argv[1])
print("""
framerate.py - Test LCD framerate.
If you're using Breakout Garden, plug the 0.96" LCD (SPI)
breakout into the rear slot.
Running at: {}MHz
""".format(SPI_SPEED_MHZ))
# Create ST7735 LCD display class.
disp = ST7735.ST7735(
port=0,
@@ -34,7 +47,7 @@ disp = ST7735.ST7735(
dc=9,
backlight=18,
rotation=90,
spi_speed_hz=10 * 1000000
spi_speed_hz=SPI_SPEED_MHZ * 1000000
)
WIDTH = disp.width
@@ -65,7 +78,7 @@ while True:
count += 1
time_current = time.time() - time_start
if count % 120 == 0:
print("Time: {}, Frames: {}, FPS: {}".format(
print("Time: {:8.3f}, Frames: {:6d}, FPS: {:8.3f}".format(
time_current,
count,
count / time_current))

View File

@@ -23,6 +23,13 @@ import ST7735
import time
import sys
print("""
gif.py - Display a gif on the LCD.
If you're using Breakout Garden, plug the 0.96" LCD (SPI)
breakout into the rear slot.
""")
if len(sys.argv) > 1:
image_file = sys.argv[1]
else:

View File

@@ -23,6 +23,13 @@ import sys
from PIL import Image
import ST7735 as ST7735
print("""
image.py - Display an image on the LCD.
If you're using Breakout Garden, plug the 0.96" LCD (SPI)
breakout into the rear slot.
""")
if len(sys.argv) < 2:
print("Usage: {} <image_file>".format(sys.argv[0]))
sys.exit(1)
@@ -42,8 +49,6 @@ disp = ST7735.ST7735(
WIDTH = disp.width
HEIGHT = disp.height
print(WIDTH, HEIGHT)
# Initialize display.
disp.begin()

View File

@@ -24,6 +24,13 @@ from PIL import ImageFont
import ST7735
print("""
shapes.py - Display test shapes on the LCD using PIL.
If you're using Breakout Garden, plug the 0.96" LCD (SPI)
breakout into the rear slot.
""")
# Create ST7735 LCD display class.
disp = ST7735.ST7735(

View File

@@ -176,8 +176,12 @@ class ST7735(object):
GPIO.setup(dc, GPIO.OUT)
# Setup backlight as output (if provided).
self._backlight = backlight
if backlight is not None:
GPIO.setup(backlight, GPIO.OUT)
GPIO.output(backlight, GPIO.LOW)
time.sleep(0.1)
GPIO.output(backlight, GPIO.HIGH)
# Setup reset as output (if provided).
if rst is not None:
@@ -202,6 +206,11 @@ class ST7735(object):
end = min(start + chunk_size, len(data))
self._spi.xfer(data[start:end])
def set_backlight(self, value):
"""Set the backlight on/off."""
if self._backlight is not None:
GPIO.output(self._backlight, value)
@property
def width(self):
return self._width if self._rotation == 0 or self._rotation == 180 else self._height