Robot driving in Leeds...

As normal these things start with receiving an email mentioning that there is this really cool event happening and would you like to take part. The event is question was the Make:Believe event held at Leeds City Museum as part of the Leeds International Festival.

Joining forces with Phil M from the micro:bit educational foundation a plan formed to provide some micro:bit activities. Phil rolled out his awesome micro:bit house to wow the crowds and I deployed the fleet of bit:bots and robo:bits:

robo:bits

To keep it simple a plan was hatched to give the young attendees a chance to drive a robot. This took the form of having the micro:bit in the robot controlled remotely by another micro:bit.

The code from multiwingspans site was tweaked to allow the user to tilt the controller micro:bit in the direction they wanted to move the robot and to stop by pressing the 'a' button.

This worked well in general but got confusing for younger attendees which usually resulted in the bit:bot speeding off in a random direction and requiring to be rescued. The main issue seemed to be pressing the 'a' button to stop the robot and not being able to tell what direction was being sent from the controller.

With this in mind, later that evening, the PXT editor was started back up and the code modified to make driving the bit:bot a bit easier.

This time tilting the controller will display what direction the robot is to go and pressing 'a' will make the robot move in the direction required. To stop the robot, the controlling micro:bit is held flat.

Controller code:

radio controller

let x = 0  
let robotNumber = 0  
let y = 0  
basic.forever(() => {  
    y = input.acceleration(Dimension.Y)
    x = input.acceleration(Dimension.X)
    if (y > 400) {
        basic.showLeds(`
            # # # . .
            # . . # .
            # # # . .
            # . . # .
            # # # . .
            `)
        if (input.buttonIsPressed(Button.A)) {
            radio.sendString("S")
        }
    } else if (y < -200) {
        basic.showLeds(`
            # # # . .
            # . . . .
            # # # . .
            # . . . .
            # . . . .
            `)
        if (input.buttonIsPressed(Button.A)) {
            radio.sendString("N")
        }
    } else if (x > 400) {
        basic.showLeds(`
            # # # . .
            # . . # .
            # # # . .
            # . . # .
            # . . . #
            `)
        if (input.buttonIsPressed(Button.A)) {
            radio.sendString("R")
        }
    } else if (x < -200) {
        basic.showLeds(`
            # . . . .
            # . . . .
            # . . . .
            # . . . .
            # # # # .
            `)
        if (input.buttonIsPressed(Button.A)) {
            radio.sendString("L")
        }
    } else {
        radio.sendString("STOP")
        basic.showNumber(robotNumber)
    }
    basic.pause(40)
})
radio.setGroup(10)  
robotNumber = 1  
basic.showNumber(robotNumber)  

Robot Code

radio receiver

radio.onDataPacketReceived(({receivedString}) => {  
    if (receivedString == "N") {
        pins.digitalWritePin(DigitalPin.P0, 1)
        pins.digitalWritePin(DigitalPin.P8, 0)
        pins.digitalWritePin(DigitalPin.P1, 1)
        pins.digitalWritePin(DigitalPin.P12, 0)
    } else if (receivedString == "S") {
        pins.digitalWritePin(DigitalPin.P0, 0)
        pins.digitalWritePin(DigitalPin.P8, 1)
        pins.digitalWritePin(DigitalPin.P1, 0)
        pins.digitalWritePin(DigitalPin.P12, 1)
    } else if (receivedString == "L") {
        pins.digitalWritePin(DigitalPin.P0, 0)
        pins.digitalWritePin(DigitalPin.P8, 0)
        pins.digitalWritePin(DigitalPin.P1, 1)
        pins.digitalWritePin(DigitalPin.P12, 0)
    } else if (receivedString == "R") {
        pins.digitalWritePin(DigitalPin.P0, 1)
        pins.digitalWritePin(DigitalPin.P8, 0)
        pins.digitalWritePin(DigitalPin.P1, 0)
        pins.digitalWritePin(DigitalPin.P12, 0)
    } else if (receivedString == "STOP") {
        pins.digitalWritePin(DigitalPin.P0, 0)
        pins.digitalWritePin(DigitalPin.P8, 0)
        pins.digitalWritePin(DigitalPin.P1, 0)
        pins.digitalWritePin(DigitalPin.P12, 0)
    }
})
radio.setGroup(10)  
basic.showNumber(1)  

Further info:

Cool micro:bit stuff can be found here
Robots can be found here