Timer with micro:bit? [SOLVED]

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
csanyipal
Posts: 6
Joined: Sat May 11, 2019 10:43 am
Location: Serbia
Contact:

Timer with micro:bit? [SOLVED]

Post by csanyipal » Sat May 11, 2019 10:57 am

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
Last edited by csanyipal on Sun May 12, 2019 4:43 am, edited 1 time in total.

lujo
Posts: 24
Joined: Sat May 11, 2019 2:30 pm

Re: Timer with micro:bit?

Post by lujo » Sat May 11, 2019 2:34 pm

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

csanyipal
Posts: 6
Joined: Sat May 11, 2019 10:43 am
Location: Serbia
Contact:

Re: Timer with micro:bit?

Post by csanyipal » Sat May 11, 2019 7:05 pm

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? )

rhubarbdog
Posts: 168
Joined: Tue Nov 07, 2017 11:45 pm

Re: Timer with micro:bit? [SOLVED]

Post by rhubarbdog » Thu May 16, 2019 3:19 pm

I have a clock class which updates the number of seconds kind of asynchronously. See clock.py in this repo

Salva_OA
Posts: 3
Joined: Mon Oct 04, 2021 2:19 pm

Timer with micro:bit?

Post by Salva_OA » 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?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Timer with micro:bit? [SOLVED]

Post by jimmo » Sat Oct 01, 2022 2:30 pm

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

Salva_OA
Posts: 3
Joined: Mon Oct 04, 2021 2:19 pm

Re: Timer with micro:bit? [SOLVED]

Post by Salva_OA » Tue Oct 04, 2022 7:55 pm

Thanks

Post Reply