ElecJ
Published © GPL3+

Gandalf: Robotic Companion Cat PART 2

Part two of how to make an awesome, easy companion robot.

BeginnerFull instructions provided2 days311
Gandalf: Robotic Companion Cat PART 2

Things used in this project

Hardware components

BBC micro:bit board
BBC micro:bit board
×2
Adafruit Crickit
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×2
Any non-continuous Servo Motor
×1
Clear Cover for BBC micro:bit
×1
EVERYTHING FROM PART 1
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×1

Software apps and online services

MakeCode
Microsoft MakeCode

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Small Cardboard Box

Story

Read more

Code

Gandalf Receiver

Python
This is the code for the "Reciever" microbit, which will be in the robot.
def RHWave(speed: number, pos: number):
    global servo1Pos
    servo1Pos = pos
    while servo1Pos >= 0:
        crickit.servo2.set_angle(servo1Pos)
        servo1Pos = servo1Pos - 4
        basic.pause(Math.map(speed, 1, 10, 40, 0))
    while servo1Pos <= pos:
        crickit.servo2.set_angle(servo1Pos)
        servo1Pos = servo1Pos + 4
        basic.pause(Math.map(speed, 1, 10, 40, 0))
def Head(speed: number, pos: number):
    global servo1Pos
    servo1Pos = pos
    while servo1Pos >= 0:
        crickit.servo1.set_angle(servo1Pos)
        servo1Pos = servo1Pos - 4
        basic.pause(Math.map(speed, 1, 10, 40, 0))
    while servo1Pos <= pos:
        crickit.servo1.set_angle(servo1Pos)
        servo1Pos = servo1Pos + 4
        basic.pause(Math.map(speed, 1, 10, 40, 0))

def on_received_string(receivedString):
    if receivedString.includes("a"):
        basic.show_string("A")
        RHWave(1, 180)
        basic.clear_screen()
    if receivedString.includes("b"):
        basic.show_string("B")
        LHWave(1, 180)
        basic.clear_screen()
    if receivedString.includes("c"):
        basic.show_string("C")
        Head(1, 180)
        basic.clear_screen()
radio.on_received_string(on_received_string)

def LHWave(speed: number, pos: number):
    global servo1Pos
    servo1Pos = pos
    while servo1Pos >= 0:
        crickit.servo3.set_angle(servo1Pos)
        servo1Pos = servo1Pos - 4
        basic.pause(Math.map(speed, 1, 10, 40, 0))
    while servo1Pos <= pos:
        crickit.servo3.set_angle(servo1Pos)
        servo1Pos = servo1Pos + 4
        basic.pause(Math.map(speed, 1, 10, 40, 0))
servo1Pos = 0
radio.set_group(1)
crickit.servo1.set_angle(180)

Gandalf Controller

Python
This is the "remote-control" microbit for Gandalf.
def on_button_pressed_a():
    radio.send_string("a")
    basic.show_string("A")
    basic.pause(500)
    basic.clear_screen()
input.on_button_pressed(Button.A, on_button_pressed_a)

def on_button_pressed_ab():
    radio.send_string("c")
    basic.show_string("C")
    basic.pause(500)
    basic.clear_screen()
input.on_button_pressed(Button.AB, on_button_pressed_ab)

def on_button_pressed_b():
    radio.send_string("b")
    basic.show_string("B")
    basic.pause(500)
    basic.clear_screen()
input.on_button_pressed(Button.B, on_button_pressed_b)

radio.set_group(1)
radio.set_transmit_power(7)

Credits

ElecJ

ElecJ

2 projects • 7 followers
I'm in 6th grade. I built a cat companion robot, inspired by Alex Glow and Odd Jayy. I love MAKE: magazine. I'm making low-budget robots.
Thanks to My Dad.

Comments

Add projectSign up / LoginAbout BBC micro:bit