Generating geomantic figures with Micro:bit

 So, I did talk about geomancy before and how many different ways there are to generate the figures, so let's look at the modern one. BBC Micro:bit is a pocket-sized computer that is perfect for getting introduced into hardware programming. You simply buy the little bugger, connect it to your computer, and then go to https://makecode.microbit.org/, there you can go through the tutorials, make your code, and download it to the Micro:bit.  There are also a ton of prepared projects for you including automated plant watering, making RC models, etc.

But enough with the unpaid advertisement for the little bugger. You can also use it to generate geomantic figures. Here's what the use-case look like:


Not bad, right? This loud noise detection is a functionality of Micro:bit V2, if you got the first version, you can use either the buttons or you can code the Micro:bit to detect shaking, etc.


And this is what the code looks like in JavaScript:

// Figure is the set of four numbers
let figure: number[] = []
let partValue = 0

// Displays the generated figure
function displayFigure (figure: number[]) {
    basic.showLeds(`
        . . . . .
        . . . . .
        . . . . .
        . . . . .
        . . . . .
        `)
    for (let i = 0; i <= 3; i++) {
        displayLine(i, figure[i])
    }
}

// Generates the figure, meaning the four numbers, either value 1 or 2
function generateFigure () {
    figure = [
    0,
    0,
    0,
    0
    ]
    for (let part = 0; part <= 3; part++) {
        partValue = randint(1, 2)
        figure[part] = partValue
    }
}

// If the generated number is 2, it will light up two LED diodes on the line, else it will light up only one
function displayLine (lineIndex: number, lineValue: number) {
    if (lineValue == 1) {
        led.plot(2, lineIndex)
    } else {
        led.plot(1, lineIndex)
        led.plot(3, lineIndex)
    }
}

input.onSound(DetectedSound.Loud, function () {
    generateFigure()
    displayFigure(figure)
    music.startMelody(music.builtInMelody(Melodies.BaDing), MelodyOptions.Once)
})

Comments

Popular posts from this blog

Simple Sumerian Banishing Ritual

Art of Shinobi: Simple Protection Ritual