39 lines
860 B
Python
39 lines
860 B
Python
'''
|
|
This is code for the hovercraft remote
|
|
'''
|
|
from microbit import *
|
|
|
|
# We start by initiating radio communication
|
|
# We want a strong signal
|
|
|
|
import radio
|
|
|
|
radio.config(group=99, power=7)
|
|
radio.on()
|
|
|
|
flying = False
|
|
|
|
def take_of():
|
|
flying = True
|
|
radio.sendValue("takeof", flying)
|
|
|
|
def land():
|
|
flying = False
|
|
radio.sendValue("land", flying)
|
|
|
|
while True:
|
|
if flying == True:
|
|
if accelerometer.was_gesture("down"):
|
|
radio.send("forward")
|
|
if accelerometer.was_gesture("up"):
|
|
radio.send("back")
|
|
if accelerometer.was_gesture("left"):
|
|
radio.send("left")
|
|
if accelerometer.was_gesture("right"):
|
|
radio.send("right")
|
|
if button_a.was_pressed():
|
|
if flying != True:
|
|
take_of()
|
|
if button_b.was_pressed():
|
|
if flying != False:
|
|
land() |