View on GitHub

CardKB-i2cKeyboard

CardKB - I2C Keyboard extension for MakeCode

This is a very basic MakeCode extension for the Grove Keyboard “CardKB” of M5Stack. It’s still in the making. This extension will work for the Calliope mini as well for the BBC micro:bit.

Further information can be found here: https://docs.m5stack.com/en/unit/cardkb

Wiring:

On the Calliope mini the wiring is quite simple. Just plug the keyboard to the left A0 Grove-port.

Example

read string

The minimal setup is to read the keyboard in the loop and directly feed it to the showString, to see the letters on the LED-matrix. You can also store values in arrays for words, or send it to the serialport. The output is a string.

basic.forever(function () {
    basic.showString(CardKB.readString())
})

read charcode This outputs the charcode as numbers. This is an example of using the charcode to create strings with the text block. Usually the Keyboard functions for reading charcode or letter should only evoked once and stored in a variable.

let charcode = 0
basic.forever(function () {
    charcode = CardKB.readCharcode()
    basic.showString(String.fromCharCode(charcode))
    if (charcode == -73) {
        basic.showIcon(IconNames.ArrowEast)
    } else if (charcode == -74) {
        basic.showIcon(IconNames.ArrowSouth)
    } else if (charcode == -75) {
        basic.showIcon(IconNames.ArrowNorth)
    } else if (charcode == -76) {
        basic.showIcon(IconNames.ArrowWest)
    }
})

Issues