# Gandalf: Robotic Companion Cat PART 2

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

BeginnerFull instructions provided2 days748

## Things used in this project

### Hardware components

 BBC micro:bit board
×2
×1
 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)
×1

### Software apps and online services

 Microsoft MakeCode

### Hand tools and fabrication machines

 Hot glue gun (generic)
 Small Cardboard Box

## Code

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))

basic.show_string("A")
RHWave(1, 180)
basic.clear_screen()
basic.show_string("B")
LHWave(1, 180)
basic.clear_screen()
basic.show_string("C")
basic.clear_screen()

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
crickit.servo1.set_angle(180)
```

### Gandalf Controller

Python
This is the "remote-control" microbit for Gandalf.
```def on_button_pressed_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():
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():
basic.show_string("B")
basic.pause(500)
basic.clear_screen()
input.on_button_pressed(Button.B, on_button_pressed_b)