From 8c08dca854b43de2608a6a92e66bda3d44b3c06f Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Wed, 23 Aug 2017 11:40:37 -0700 Subject: [PATCH] Egg and Spoon example (#429) --- docs/examples.md | 5 +++++ docs/examples/egg-and-spoon.md | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 docs/examples/egg-and-spoon.md diff --git a/docs/examples.md b/docs/examples.md index 13b7e1ab..ec64d259 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -36,6 +36,11 @@ Here are some fun programs for your @boardname@! ```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", "description": "chart acceleration on the LED screen", "url":"/examples/plot-acceleration", diff --git a/docs/examples/egg-and-spoon.md b/docs/examples/egg-and-spoon.md new file mode 100644 index 00000000..dbbc2f88 --- /dev/null +++ b/docs/examples/egg-and-spoon.md @@ -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 + +```