I'm a newbie on micropython, and after few programs, i'm in a dead end.
I'm trying to code a little quiz game with a RPi Pico, and a lcd 240x240 (waveshare round GC9A01).
The objective is:
1: Click on the momentary button
1: Show the picture with the question
2: During 3minutes, the image stay and the button is lock.
3: After 3minutes, the button is unlock, and a pressure show the second picture
4: During 3minutes, the image stay and the button is lock.
5: ... Same till image n°10...
6: When image "11" we return to the image n°1.
Here is the code i wrote (sorry some informations are in french in it):
Code: Select all
"""
Test quizz v3
Images changeantes appuie boutton après 3minutes.
Ecran GC9A01 connecté au Raspberry Pi Pico. (firmware de RussHughes)
Bouton momentané en GP28
"""
import gc
import time
import machine
import gc9a01 # import librairie écran chargé dans firmware
button = machine.Pin(28 machine.Pin.IN, machine.Pin.PULL_UP) [b]#momentary button[/b]
var = None # Création variable pour changement de nom d'image
gc.enable()
gc.collect()
def gpio_set(pin,value): #[b] Def gpio for display[/b]
if value >= 1:
Pin(pin, Pin.OUT).on()
else:
Pin(pin, Pin.OUT).off()
def main(): # déclaration écran
spi = SPI(1, baudrate=60000000, sck=Pin(14), mosi=Pin(15))
tft = gc9a01.GC9A01(
spi,
240,
240,
reset=Pin(11, Pin.OUT),
cs=Pin(13, Pin.OUT),
dc=Pin(12, Pin.OUT),
backlight=Pin(10, Pin.OUT),
rotation=2) # ecran 180deg, mettre 0 pour normal
tft.init() # active ecran et ecran noir
while True:
gpio_set((25), True)
if not button.value(): #lecture état bouton
tft.jpg("image"var".jpg", 0, 0, gc9a01.SLOW) # afficher sur ecran image'var'.jpg . Penser a renommer les images
utime.sleep_ms(500) #attente 500ms pour agir comme debouncer
var = (var if isinstance(var, int) else 0) + 1 # var +1
if var == 10: # si var=10 (10eme image) alors var devient 1
var = 1
utime.sleep_s(180) #blocage de l'image pendant 3minutes
Code: Select all
def gpio_set(pin,value): # Def gpio for display
if value >= 1:
Pin(pin, Pin.OUT).on()
else:
Pin(pin, Pin.OUT).off()
Code: Select all
button = machine.Pin(28 machine.Pin.IN, machine.Pin.PULL_UP) #momentary button
I will be great to talk with you!
(Even if you don't have any solutions, i will still be glad to talk with you )
Bye.
PS: Please excuse my basic english, i'm still learning it.