![]()

Fireflies in the wild synchronize their glowing although there is no leader to give the tempo. Go to http://ncase.me/fireflies/ and read about the fireflies synchronization phenomenon.
Just like fireflies in the wild, you can create program that synchronize blinking between any number of micro:bit! The firefly program uses two pages, page 1 will run when the light is off and page 2 will handle a glow. You will need 3 micro:bit to make the synchronization work!
page 1

In
page 1, we add a rule that clears the screen and keeps a dot
when the page starts.

The clock of the firefly will be held in
variable X. It starts at
1 and once it reaches 8, the firefly will glow.
The
radio receive moves the clock by 1 whenever a neighboring firefly sent a message.

The
timer rule moves the clock every
quarter of a second;

The next rule,
when variable X changed to 8, transitions to
page 2 when the clock reaches 8.

Since it is possible that we miss the number 8 because the firefly received many radio updates at once,
we add one last rule, a timer every 3s that transitions to page 2.

page 2

A radio message is sent to other firefly so that they can nudge their clock (
).

The variable X is
set to
1.

All the LEDs are turned on.

A sound is played.

After half a second, we transition back to page 1 to restart the non-glow phase.

improvement ideas
- use a radio group to avoid interference with other users
- remix this technique with other programs to create new synchronized experiences!