Hi,
recently we got micro:bits at school.
We are working on a project that uses two micro:bit's: mb1 and mb2.
One micro:bit - the mb2 - should do the followings:
when it receives a message from the other micro:bit - namely 'mb1',
then the 'mb2' must to start a timer which count from 1 to 10.
During this time, it has to count the steps taken by the competitor with the micro: bit 'mb2' attached to the leg.
When mb2 reaches 10 seconds, it must to stop counting steps.
Can this be done with just two micro:bit's at all?
Best, Pal
Timer with micro:bit? [SOLVED]
Timer with micro:bit? [SOLVED]
Last edited by csanyipal on Sun May 12, 2019 4:43 am, edited 1 time in total.
Re: Timer with micro:bit?
Yes, this can be done with just two micro:bits. One plus battery pack
in your tennis sock (mb1) and one connected to your laptop (mb2).
This is a typical micro:bit task. So, should be easy.
The microbit has an increasing millisecond counter for measuring
time intervals and an accelerometer for detecting movements.
From https://microbit-micropython.readthedocs.io/en/latest/
you need to read up on the following modules:
- microbit : for buttons, display and movements
- radio : send and receive messages
- utime : count milliseconds
On mb1:
when button A pressed send message "OK"
On mb2:
when message "OK" received
set step counter to 0
start counting milliseconds
when step detected increment counter
show counter
stop after 10 seconds
wait for next "OK" message
in your tennis sock (mb1) and one connected to your laptop (mb2).
This is a typical micro:bit task. So, should be easy.
The microbit has an increasing millisecond counter for measuring
time intervals and an accelerometer for detecting movements.
From https://microbit-micropython.readthedocs.io/en/latest/
you need to read up on the following modules:
- microbit : for buttons, display and movements
- radio : send and receive messages
- utime : count milliseconds
On mb1:
when button A pressed send message "OK"
On mb2:
when message "OK" received
set step counter to 0
start counting milliseconds
when step detected increment counter
show counter
stop after 10 seconds
wait for next "OK" message
Re: Timer with micro:bit?
Thank you very much for pointing me into the right direction!
I learn from the documentation how to use utime, radio and microbit : for buttons, display and movements.
mb1 and mb2 will be used booth with battery pack.
The code snippet is this:
This is on mb2 which is attached to the leg of competitor.
( Do not know how to switch ON BBCode? )
I learn from the documentation how to use utime, radio and microbit : for buttons, display and movements.
mb1 and mb2 will be used booth with battery pack.
The code snippet is this:
Code: Select all
step = 0
now = int(utime.ticks_ms() / 1000)
while True:
if int(utime.ticks_ms() / 1000) > now + 10:
break
else:
if accelerometer.was_gesture("3g"):
step += 1
( Do not know how to switch ON BBCode? )
-
- Posts: 168
- Joined: Tue Nov 07, 2017 11:45 pm
Re: Timer with micro:bit? [SOLVED]
I have a clock class which updates the number of seconds kind of asynchronously. See clock.py in this repo
Timer with micro:bit?
My question is related to multitask. Having a model with several sensors or actuators time dependants, how do we code it in python?
How many timers can we use simultaneously in one board?
For instance one front sensor, one back an some pwm motors?
How many timers can we use simultaneously in one board?
For instance one front sensor, one back an some pwm motors?
Re: Timer with micro:bit? [SOLVED]
I wrote this a few years ago at a previous job... might give you some ideas.
https://medium.com/groklearning/become- ... b8b4e2d747