Egg and Spoon example (#429)

This commit is contained in:
Sam El-Husseini 2017-08-23 11:40:37 -07:00 committed by GitHub
parent c040de6134
commit 8c08dca854
2 changed files with 33 additions and 0 deletions

View File

@ -36,6 +36,11 @@ Here are some fun programs for your @boardname@!
```codecard ```codecard
[{ [{
"name": "Egg & Spoon race",
"description": "Balance a micro:bit like an egg and spoon race",
"url":"/examples/egg-and-spoon",
"cardType": "example"
},{
"name": "Plot Acceleration", "name": "Plot Acceleration",
"description": "chart acceleration on the LED screen", "description": "chart acceleration on the LED screen",
"url":"/examples/plot-acceleration", "url":"/examples/plot-acceleration",

View File

@ -0,0 +1,28 @@
# Egg and Spoon race
```blocks
let accY = 0
let accX = 0
let y = 0
let x = 0
basic.forever(() => {
led.plot(x, y)
accX = input.acceleration(Dimension.X)
accY = input.acceleration(Dimension.Y)
if (accX < -150 && x > 0) {
x += -1
} else if (accX > 150 && x < 4) {
x += 1
}
if (accY < -150 && y > 0) {
y += -1
} else if (accY > 150 && y < 4) {
y += 1
}
basic.pause(500)
basic.clearScreen()
})
x = 2
y = 2
```