How to build a quiz game?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
totorock
Posts: 1
Joined: Sun Oct 10, 2021 9:10 am

How to build a quiz game?

Post by totorock » Tue Oct 12, 2021 5:26 am

Hello everybody.

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
        
The problem seems to be the opposition between:

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()
    
and

Code: Select all

button = machine.Pin(28 machine.Pin.IN, machine.Pin.PULL_UP) #momentary button
So if anyone have an idea to resolve this and can help me to understand this problem.
I will be great to talk with you! :D
(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.

FillSmith
Posts: 2
Joined: Sun Sep 26, 2021 8:01 am

Re: How to build a quiz game?

Post by FillSmith » Wed Jun 22, 2022 6:57 am

Hello dude, Im really sorry for bumping old thread. Just asking your little help, Im newbie and starting to build quiz game, and stuck. play jet x on 9winz

Post Reply