Last active
April 23, 2018 20:34
-
-
Save will-moore/2ed8accad665ec98b24dc2369a87af63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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