Things used in this project

Hardware components:
Microbitheart
micro:bit BBC micro:bit board
×1
Adafruit Breadboard-friendly RGB Smart NeoPixel - Sheet of 25
×1
266 04
Female/Female Jumper Wires
×1
Umbrella
×1
Te connectivity 4 103741 0 image 75px
Male Header 40 Position 1 Row (0.1")
×1
Edge Connector Breakout Board for BBC micro:bit
×1
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)

Code

micro python lighteningPython
micro python file used in the mu editor
from microbit import *
import neopixel
from random import randint

#set up the 4 neopixels on pin 0
np = neopixel.NeoPixel(pin0,4)


while True:
    if button_a.is_pressed():
        while True:
            #get a random light number
            randButton = randint(0,3)
            
            #TEST display the light that's flashing
            #display.show(str(randButton))
            
            #set the random light to white, show, flash twice
            np[randButton] = (255, 255, 255)
            np.show()
            sleep(100)
            np.clear()
            
            sleep(150)
            
            np[randButton] = (255, 255, 255)
            np.show()
            sleep(400)
            np.clear()

            #randomly sleep between flashing lights
            randSleep = randint(500, 1500)
            sleep(randSleep)



        
    if button_b.is_pressed():
        #rainbow time! cycle through the rainbow colours 3 times
        for x in range (0,3):
            np[0] = (255, 0, 0)
            np.show()
            sleep(300)
            np.clear()
            
            np[1] = (255, 127, 0)
            np.show()
            sleep(300)
            np.clear()
            
            np[2] = (255, 255, 0)
            np.show()
            sleep(300)
            np.clear()
            
            np[3] = (0, 255, 0)
            np.show()
            sleep(300)
            np.clear()
            
            np[0] = (0, 0, 255)
            np.show()
            sleep(300)
            np.clear()
            
            np[1] = (75, 0, 130)
            np.show()
            sleep(300)
            np.clear()
            
            np[2] = (139, 0, 255)
            np.show()
            sleep(300)
            np.clear()        
        
            sleep(1000)

        #scare them with some more lightening at the end
        for x in range (0,4):
            np[0]=(255,255,255)
            np[1]=(255,255,255)
            np[2]=(255,255,255)
            np[3]=(255,255,255)
            np.show()
            sleep(100)
            np.clear()
            sleep(200)

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Weather on micro:bit
Intermediate
  • 886
  • 6

Full instructions

Ask Amazon Alexa current weather, then display the result on the BBC micro:bit's LEDs.

Conway's Game of Life
Intermediate
  • 469
  • 3

Full instructions

Do you know your micro:bit can grow life? Look at a small universe that evolves.

Baseball Pitch Counter
Intermediate
  • 4,331
  • 10

Work in progress

An automated baseball pitch counter with the help of a micro:bit.

Programming using C/C++ (Offline IDE Setup) | BBC Microbit
Intermediate
  • 305
  • 0

This tutorial is around BBC Microbit and programming the microbit using mbed C/C++ IDE .

Custom BLE Services with Micro:bit
Intermediate
  • 283
  • 1

Protip

Build your own Bluetooth low energy services and bundle them as blocks that beginners can use!

Micro;Bit Top Revolution Counter
Intermediate
  • 234
  • 1

Full instructions

A Micro;Bit attached to a self made top, that will count the number of times the top spins in a circle.

Add projectSign up / LoginAbout BBC micro:bit