Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Flashing updates, no buffer #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DedFishy opened this issue Dec 22, 2022 · 2 comments
Closed

Flashing updates, no buffer #9

DedFishy opened this issue Dec 22, 2022 · 2 comments

Comments

@DedFishy
Copy link

Hello, I'm using this with the intent of creating a game that utilizes the screen. However, there's no update method or anything to utilize a buffer, so every operation is immediately applied. This causes the screen to flicker and show things loading in, which is not ideal. Is there a way to fix this?

@boochow
Copy link
Owner

boochow commented Dec 29, 2022

Hi,
You want to use an off-screen buffer for drawing something and then transport the buffer to the screen, right?
Here is an example. ( I tested this code on RPi Pico + ST7735. )

from machine import SPI,Pin
from ST7735 import TFT
spi = SPI(0, baudrate=20000000, polarity=0, phase=0, sck=Pin(2), mosi=Pin(3), miso=Pin(0))
tft=TFT(spi,4,5,1)
tft.initr()
tft.rgb(True)
tft.fill(TFT.BLACK)

from framebuf import FrameBuffer, RGB565
buf = bytearray(128*160*2)
fb = FrameBuffer(buf, 128, 160, RGB565)

tft._setwindowloc((0,0),(127,159))

size=20
(xmax, ymax) = (128-size, 160-size)
(x, y) = (size, size)
(vx, vy) = (1, 1)

while True:
    fb.fill(0)
    fb.ellipse(x, y, size, size, 0xffff, True)
    x += vx
    if x == xmax or x == size:
        vx = -vx
    y += vy
    if y == ymax or y == size:
        vy = -vy
    tft._writedata(buf)

pico-spi-st7735

@DedFishy
Copy link
Author

This code works very well! Thank you so much! Maybe you should put this in as a separate script as an example, because it's a lot smoother this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants