2

See the headline

I can easily get gestures to work. But what if I were to attach the board on a rock, and make it register how many times the rock has been thrown up into the air - and caught again? I am wondering if it is possible to utilize the accelerometer?

This code works, if I just flip the board, it counts as described.

from microbit import *
score = 0
display.show(str(score))

while True:
if accelerometer.was_gesture('face down'):
    score += 1
    if score < 10:
        display.show(score)
    else: 
        display.scroll(score)
continue
Mikkel
  • 33
  • 2
  • Hi @Mikkel, I would think if you used the G force of the accelerometer you could count the number of times it exceed some threshold and then only count 1 of the times in a 1 second period to deal with bouncing... something like that anyway. Let us know what you ended up with. Sounds fun! – Patrick Mar 18 '20 at 21:39
  • If the answer below worked, be sure to mark it as the answer. If you did this another way, add your own answer. – Patrick Mar 25 '20 at 17:17

1 Answers1

1

This code seems to work, so in theory, it should work. The Microbit Foundation have a project for a step counter on their website (https://microbit.org/projects/make-it-code-it/step-counter/?editor=python), which is similar to what you're trying to do.

You might want to get a smashproof case for your micro:bit though!

edapm
  • 45
  • 1
  • 9