Page 1 of 1

Timer with micro:bit? [SOLVED]

Posted: Sat May 11, 2019 10:57 am
by csanyipal
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

Re: Timer with micro:bit?

Posted: Sat May 11, 2019 2:34 pm
by lujo
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

Re: Timer with micro:bit?

Posted: Sat May 11, 2019 7:05 pm
by csanyipal
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:

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
This is on mb2 which is attached to the leg of competitor.
( Do not know how to switch ON BBCode? )

Re: Timer with micro:bit? [SOLVED]

Posted: Thu May 16, 2019 3:19 pm
by rhubarbdog
I have a clock class which updates the number of seconds kind of asynchronously. See clock.py in this repo

Timer with micro:bit?

Posted: Sat Oct 01, 2022 11:12 am
by Salva_OA
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?

Re: Timer with micro:bit? [SOLVED]

Posted: Sat Oct 01, 2022 2:30 pm
by jimmo
Salva_OA wrote:
Sat Oct 01, 2022 11:12 am
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?
I wrote this a few years ago at a previous job... might give you some ideas.
https://medium.com/groklearning/become- ... b8b4e2d747

Re: Timer with micro:bit? [SOLVED]

Posted: Tue Oct 04, 2022 7:55 pm
by Salva_OA
Thanks