Skip to content

Commit

Permalink
11-TestKaspers buttons working
Browse files Browse the repository at this point in the history
  • Loading branch information
4-R-Forum authored and 4-R-Forum committed Nov 18, 2023
1 parent 951ee54 commit a1e3aae
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 11-TestKaspersMbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
def accelerometer_data(data: ()):
print(f"Accelerometer data: {data}")

def pressed(button):
print(f"button {button} pressed")

def get_roll(x,y,z):
return math.atan(x/math.sqrt(math.pow(y,2) + math.pow(z,2))) * -180 / math.pi
def get_pitch(x,y,z):
Expand All @@ -33,6 +36,19 @@ def get_pitch_roll(microbit):
'''
res = get_pitch_roll(microbit)
print(f"{res}")
#microbit.buttons.on_button_a(press=pressed)
a = microbit.buttons.read_button_a()
b = microbit.buttons.read_button_b()
m = "No button"
if a > 0 and b == 0:
m = "Go up"
if a == 0 and b > 0:
m = "Go down"
if a > 0 and b > 0:
m = "Stop Flying"

print(f"{m}")

time.sleep(2)
# check how often accelerometer updates will occur if you listen to them with notify
# / lees hoe vaak accelerometer updates doorgestuurd worden wanneer je er naar luistert met notify
Expand Down

0 comments on commit a1e3aae

Please sign in to comment.