Philip Cua
Published

Competitive Math Training Thru Microbit Icons(MasterVersion)

A Microbit-based game to help teachers train their students in math through a fun & competitive manner by counting LEDs in icons.

IntermediateFull instructions provided1 hour1,225
Competitive Math Training Thru Microbit Icons(MasterVersion)

Things used in this project

Hardware components

BBC micro:bit board
BBC micro:bit board
×1
Kitronik MI:Power Board
×1
Kitronik MI:pro Protector Case
×1

Story

Read more

Code

A Microbit-Based Competitive Math Training Game Using the Counting of Icon LEDs (Master Version)

JavaScript
It's a Math teacher's tool for training her students in math through a fun and competitive manner.
let Ictr3 = 0
let IctrLst: number[] = []
let Ictr2 = 0
let Z = 0
let Ictr1 = 0
let Y = 0
let Img3: Image = null
let IconLst: Image[] = []
let CorrectID = 0
let RadioCorrectID = 0
let Answer = 0
let Img2: Image = null
let LupSw = 0
let GotCorrect = 0
let RadioIconStr = 0
let Img1: Image = null
let X = 0
let PressButtA = 0
let Lvl = 0
let ReceiveSw = 0
let Eqn = 0
let serial2 = 0
input.onButtonPressed(Button.A, () => {
    if (PressButtA == 0) {
        if (Lvl == 0) {
            X = Math.randomRange(0, 6)
            LupSw = 0
            while (LupSw == 0) {
                Y = Math.randomRange(0, 6)
                if (X != Y) {
                    LupSw = 1
                }
            }
            LupSw = 0
            Z = Math.randomRange(0, 6)
            while (LupSw == 0) {
                if (Z == X) {
                    Z = Math.randomRange(0, 6)
                } else {
                    if (Z == Y) {
                        Z = Math.randomRange(0, 6)
                    } else {
                        LupSw = 1
                    }
                }
            }
        } else {
            X = Math.randomRange(0, 16)
            LupSw = 0
            while (LupSw == 0) {
                Y = Math.randomRange(0, 16)
                if (X != Y) {
                    LupSw = 1
                }
            }
            LupSw = 0
            Z = Math.randomRange(0, 16)
            while (LupSw == 0) {
                if (Z == X) {
                    Z = Math.randomRange(0, 16)
                } else {
                    if (Z == Y) {
                        Z = Math.randomRange(0, 16)
                    } else {
                        LupSw = 1
                    }
                }
            }
        }
        Img1 = IconLst[X]
        Img2 = IconLst[Y]
        Img3 = IconLst[Z]
        Ictr1 = IctrLst[X]
        Ictr2 = IctrLst[Y]
        Ictr3 = IctrLst[Z]
        X += 10
        Y += 10
        Z += 10
        Answer = Ictr1 + (Ictr2 + Ictr3)
        Eqn = X * 10000
        Eqn += Y * 100
        Eqn += Z
        PressButtA = 1
        ReceiveSw = 1
        RadioIconStr = 1
    }
    basic.clearScreen()
    Img1.showImage(0)
    basic.pause(1000)
    Img2.showImage(0)
    basic.pause(1000)
    Img3.showImage(0)
    basic.pause(1000)
    basic.clearScreen()
})
input.onButtonPressed(Button.B, () => {
    if (PressButtA == 1) {
        basic.clearScreen()
        basic.showNumber(Answer)
        basic.pause(500)
        basic.clearScreen()
    }
})
radio.onDataPacketReceived( ({ receivedString: name, receivedNumber: value, serial: serial2 }) =>  {
    if (name == "IANS") {
        if (ReceiveSw == 1) {
            if (GotCorrect == 0) {
                if (Answer == value) {
                    CorrectID = serial2
                    ReceiveSw = 0
                    GotCorrect = 1
                    RadioCorrectID = 1
                    RadioIconStr = 0
                    for (let i = 0; i < 2; i++) {
                        basic.clearScreen()
                        basic.showIcon(IconNames.Yes)
                    }
                    music.beginMelody(music.builtInMelody(Melodies.PowerUp), MelodyOptions.Once)
                }
            }
        }
    }
})
input.onButtonPressed(Button.AB, () => {
    Eqn = 0
    ReceiveSw = 0
    GotCorrect = 0
    X = 0
    Y = 0
    Z = 0
    RadioIconStr = 0
    RadioCorrectID = 0
    PressButtA = 0
    Answer = 0
    basic.clearScreen()
})
input.onGesture(Gesture.Shake, () => {
    if (Lvl == 0) {
        Lvl = 1
        basic.clearScreen()
        basic.showLeds(`
            # . . # .
            # . # # .
            # . . # .
            # . . # .
            # # . # .
            `)
        basic.pause(1000)
        basic.clearScreen()
    } else {
        Lvl = 0
        basic.clearScreen()
        basic.showLeds(`
            # . . # .
            # . # . #
            # . # . #
            # . # . #
            # # . # .
            `)
        basic.pause(1000)
        basic.clearScreen()
    }
})
radio.setGroup(25)
radio.setTransmitSerialNumber(true)
Eqn = 0
ReceiveSw = 0
GotCorrect = 0
X = 0
Y = 0
Z = 0
RadioIconStr = 0
RadioCorrectID = 0
PressButtA = 0
Answer = 0
Lvl = 0
IconLst = [images.createImage(`
    # . . . #
    . # # # .
    . . # . .
    . # . # .
    # . . . #
    `), images.createImage(`
    . . . . .
    . # # # .
    . . # . .
    . # # # .
    . . . . .
    `), images.createImage(`
    . . . . .
    . . . . .
    . # . # .
    . . . . .
    . . . . .
    `), images.createImage(`
    . . # . .
    . . . . .
    . . # . .
    . . . . .
    . . # . .
    `), images.createImage(`
    . # . # .
    . . . . .
    . . . . .
    . # . # .
    . . . . .
    `), images.createImage(`
    . # . # .
    . . . . .
    . . # . .
    . . . . .
    . # . # .
    `), images.createImage(`
    . # . # .
    . . . . .
    . # . # .
    . . . . .
    . # . # .
    `), images.createImage(`
    # # . # #
    . # . # .
    . # # # .
    . # . # .
    # # . # #
    `), images.createImage(`
    # # . # #
    . . . . .
    # # # # #
    . . . . .
    # # . # #
    `), images.createImage(`
    . # . # .
    # . # . #
    . # . # .
    # . # . #
    . # . # .
    `), images.createImage(`
    . # . # .
    . . . . .
    # # # # #
    . . . . .
    . # . # .
    `), images.createImage(`
    . # # # .
    . # . . .
    . # # # .
    . . . # .
    . # # . .
    `), images.createImage(`
    . # # # .
    . . . . #
    . . # # .
    . . . . #
    . # # # .
    `), images.createImage(`
    . # . # .
    # # # # #
    # # # # #
    . # # # .
    . . # . .
    `), images.createImage(`
    # # . # #
    # # # # #
    . . # . .
    # # # # #
    # # . # #
    `), images.createImage(`
    . # # # .
    # . # . #
    # # # # #
    # # # # #
    # . # . #
    `)]
IctrLst = [10, 7, 2, 3, 4, 5, 6, 15, 13, 12, 9, 10, 10, 16, 19, 19]
basic.forever(() => {
    if (RadioIconStr == 1) {
        radio.sendValue("ICON", Eqn)
    }
    if (RadioCorrectID == 1) {
        radio.sendValue("IID", CorrectID)
    }
})

Credits

Philip Cua

Philip Cua

4 projects • 0 followers
Thanks to Marcus Loo Cua.

Comments