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

A = 0 #Arm
R = 0 #Roll
T = 0 #Throttle

def take_of():
    A = 1
    radio.sendValue("A", A)

def land():
    A = 0
    radio.sendValue("A", A)

while True:
    if A == 1:
        if accelerometer.was_gesture("down"):
            T += 0.1
            radio.sendValue("T", T)
        if accelerometer.was_gesture("up"):
            T -= 0.1
            radio.sendValue("T", T)
        if accelerometer.was_gesture("left"):
            R += 45
            radio.sendValue("R", R)
        if accelerometer.was_gesture("right"):
            R -= 45
            radio.sendValue("R", R)
        if button_b.was_pressed():
            land()
    else:
        if button_a.was_pressed():
            take_of()
    T, R = 0, 0