Fireflies Assignment

Partner Work (2-3 students per group)

Spend approximately 15 minutes on this site to understand how fireflies sync their internal clocks

pageNative American Spirit Animal

Now let's program the fireflies: We ant to create digital fireflies using multiple micro:bits (each microbit acts as a firefly). Each firefly will have its own internal clock or counter. Each partner needs to design a unique "flash" for their bug.

set clock = 0

Every time the clock strikes 15 we want the firefly to flash

forever
    if clock > 14
        flash firefly
        pause 200
        set clock to 0
    else
        pause 100
        set clock to clock + 1

Test this out and make sure your firefly flashes. Adjust the pauses and clock settings as you see fit to make a unique firefly

In real life fireflies adjust their timing when they are near another fire fly so we need to adjust our code to send and receive messages from nearby flies. When you flash your light you also need to send a signal over the radio. This will communicate to nearby flies that you are flashing

radio send number 0

When fireflies detect that there are other flashes nearby they actually increase the timing of their internal clocks, meaning they will flash faster than if they were alone.

on radio recevied number
    if clock < 15
        set clock to clock + 1

This will increment your clock if you are not already flashing

TIPS: Check radio group settings

Once you have installed your working program on all microbits, and each "firefly" has a unique flash - then test them in the hallway moving closer and farther apart to discover what is happening to the clocks.

This assignment and corresponding code are based on an activity found on https://makecode.microbit.org/projects/fireflies - originally accessed 9/22/2019

Last updated