Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Micro:bit "Lighting Desk"
- //Adam Robbins 2017
- //RGB LED Connected to pins 1, 2 and 8
- //Variable resistor to pin 0
- let blue = 0
- let green = 0
- let value = 0
- let red = 0
- let select = 0
- basic.forever(() => {
- update()
- value = pins.analogReadPin(AnalogPin.P0)
- switch (select) {
- case 0:
- red = value
- basic.showString("R")
- break;
- case 1:
- green = value
- basic.showString("G")
- break;
- case 2:
- blue = value
- basic.showString("B")
- break;
- case 99:
- basic.showString(" ")
- break;
- default:
- basic.showString("ERROR 1") //all errors are undocumented
- break;
- }
- })
- input.onButtonPressed(Button.A, () => {
- select += 1
- if (select >= 3) { //could be == if it was not for the special 99 case
- select = 0
- }
- })
- input.onButtonPressed(Button.B, () => {
- red = Math.random(1023)
- green = Math.random(1023)
- blue = Math.random(1023)
- select = 99
- })
- function update() {
- pins.analogWritePin(AnalogPin.P1, red)
- pins.analogWritePin(AnalogPin.P8, green)
- pins.analogWritePin(AnalogPin.P2, blue)
- }
- input.onButtonPressed(Button.AB, () => {
- basic.showString(".R")
- basic.showNumber(red)
- basic.showString(".G")
- basic.showNumber(green)
- basic.showString(".B")
- basic.showNumber(blue)
- basic.clearScreen()
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement