BBC micro:bit
Sam's French Number Game

Introduction

This program is based on an idea that Sam had. He wanted to find some way to test himself on French words using the micro:bit. This is quite tricky because of the limitations of the display and the time it takes to enter text. This project is a compromise to try to find a starting point for Sam.

Program 1

The size of the LED matrix makes it hard to display certain French characters, the ones with accents. If we use the numbers 1 - 25 (one for each of our LEDs), no accents or special characters are needed. That means saying goodbye to zéro unless you do a little more work.

This first program is a test to prove the concept. You press the A button to light up as many LEDs as you like. Press the B button and the French word for the selected number will scroll across the screen.

from microbit import *

# function to create an image consisting of value LEDs
def nleds(value):
    img = Image('00000:'*5)
    sp = img.set_pixel
    counter = 0
    for row in range(0,5):
        for col in range(0,5):
            if counter<value:
                sp(col,row,9)
            else:
                sp(col,row,0)
            counter += 1
    return img

# List of French words
french = ["zéro","un","deux","trois","quatre","cinq","six",
    "sept","huit","neuf","dix","onze","douze","treize",
    "quatorze","quinze","seize","dix-sept","dix-huit",
    "dix-neuf","vingt","vingt et un", "vingt-deux",
    "vingt-trois","vingt-quatre", "vingt cinq"]

# Set and show the starting value for the display
counter = 1
display.show(nleds(counter))

while True:
    # Press A to change the number
    if button_a.was_pressed():
        counter += 1
        if counter == 26:
            counter = 1
        display.show(nleds(counter))
        sleep(50)
    # Press B to show the French word
    if button_b.was_pressed():
        display.scroll(french[counter])
    sleep(50)

Program 2

Sam wanted there to be some sort of quiz element to the program. In this version, a random word is chosen from the list. Then you have to turn on that many lights. Press button B to input your number and you will get a tick or a cross depending on whether or not you chose the correct number of LEDs.

from microbit import *
import random

def nleds(value):
    img = Image('00000:'*5)
    sp = img.set_pixel
    counter = 0
    for row in range(0,5):
        for col in range(0,5):
            if counter<value:
                sp(col,row,9)
            else:
                sp(col,row,0)
            counter += 1
    return img

french = ["zéro","un","deux","trois","quatre","cinq","six",
    "sept","huit","neuf","dix","onze","douze","treize",
    "quatorze","quinze","seize","dix-sept","dix-huit",
    "dix-neuf","vingt","vingt et un", "vingt-deux",
    "vingt-trois","vingt-quatre", "vingt cinq"]

def SelectNumber():
    counter = 1
    display.show(nleds(counter))
    while button_b.was_pressed()==False:
        if button_a.was_pressed():
            counter += 1
            if counter == 26:
                counter = 1
            display.show(nleds(counter))
            sleep(50)
        sleep(50)
    return counter
    
    
while True:
    question = random.randint(1,25)
    display.scroll(french[question])
    answer = SelectNumber()
    if answer==question:
        display.show(Image.YES)
    else:
        display.show(Image.NO)
    sleep(3000)

Challenges

  1. Clearly, the quiz program could do with a little more work. Perhaps there should be a set number of questions and a score to be kept. The user should be told their score at the end of the quiz.
  2. The target language words can be changed to another language. You need to think about accented characters. Not having to show any is a deal-breaker here.
  3. Some buzzing on right and wrong answers and a more sophisticated light show would beef up the game.
  4. To deal with the 0, you would need to make your own character and scroll the text as an animation. It would be more efficient to scroll the letter you can do, then animate your acute accent 'e', then scroll the other two letters.