Bhavithiran
Published © MIT

Program micro:bit mobile robot with Python | 1 Colour Splash

A step by step guide to program a micro:bit mobile robot to light up using MicroPython

BeginnerProtip30 minutes255
Program micro:bit mobile robot with Python | 1 Colour Splash

Things used in this project

Hardware components

Cytron Technologies rero:micro
×1

Software apps and online services

Mu
Python Editor for micro:bit

Story

Read more

Code

Colour Splash

Python
This tutorial's full code
from reromicro import *
import neopixel

rero = reromicro()
strip = neopixel.NeoPixel(pin1, 7)

while True:
    if button_a.was_pressed():             # if button A pressed
        display.show(Image.HAPPY)          # show happy symbol in micro:bit LED matrix
        for pixel in range(7):             # set all the pixels to same colour
            strip[pixel] = (255,0,0)       # red
            strip.show()
        sleep_ms(500)                      
        for pixel in range(7):
            strip[pixel] = (0,255,0)       # green
            strip.show()
        sleep_ms(500)
        for pixel in range(7):
            strip[pixel] = (0,0,255)       # blue
            strip.show()
        sleep_ms(500)
    elif button_b.was_pressed():           # if button B pressed
        display.show(Image.HEART)          # show heart symbol in micro:bit LED matrix
        strip[0] = 255,0,0                 # red
        strip[1] = 255,164,0               # orange
        strip[2] = 255,255,0               # yellow
        strip[3] = 0,255,0                 # green
        strip[4] = 0,0,255                 # blue
        strip[5] = 255,0,255               # purple
        strip[6] = 255,255,255             # white
        strip.show()

Credits

Bhavithiran

Bhavithiran

11 projects • 4 followers

Comments