Here are another couple of RGB led examples for the Micro:bit
Layout
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]