Skip to content

crwdns342183:0crwdne342183:0

crwdns312404:0crwdne312404:0

crwdns347529:0crwdne347529:0 | MakeCode, Python | crwdns255558:0crwdne255558:0, crwdns255566:0crwdne255566:0 | crwdns258504:0crwdne258504:0, crwdns258554:0crwdne258554:0, crwdns258562:0crwdne258562:0

crwdns291062:0crwdne291062:0

crwdns291064:0crwdne291064:0

crwdns291066:0crwdne291066:0

crwdns291068:0crwdne291068:0

  • crwdns291070:0crwdne291070:0
  • crwdns291072:0crwdne291072:0
  • crwdns291074:0crwdne291074:0

crwdns291076:0crwdne291076:0

crwdns291078:0crwdne291078:0

crwdns291080:0crwdne291080:0 crwdns291082:0crwdne291082:0

crwdns291084:0crwdne291084:0 crwdns291086:0crwdne291086:0 crwdns291088:0crwdne291088:0

crwdns291090:0crwdne291090:0

crwdns291092:0crwdne291092:0

crwdns291094:0crwdne291094:0

  • crwdns291096:0crwdne291096:0
  • crwdns291098:0crwdne291098:0 crwdns291100:0crwdne291100:0
  • crwdns291102:0crwdne291102:0 crwdns291104:0crwdne291104:0 crwdns291106:0crwdne291106:0
  • crwdns291108:0crwdne291108:0 crwdns291110:0crwdne291110:0 crwdns291112:0crwdne291112:0

crwdns291114:0crwdne291114:0

  • crwdns291116:0crwdne291116:0
  • crwdns291118:0crwdne291118:0

crwdns291120:0crwdne291120:0

1# A micro:bit Firefly.
2# By Nicholas H.Tollervey. Released to the public domain.
3import radio
4import random
5from microbit import display, Image, button_a, sleep
6
7# Create the "flash" animation frames. Can you work out how it's done?
8flash = [Image().invert()*(i/9) for i in range(9, -1, -1)]
9
10# The radio won't work unless it's switched on.
11radio.on()
12
13# Event loop.
14while True:
15    # Button A sends a "flash" message.
16    if button_a.was_pressed():
17        radio.send('flash')  # a-ha
18    # Read any incoming messages.
19    incoming = radio.receive()
20    if incoming == 'flash':
21        # If there's an incoming "flash" message display
22        # the firefly flash animation after a random short
23        # pause.
24        sleep(random.randint(50, 350))
25        display.show(flash, delay=100, wait=False)
26        # Randomly re-broadcast the flash message after a
27        # slight delay.
28        if random.randint(0, 9) == 0:
29            sleep(500)
30            radio.send('flash')  # a-ha
31            
32

crwdns291122:0crwdne291122:0

  • crwdns291124:0crwdne291124:0
  • crwdns291126:0crwdne291126:0 crwdns291128:0crwdne291128:0
  • crwdns291130:0crwdne291130:0 crwdns291132:0crwdne291132:0
  • crwdns291134:0crwdne291134:0
    crwdns291136:0crwdne291136:0
    crwdns291138:0crwdne291138:0
    crwdns291140:0crwdne291140:0