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

[codesyntax lang=”python”]

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)

[/codesyntax]

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

[codesyntax lang=”python”]

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)

[/codesyntax]

Leave a Comment

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views :