Skip to content

Commit

Permalink
added distance measurer
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Feb 15, 2018
1 parent 472ea17 commit 3b6cfed
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,10 @@ Here are some fun programs for your @boardname@!
"description": "Keep your brick entertained and happy",
"url":"/examples/happy-unhappy",
"cardType": "example"
}, {
"name": "Distance Measurer",
"description": "Use a motor to measure angle and distance",
"url": "/examples/distance-measurer",
"cardType": "example"
}]
```
34 changes: 34 additions & 0 deletions docs/examples/distance-measurer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Distance Measurer

```blocks
let distance = 0
let angle = 0
let measuring = false
let radius = 0
// Start and stop measuring with the enter button
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
if (measuring) {
// turn off the measuring
measuring = false
brick.setStatusLight(StatusLight.Off)
} else {
// turn on the measuring clear the counters so that
// the motor tracks the angle
measuring = true
motors.largeB.clearCounts()
brick.setStatusLight(StatusLight.GreenPulse)
}
})
radius = 2.5
brick.showString("Press ENTER to measure", 4)
forever(function () {
if (measuring) {
angle = motors.largeB.angle()
distance = angle / 180 * Math.PI * radius
brick.clearScreen()
brick.showValue("angle", angle, 2)
brick.showValue("distance", distance, 3)
}
pause(100)
})
```

0 comments on commit 3b6cfed

Please sign in to comment.