Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Micro:bit Motor Experiments
- //Adam Robbins 2017
- //Motor via transistor on pin0
- //Motor in reverse on pin 1 (via potential divider to halve reading)
- let duty: number
- let mode: boolean
- basic.forever(() => {
- if (mode) {
- pins.analogWritePin(AnalogPin.P0, duty)
- if (input.buttonIsPressed(Button.A)) {
- duty += -10
- basic.showString("-")
- if (duty < 1) {
- duty = 1
- basic.showString(" ")
- }
- } else if (input.buttonIsPressed(Button.B)) {
- duty += 10
- basic.showString("+")
- if (duty > 1023) {
- duty = 1023
- basic.showString(" ")
- }
- } else {
- led.plotBarGraph(duty, 1023)
- }
- } else {
- duty = pins.analogReadPin(AnalogPin.P1)
- led.plotBarGraph(duty, 1023)
- }
- })
- //Change Mode (Starts on input mode)
- input.onButtonPressed(Button.AB, () => {
- if (mode) {
- mode = false
- } else {
- mode = true
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement