added turtle program

This commit is contained in:
Peli de Halleux 2019-09-08 21:29:27 -07:00
parent 2975bf2b55
commit 23f48db20b
3 changed files with 62 additions and 0 deletions

View File

@ -212,6 +212,12 @@ Here are some fun programs for your @boardname@!
"description": "Keep your brick entertained and happy",
"url":"/examples/happy-unhappy",
"cardType": "example"
}, {
{
"name": "Turtle",
"description": "Encode moves and run them on a driving base",
"url":"/examples/turtle",
"cardType": "example"
}, {
"name": "Distance Measurer",
"description": "Use a motor to measure angle and distance",

52
docs/examples/turtle.md Normal file
View File

@ -0,0 +1,52 @@
# Turtle
A fun interactive program where the user enters a sequence of moves using the buttons and the robot executes it.
```blocks
/**
* Run this program with a driving base.
**/
let indent = ""
let command = ""
let c = ""
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
command = command + "L"
})
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
command = command + "R"
})
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
command = command + "F"
})
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
command = command + "B"
})
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
indent = ""
for (let index = 0; index <= command.length; index++) {
c = command[index]
brick.showString("" + indent + c, 4)
indent = "" + indent + " "
if (c == "L") {
motors.largeBC.steer(-100, 50, 378, MoveUnit.Degrees)
} else if (c == "R") {
motors.largeBC.steer(100, 50, 378, MoveUnit.Degrees)
} else if (c == "F") {
motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations)
} else if (c == "B") {
motors.largeBC.steer(0, -50, 1, MoveUnit.Rotations)
}
}
command = ""
brick.showString("", 2)
})
motors.largeBC.setBrake(true)
forever(function () {
brick.showString("TURTLE", 1)
brick.showString(command, 3)
brick.showString("up/down: forward/backward", 8)
brick.showString("left/right: turn", 9)
brick.showString("enter: play commands", 10)
})
```

View File

@ -20,6 +20,10 @@ If you found a bug, please try if it hasn't been fixed yet! Go to https://makeco
* You will need a computer with a USB port to connect to the EV3 in order to download your programs.
* You will need internet access and a browser on your computer to get to https://makecode.mindstorms.com.
### I know LabView, how is MakeCode different?
We have compiled a guide for EV3 LabView users at https://makecode.mindstorms.com/labview.
### Whats the best way to get started with MakeCode?
Go to https://makecode.mindstorms.com. The home screen is filled with videos, tutorials and examples that might be relevant for your missions.