Microbit RGB led examples

Here are another couple of RGB led examples for the Micro:bit

Layout

 

anode-rgb_bb

 

Code

The first example just shows some extra colour combinations

from microbit import *
 
while True:  
    pin0.write_digital(0)
    pin1.write_digital(1)
    pin2.write_digital(1)
    sleep(500)
    pin0.write_digital(1)
    pin1.write_digital(0)
    pin2.write_digital(1)
    sleep(500)
    pin0.write_digital(1)
    pin1.write_digital(1)
    pin2.write_digital(0)
    sleep(500)
    pin0.write_digital(0)
    pin1.write_digital(0)
    pin2.write_digital(1)
    sleep(500)
    pin0.write_digital(1)
    pin1.write_digital(0)
    pin2.write_digital(0)
    sleep(500)
    pin0.write_digital(0)
    pin1.write_digital(1)
    pin2.write_digital(0)
    sleep(500)
    pin0.write_digital(0)
    pin1.write_digital(0)
    pin2.write_digital(0)
    sleep(500)

The next example displays a colour depending on whether button a, button b or no button is pressed

from microbit import *
while True:
    if button_a.is_pressed():
        pin0.write_digital(0)
        pin1.write_digital(1)
        pin2.write_digital(1)
    elif button_b.is_pressed():
        pin0.write_digital(1)
        pin1.write_digital(0)
        pin2.write_digital(1)
    else:
        pin0.write_digital(1)
        pin1.write_digital(1)
        pin2.write_digital(0)