Skip to content

Instantly share code, notes, and snippets.

@will-moore
Last active April 23, 2018 20:34
Show Gist options
  • Save will-moore/2ed8accad665ec98b24dc2369a87af63 to your computer and use it in GitHub Desktop.
Save will-moore/2ed8accad665ec98b24dc2369a87af63 to your computer and use it in GitHub Desktop.
// Tilting the microbit to one side or the other,
// drives a continuous servo one direction (10) or the other (100)
// Editor: https://makecode.microbit.org/
let angle = 0
let millig = 0
input.onButtonPressed(Button.A, () => {
for (let i = 0; i < 4; i++) {
pins.analogWritePin(AnalogPin.P0, 100)
basic.pause(100)
pins.analogWritePin(AnalogPin.P0, 0)
basic.pause(1000)
pins.analogWritePin(AnalogPin.P0, 10)
basic.pause(80)
}
})
basic.forever(() => {
millig = input.acceleration(Dimension.X)
angle = pins.map(
millig,
-1023,
1023,
10,
100
)
pins.analogWritePin(AnalogPin.P0, angle)
basic.pause(100)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment