Md. Khairul Alam
Published © Apache-2.0

Interfacing OLED Display with Micro Maqueen Robot

Show the status and sensor value to an OLED display.

IntermediateFull instructions provided3 hours125
Interfacing OLED Display with Micro Maqueen Robot

Things used in this project

Hardware components

BBC micro:bit board
BBC micro:bit board
×1
DFRobot micro: Maqueen micro:bit Educational Programming Robot Platform
×1
0.96" OLED 64x128 Display Module
ElectroPeak 0.96" OLED 64x128 Display Module
×1

Software apps and online services

MakeCode
Microsoft MakeCode

Story

Read more

Schematics

.hex file

Design Block

Code

JavaScript Source

JavaScript
function horizon () {
    OLED12864_I2C.hline(
    20,
    20,
    25,
    1
    )
    OLED12864_I2C.hline(
    20,
    21,
    25,
    1
    )
    OLED12864_I2C.hline(
    20,
    22,
    25,
    1
    )
    OLED12864_I2C.hline(
    20,
    23,
    25,
    1
    )
    OLED12864_I2C.hline(
    20,
    18,
    25,
    1
    )
    OLED12864_I2C.hline(
    20,
    19,
    25,
    1
    )
}
function right () {
    horizon()
    OLED12864_I2C.vline(
    43,
    14,
    14,
    1
    )
    OLED12864_I2C.vline(
    44,
    15,
    12,
    1
    )
    OLED12864_I2C.vline(
    45,
    16,
    10,
    1
    )
    OLED12864_I2C.vline(
    46,
    17,
    8,
    1
    )
    OLED12864_I2C.vline(
    47,
    18,
    6,
    1
    )
    OLED12864_I2C.vline(
    48,
    19,
    4,
    1
    )
    OLED12864_I2C.vline(
    49,
    20,
    2,
    1
    )
}
maqueen.IR_callbackUser(function ({ myparam: message }) {
    if (message == 13) {
        maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, speed)
        maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, speed)
        maqueen.writeLED(maqueen.LED.LEDLeft, maqueen.LEDswitch.turnOn)
        maqueen.writeLED(maqueen.LED.LEDRight, maqueen.LEDswitch.turnOn)
    }
    if (message == 21) {
        maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CCW, speed)
        maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CCW, speed)
        maqueen.writeLED(maqueen.LED.LEDLeft, maqueen.LEDswitch.turnOff)
        maqueen.writeLED(maqueen.LED.LEDRight, maqueen.LEDswitch.turnOff)
    }
    if (message == 18) {
        OLED12864_I2C.clear()
        OLED12864_I2C.showString(
        1,
        0,
        "Speed :" + speed,
        1
        )
        left()
        maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, 0)
        maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, speed)
        maqueen.writeLED(maqueen.LED.LEDLeft, maqueen.LEDswitch.turnOn)
        maqueen.writeLED(maqueen.LED.LEDRight, maqueen.LEDswitch.turnOff)
    }
    if (message == 16) {
        OLED12864_I2C.clear()
        OLED12864_I2C.showString(
        1,
        0,
        "Speed :" + speed,
        1
        )
        right()
        maqueen.MotorRun(maqueen.aMotors.M1, maqueen.Dir.CW, speed)
        maqueen.MotorRun(maqueen.aMotors.M2, maqueen.Dir.CW, 0)
        maqueen.writeLED(maqueen.LED.LEDLeft, maqueen.LEDswitch.turnOff)
        maqueen.writeLED(maqueen.LED.LEDRight, maqueen.LEDswitch.turnOn)
    }
    if (message == 17) {
        maqueen.motorStopAll()
        maqueen.writeLED(maqueen.LED.LEDLeft, maqueen.LEDswitch.turnOff)
        maqueen.writeLED(maqueen.LED.LEDRight, maqueen.LEDswitch.turnOff)
    }
    if (message == 9) {
        speed = speed - 10
        if (speed < 50) {
            speed = 50
        }
    }
    if (message == 10) {
        maqueen.motorStopAll()
        speed = speed + 10
        if (speed > 255) {
            speed = 255
        }
    }
})
function left () {
    horizon()
    OLED12864_I2C.vline(
    20,
    14,
    14,
    1
    )
    OLED12864_I2C.vline(
    19,
    15,
    12,
    1
    )
    OLED12864_I2C.vline(
    18,
    16,
    10,
    1
    )
    OLED12864_I2C.vline(
    17,
    17,
    8,
    1
    )
    OLED12864_I2C.vline(
    16,
    18,
    6,
    1
    )
    OLED12864_I2C.vline(
    15,
    19,
    4,
    1
    )
    OLED12864_I2C.vline(
    14,
    20,
    2,
    1
    )
}
let speed = 0
OLED12864_I2C.init(60)
speed = 100
OLED12864_I2C.showString(
1,
0,
"Speed :" + speed,
1
)

Credits

Md. Khairul Alam

Md. Khairul Alam

40 projects • 355 followers
Engineer, developer, maker, and hacker.

Comments

Add projectSign up / LoginAbout BBC micro:bit