mirror of
https://github.com/pimoroni/st7735-python.git
synced 2025-01-05 22:40:25 +03:00
Added framerate test
This commit is contained in:
69
examples/framerate.py
Normal file
69
examples/framerate.py
Normal file
@@ -0,0 +1,69 @@
|
||||
# Copyright (c) 2014 Adafruit Industries
|
||||
# Author: Tony DiCola
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
import time
|
||||
import sys
|
||||
import math
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageDraw
|
||||
import ST7735 as ST7735
|
||||
|
||||
SPI_SPEED_MHZ = 10 # Higher speed = higher framerate
|
||||
|
||||
# Create ST7735 LCD display class.
|
||||
disp = ST7735.ST7735(
|
||||
port=0,
|
||||
cs=0,
|
||||
dc=24,
|
||||
backlight=18,
|
||||
rotation=90,
|
||||
spi_speed_hz=10 * 1000000
|
||||
)
|
||||
|
||||
WIDTH = disp.width
|
||||
HEIGHT = disp.height
|
||||
STEPS = WIDTH * 2
|
||||
images = []
|
||||
|
||||
for step in range(STEPS):
|
||||
image = Image.new("RGB", (WIDTH, HEIGHT), (0, 0, 128))
|
||||
draw = ImageDraw.Draw(image)
|
||||
|
||||
if step % 2 == 0:
|
||||
draw.rectangle((79, 0, 159, 79), (0, 128, 0))
|
||||
else:
|
||||
draw.rectangle((0, 0, 79, 79), (0, 128, 0))
|
||||
|
||||
f = math.sin((float(step) / STEPS) * math.pi)
|
||||
offset_left = int(f * WIDTH)
|
||||
draw.ellipse((offset_left, 35, offset_left + 10, 45), (255, 0, 0))
|
||||
|
||||
images.append(image)
|
||||
|
||||
count = 0
|
||||
time_start = time.time()
|
||||
|
||||
while True:
|
||||
disp.display(images[count % len(images)])
|
||||
count += 1
|
||||
time_current = time.time() - time_start
|
||||
if count % 120 == 0:
|
||||
print("Time: {}, Frames: {}, FPS: {}".format(time_current, count, count / time_current))
|
||||
Reference in New Issue
Block a user