Due to high demand, expect some shipping delays at this time - orders may not ship for up to 2-3 business days.

MagTag child's letters/numbers game
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MagTag child's letters/numbers game

by nealdt on Tue Jan 12, 2021 5:11 pm

This is a very simple and silly game I made for my 3 year old to help practice letters and numbers. On boot, it displays a random letter and then sleeps until button A or B is pressed. IRL, my child finds the MagTag in the house, she has to tell me 3 words that start with that letter. When done, she presses a button to wake the MagTag, a song plays, and a new letter is chosen. The system goes back to deep sleep and we wait until the next day to play again.

Code: Select all | TOGGLE FULL SIZE
import random
import board
from adafruit_magtag.magtag import MagTag
import alarm
from alarm.pin import PinAlarm


magtag = MagTag()
display_type = DISPLAY_LETTER

if alarm.wake_alarm:
    magtag.peripherals.neopixel_disable = False
    magtag.peripherals.neopixels.fill((0, 255, 0))
    songs = ( # Wheels on the Bus
              ((147, 2), (196, 1.5), (196, .5), (196, 1.5), (196, .5), (196, 2),
               (247, 2), (294, 2), (247, 2), (196, 2)),
              # Twinkle Twinkle
              ((196, 2), (196, 2), (294, 2), (294, 2), (330, 2), (330, 2), (294, 4),
               #(262, 2), (262, 2), (220, 2), (220, 2), (196, 4)


    song = random.choice(songs)
    for notepair in song:
        magtag.peripherals.play_tone(notepair[0], notepair[1] * 0.2)
    if alarm.wake_alarm.pin == board.BUTTON_B:
        display_type = DISPLAY_NUMBER

magtag.peripherals.neopixel_disable = True
magtag.peripherals.speaker_disable = True

if display_type == DISPLAY_LETTER:
    display_str = random.choice(LETTERS)
    display_str = str(random.randint(0, 99))

    text_font = "Merriweather-100.bdf",
        magtag.graphics.display.width // 2,
        magtag.graphics.display.height // 2,
    text_scale = 0.75,
    line_spacing = 1,
    text_anchor_point=(0.5, 0.5),
magtag.set_text(display_str, 0)


    PinAlarm(pin=board.BUTTON_A, value=False, pull=True),
    PinAlarm(pin=board.BUTTON_B, value=False, pull=True)

If button B is pressed, a random integer from 0 to 99 is displayed instead.

Potential improvements: shuffle the list of letters on first boot, and store them along with an index in sleep memory so all letters are eventually shown before any repeats. (Might be sufficient to store the random seed and re-shuffle with that seed each boot.)

Posts: 18
Joined: Mon Feb 10, 2020 5:31 pm

Re: MagTag child's letters/numbers game

by Disciple on Wed Jan 13, 2021 3:31 pm

That's delightful. Thank you for sharing this. I hope it catches on.

I'm compelled to share my tip for a parent with a heart for learning, how my mother made a preschool reader out of me. It was low-tech. She regularly sat down with her little ones and a book, and would read to them. Her moving finger tracked word by word, and those little eyes and neurons took it in, sound and vision, and the language acquisition machinery absorbed it. Reading became hard-coded. When I entered school, I was surprised that the class was starting at ABC.
I share this tip wherever I can, presenting little ones with words spoken and printed, with that moving finger. I wish every child could be blessed with what I was given. Best of success to you and your family.

[Edit:] If you upload a photo, this project might get a mention in the Adafruit blog. (c:


Posts: 840
Joined: Tue Jan 06, 2015 8:13 pm

Re: MagTag child's letters/numbers game

by nealdt on Wed Jan 13, 2021 10:49 pm

Thanks :). Reading is also big in my family; my mom worked for the public library for 30 years and I spent half my childhood there. I made a letter-matching game when she was just learning her letters as my first Arduino project, a Feather 328P with a TFT screen. Obviously there are tons of phone apps for this purpose too, but phones are expensive. The MagTag works great! Low power, inexpensive, sounds, and I can hide it all over the house with the magnet feet :).

I posted a picture, though it's probably not worth much -- just a letter!

magtag_game.jpg (198.74 KiB) Viewed 370 times

Posts: 18
Joined: Mon Feb 10, 2020 5:31 pm

Please be positive and constructive with your questions and comments.