Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
ceb9b7fabf | |||
9e0670551f | |||
6613607503 | |||
3a67190914 | |||
05e916e247 | |||
fad4ca98db | |||
3b6cfed5b2 | |||
472ea170d0 | |||
80f24948ec | |||
daa88b299d | |||
0384eb4d9d | |||
f33f88e87c |
@ -67,7 +67,7 @@
|
||||
* [set light](/reference/brick/set-status-light)
|
||||
* [battery level](/reference/brick/battery-level)
|
||||
* [Motors](/reference/motors)
|
||||
* [set speed](/reference/motors/motor/set-speed)
|
||||
* [run](/reference/motors/motor/run)
|
||||
* [stop](/reference/motors/motor/stop)
|
||||
* [reset](/reference/motors/motor/reset)
|
||||
* [set brake](/reference/motors/motor/set-brake)
|
||||
@ -93,4 +93,8 @@
|
||||
* [Ultrasonic](/reference/sensors/ultrasonic)
|
||||
* [on event](/reference/sensors/ultrasonic/on-event),
|
||||
* [distance](reference/sensors/ultrasonic/distance),
|
||||
* [pause until](reference/sensors/ultrasonic/pause-until)
|
||||
* [pause until](reference/sensors/ultrasonic/pause-until)
|
||||
* [Infrared](/reference/sensors/infrared)
|
||||
* [on event](/reference/sensors/infrared/on-event),
|
||||
* [distance](reference/sensors/infrared/proximity),
|
||||
* [pause until](reference/sensors/infrared/pause-until)
|
@ -8,12 +8,12 @@ You can program the @boardname@ using [Blocks](/blocks) or [JavaScript](/javascr
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
```
|
||||
```typescript
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
```
|
||||
|
||||
@ -34,6 +34,6 @@ The simulator has support for the LED screen, buttons, as well as compass, accel
|
||||
|
||||
```sim
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
```
|
||||
|
@ -3,6 +3,6 @@
|
||||
### #specific
|
||||
|
||||
```cards
|
||||
loops.forever(() => {});
|
||||
loops.pause(0)
|
||||
forever(() => {});
|
||||
pause(0)
|
||||
```
|
@ -5,6 +5,6 @@ let speed = 0;
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
if (speed < 100)
|
||||
speed = speed + 10;
|
||||
motors.largeBC.setSpeed(speed);
|
||||
motors.largeBC.run(speed);
|
||||
})
|
||||
```
|
@ -5,11 +5,11 @@ let speed = 0;
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
if (speed < 100)
|
||||
speed = speed + 10;
|
||||
motors.largeBC.setSpeed(speed);
|
||||
motors.largeBC.run(speed);
|
||||
})
|
||||
sensors.touch2.onEvent(ButtonEvent.Pressed, function () {
|
||||
if (speed > -100)
|
||||
speed = speed - 10;
|
||||
motors.largeBC.setSpeed(speed);
|
||||
motors.largeBC.run(speed);
|
||||
})
|
||||
```
|
@ -15,7 +15,7 @@ function accelerate() {
|
||||
function update() {
|
||||
brick.clearScreen()
|
||||
brick.showString("speed: " + speed, 1)
|
||||
motors.largeBC.setSpeed(speed)
|
||||
motors.largeBC.run(speed)
|
||||
}
|
||||
sensors.touch2.onEvent(ButtonEvent.Pressed, function () {
|
||||
accelerate()
|
||||
|
@ -7,6 +7,6 @@ while (true) {
|
||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
||||
}
|
||||
loops.pause(1);
|
||||
pause(1);
|
||||
}
|
||||
```
|
||||
|
@ -8,6 +8,6 @@ while (true) {
|
||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
||||
}
|
||||
loops.pause(1);
|
||||
pause(1);
|
||||
}
|
||||
```
|
||||
|
@ -3,7 +3,7 @@
|
||||
```blocks
|
||||
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Dark, function () {
|
||||
brick.showImage(images.objectsLightOn)
|
||||
loops.pause(5000)
|
||||
pause(5000)
|
||||
brick.clearScreen()
|
||||
})
|
||||
```
|
@ -1,11 +1,11 @@
|
||||
# Reverse Beeper Activity 1
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
music.playTone(440, sensors.ultrasonic4.distance());
|
||||
loops.pause(50)
|
||||
pause(50)
|
||||
})
|
||||
motors.largeBC.setSpeed(-20);
|
||||
motors.largeBC.run(-20);
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
|
||||
motors.largeBC.stop();
|
||||
```
|
||||
|
@ -1,13 +1,13 @@
|
||||
# Reverse Beeper Activity 2
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
if (motors.largeB.speed() != 0 && sensors.ultrasonic4.distance() < 20) {
|
||||
music.playTone(440, sensors.ultrasonic4.distance());
|
||||
loops.pause(50)
|
||||
pause(50)
|
||||
}
|
||||
})
|
||||
motors.largeBC.setSpeed(-20);
|
||||
motors.largeBC.run(-20);
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
|
||||
motors.largeBC.stop();
|
||||
```
|
||||
|
@ -4,7 +4,7 @@
|
||||
let beep = false
|
||||
beep = true
|
||||
control.runInParallel(function () {
|
||||
motors.largeBC.setSpeed(-20)
|
||||
motors.largeBC.run(-20)
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear)
|
||||
motors.largeBC.stop()
|
||||
beep = false
|
||||
@ -13,7 +13,7 @@ control.runInParallel(function () {
|
||||
while (beep) {
|
||||
if (sensors.ultrasonic4.distance() < 20) {
|
||||
music.playTone(440, sensors.ultrasonic4.distance())
|
||||
loops.pause(50)
|
||||
pause(50)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -2,13 +2,13 @@
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
motors.largeBC.setSpeed(50)
|
||||
motors.largeBC.run(50)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeBC.setSpeed(0)
|
||||
loops.pause(1000)
|
||||
motors.largeBC.run(0)
|
||||
pause(1000)
|
||||
brick.setStatusLight(StatusLight.OrangeFlash)
|
||||
motors.largeBC.setSpeed(-50)
|
||||
loops.pause(2000)
|
||||
motors.largeBC.setSpeed(0)
|
||||
motors.largeBC.run(-50)
|
||||
pause(2000)
|
||||
motors.largeBC.run(0)
|
||||
})
|
||||
```
|
@ -3,13 +3,13 @@
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeBC.setSpeed(50)
|
||||
motors.largeBC.run(50)
|
||||
sensors.touch2.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeBC.setSpeed(0)
|
||||
loops.pause(1000)
|
||||
motors.largeBC.run(0)
|
||||
pause(1000)
|
||||
brick.setStatusLight(StatusLight.OrangeFlash)
|
||||
motors.largeBC.setSpeed(-50)
|
||||
loops.pause(2000)
|
||||
motors.largeBC.setSpeed(0)
|
||||
motors.largeBC.run(-50)
|
||||
pause(2000)
|
||||
motors.largeBC.run(0)
|
||||
})
|
||||
```
|
@ -5,15 +5,15 @@ brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
brick.showImage(images.eyesSleeping)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
brick.showImage(images.eyesNeutral)
|
||||
motors.largeBC.setSpeed(50)
|
||||
motors.largeBC.run(50)
|
||||
sensors.touch2.pauseUntil(ButtonEvent.Pressed)
|
||||
brick.showImage(images.eyesTiredMiddle)
|
||||
motors.largeBC.setSpeed(0)
|
||||
loops.pause(1000)
|
||||
motors.largeBC.run(0)
|
||||
pause(1000)
|
||||
brick.setStatusLight(StatusLight.OrangeFlash)
|
||||
brick.showImage(images.eyesDizzy)
|
||||
motors.largeBC.setSpeed(-50)
|
||||
loops.pause(2000)
|
||||
motors.largeBC.setSpeed(0)
|
||||
motors.largeBC.run(-50)
|
||||
pause(2000)
|
||||
motors.largeBC.run(0)
|
||||
})
|
||||
```
|
@ -15,17 +15,17 @@ brick.buttonDown.onEvent(ButtonEvent.Bumped, function () {
|
||||
drive.push(5)
|
||||
})
|
||||
pauseUntil(() => drive.length >= 5)
|
||||
loops.pause(1000)
|
||||
pause(1000)
|
||||
music.playSoundEffectUntilDone(sounds.communicationGo)
|
||||
for (let d of drive) {
|
||||
if (d == 1) {
|
||||
motors.largeC.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeC.run(50, 360, MoveUnit.Degrees)
|
||||
} else if (d == 3) {
|
||||
motors.largeB.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeB.run(50, 360, MoveUnit.Degrees)
|
||||
} else if (d == 4) {
|
||||
motors.largeBC.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeBC.run(50, 360, MoveUnit.Degrees)
|
||||
} else {
|
||||
motors.largeBC.setSpeed(-50, 360, MoveUnit.Degrees)
|
||||
motors.largeBC.run(-50, 360, MoveUnit.Degrees)
|
||||
}
|
||||
}
|
||||
music.playSoundEffectUntilDone(sounds.communicationGameOver)
|
||||
|
@ -19,17 +19,17 @@ brick.buttonDown.onEvent(ButtonEvent.Bumped, function () {
|
||||
music.playSoundEffectUntilDone(sounds.systemClick)
|
||||
})
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Bumped);
|
||||
loops.pause(1000)
|
||||
pause(1000)
|
||||
music.playSoundEffectUntilDone(sounds.communicationGo)
|
||||
for (let d of drive) {
|
||||
if (d == 1) {
|
||||
motors.largeC.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeC.run(50, 360, MoveUnit.Degrees)
|
||||
} else if (d == 3) {
|
||||
motors.largeB.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeB.run(50, 360, MoveUnit.Degrees)
|
||||
} else if (d == 4) {
|
||||
motors.largeBC.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeBC.run(50, 360, MoveUnit.Degrees)
|
||||
} else {
|
||||
motors.largeBC.setSpeed(-50, 360, MoveUnit.Degrees)
|
||||
motors.largeBC.run(-50, 360, MoveUnit.Degrees)
|
||||
}
|
||||
}
|
||||
music.playSoundEffectUntilDone(sounds.communicationGameOver)
|
||||
|
@ -3,10 +3,10 @@
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
motors.largeBC.tank(75, 30)
|
||||
loops.pause(1500)
|
||||
pause(1500)
|
||||
motors.largeBC.tank(-30, -75)
|
||||
loops.pause(1000)
|
||||
pause(1000)
|
||||
motors.largeBC.tank(50, 50)
|
||||
loops.pause(3000)
|
||||
pause(3000)
|
||||
})
|
||||
```
|
@ -3,12 +3,12 @@
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
motors.largeBC.tank(75, 30)
|
||||
loops.pause(1500)
|
||||
pause(1500)
|
||||
motors.largeBC.tank(-30, -75)
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
|
||||
motors.largeBC.tank(0, 0)
|
||||
loops.pause(1000)
|
||||
pause(1000)
|
||||
motors.largeBC.tank(50, 50)
|
||||
loops.pause(3000)
|
||||
pause(3000)
|
||||
})
|
||||
```
|
@ -3,13 +3,13 @@
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
motors.largeBC.tank(75, 30)
|
||||
loops.pause(1500)
|
||||
pause(1500)
|
||||
motors.largeBC.tank(-30, -75)
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
|
||||
motors.largeBC.tank(0, 0)
|
||||
music.playSoundEffect(sounds.animalsDogBark1)
|
||||
loops.pause(1000)
|
||||
pause(1000)
|
||||
motors.largeBC.tank(50, 50)
|
||||
loops.pause(3000)
|
||||
pause(3000)
|
||||
})
|
||||
```
|
@ -1,7 +1,7 @@
|
||||
# Traffic Lights Activity 3
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
if (sensors.color3.light(LightIntensityMode.Reflected) < 15) {
|
||||
motors.largeBC.tank(30, 12)
|
||||
} else {
|
||||
|
@ -20,9 +20,9 @@
|
||||
},
|
||||
{
|
||||
"name": "Make a System that Communicates",
|
||||
"description": "TBD",
|
||||
"imageUrl": "/static/lessons/make-a-system.png",
|
||||
"url": "/design-engineering/make-it-move",
|
||||
"description": "A robot that tells you what it is doing.",
|
||||
"imageUrl": "/static/lessons/make-it-communicate.png",
|
||||
"url": "/design-engineering/make-it-communicate",
|
||||
"cardType": "side"
|
||||
}
|
||||
]
|
||||
|
164
docs/design-engineering/make-it-communicate.md
Normal file
164
docs/design-engineering/make-it-communicate.md
Normal file
@ -0,0 +1,164 @@
|
||||
# Make A System That Communicates
|
||||
|
||||
## Connect
|
||||
|
||||
### Design Brief
|
||||
|
||||
Design, build and program a robotic system that follows a path and communicates its position at least twice along the way.
|
||||
|
||||
https://www.youtube.com/watch?v=6piMI1JPDQc
|
||||
|
||||
* Robotic systems are built from smaller, related subsystems. Look at the automobile system shown in the video. What subsystems can you see?
|
||||
* What kinds of robots follow a path?
|
||||
* What kind of system do you want to make?
|
||||
|
||||
### Brainstorm
|
||||
|
||||
Discuss different solutions to the design brief.
|
||||
|
||||
Think about:
|
||||
* What kind of motorized mechanism can be used to control the movements of a robot?
|
||||
* How can the robot sense where it is along the path?
|
||||
* How can the robot communicate its position?
|
||||
|
||||

|
||||
|
||||
## Construct
|
||||
|
||||
### Build
|
||||
|
||||
You can start by tinkering with the LEGO elements in the picture and then build on.
|
||||
|
||||
More building ideas:
|
||||
* [EV3 Frames](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/ev3%20frames-5054ee378e624fb4cb31158d2fc8e5cf.pdf)
|
||||
|
||||
* [Tracks](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/tracks-32d7554813af3f25cf5012d54a4bad2b.pdf)
|
||||
|
||||
* [Color Sensor 2](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/color%20sensor_v2-e7fd54b6fa3cdfe36f414c1d2510f9cb.pdf)
|
||||
|
||||
|
||||
Build a path for your robot to follow. You can use electrical tape on a floor, or marker on paper. You can use objects as milestones to indicate a path that can be detected by either the Touch Sensor, Color Sensor, or Ultrasonic Sensor.
|
||||
|
||||
## Program
|
||||
|
||||
Before you program, think about:
|
||||
|
||||
* How will you program the robot to follow a path?
|
||||
* How will you program the robot to communicate its position?
|
||||
* Which programming blocks will you use?
|
||||
|
||||
### ~ hint
|
||||
|
||||
Explore the different Motor and Sensor blocks in the programming menu.
|
||||
|
||||
### ~
|
||||
|
||||
### Sample Solution
|
||||
|
||||
[Video: EV3 Track Rover](/static/lessons/make-it-communicate/trackrover.mp4)
|
||||
|
||||
The Track Rover follows a path using the color sensor. It identifies two locations by color.
|
||||
|
||||
[Building Instructions](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/ev3-dep/building%20instructions/track-rover-bi-6aadb1b053df0c58a0dea108b5ce0eea.pdf)
|
||||
|
||||
### Sample Program Solution
|
||||
|
||||
This program works with the Track Rover. If you create a different robot, adjust the program to fit your solution.
|
||||
|
||||
#### Program summary:
|
||||
|
||||
* If the Color Sensor sees black, Motor B runs at -50 power and Motor C turns off.
|
||||
* If the Color Sensor sees white, Motor B turns off and Motor C runs at -50 power.
|
||||
* If the Color Sensor sees green, all motors stop and the green sound plays.
|
||||
* The robot waits one second, then motors move forward.
|
||||
* If the Color Sensor sees red, all motors stop, and the red sound plays.
|
||||
* The robot waits one second, then motors move forward.
|
||||
* Loops unlimited.
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
if (sensors.color3.color() == ColorSensorColor.Black) {
|
||||
motors.largeB.run(-50)
|
||||
motors.largeC.run(0)
|
||||
} else if (sensors.color3.color() == ColorSensorColor.White) {
|
||||
motors.largeC.run(-50)
|
||||
motors.largeB.run(0)
|
||||
} else if (sensors.color3.color() == ColorSensorColor.Green) {
|
||||
motors.stopAll()
|
||||
music.playSoundEffectUntilDone(sounds.colorsGreen)
|
||||
motors.largeBC.run(-50)
|
||||
} else if (sensors.color3.color() == ColorSensorColor.Red) {
|
||||
motors.stopAll()
|
||||
music.playSoundEffectUntilDone(sounds.colorsRed)
|
||||
motors.largeBC.run(-50)
|
||||
} else {
|
||||
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
```blocks
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Black, function () {
|
||||
motors.largeB.run(-50)
|
||||
motors.largeC.run(0)
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.White, function () {
|
||||
motors.largeB.run(0)
|
||||
motors.largeC.run(-50)
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Green, function () {
|
||||
motors.stopAll()
|
||||
music.playSoundEffect(sounds.colorsGreen)
|
||||
pause(1000)
|
||||
motors.largeBC.run(-50)
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Red, function () {
|
||||
motors.stopAll()
|
||||
music.playSoundEffect(sounds.colorsRed)
|
||||
pause(1000)
|
||||
motors.largeBC.run(-50)
|
||||
})
|
||||
```
|
||||
|
||||
### Download and test
|
||||
|
||||
Click Download and follow the instructions to get your code onto your EV3 Brick. Press the center button on the EV3 Brick to run the program.
|
||||
|
||||
## Contemplate
|
||||
|
||||
### Test and Analyze
|
||||
|
||||
As you work on your solution:
|
||||
1. Describe one part of your design that worked especially well.
|
||||
2. Describe one design change that you had to make.
|
||||
3. What will you try next?
|
||||
|
||||
|
||||
### Review and Revise
|
||||
Take a moment to reflect on your robot solution.
|
||||
|
||||
### Think about:
|
||||
* Can the robot’s movement be more accurate?
|
||||
* What are some ways that others have solved the problem?
|
||||
|
||||
Describe two ways you could improve your robot.
|
||||
|
||||
## Continue
|
||||
|
||||
### Personalize your project
|
||||
* Add/remove LEGO elements to improve the way your robot moves.
|
||||
* Click on the JavaScript tab and experiment with changing the values in the code.
|
||||
* Add a custom image or sounds by adding blocks from the Brick or Music menus.
|
||||
|
||||
## Communicate
|
||||
|
||||
Here are some ideas:
|
||||
* Create a video of your project, especially your final presentation and your robot’s performance.
|
||||
* Explain some important features of your software program.
|
||||
* Produce a building guide for your model by taking a series of photographs as you deconstruct it.
|
||||
* Include an image of your program with comments.
|
||||
* Add a team photograph!
|
||||
|
||||
Congratulations! What will you design next?
|
||||
|
||||
|
@ -32,7 +32,7 @@ Think about examples from your brainstorming discussion. Then explain why you ch
|
||||
|
||||

|
||||
|
||||
https://www.youtube.com/watch?v=ErC_s3hLGMk
|
||||
https://www.youtube.com/ErC_s3hLGMk
|
||||
|
||||
## Construct
|
||||
|
||||
@ -56,13 +56,13 @@ As you test your design solution, use the table for recording your findings.
|
||||
|
||||
[**VIEW BUILDING INSTRUCTIONS**](TODO) for a sample solution. (7.8 MB, PDF)
|
||||
|
||||
# Contemplate
|
||||
## Contemplate
|
||||
|
||||
## Test and Analyze
|
||||
### Test and Analyze
|
||||
|
||||
How well does your solution satisfy the design brief? Record your data. Name the columns and rows, such as Trial Number, Distance Moved, and Observations.
|
||||
|
||||
## Review and Revise
|
||||
### Review and Revise
|
||||
|
||||
Take a moment to reflect on your robot solution.
|
||||
|
||||
@ -72,9 +72,9 @@ Think about:
|
||||
* Is it accurate? How do you know?
|
||||
Describe two ways you could improve your robot.
|
||||
|
||||
# Continue
|
||||
## Continue
|
||||
|
||||
## Communicate
|
||||
### Communicate
|
||||
|
||||
Here are some ideas:
|
||||
* Create a video of your project, especially your final presentation and your robot’s performance.
|
||||
|
@ -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"
|
||||
}]
|
||||
```
|
@ -119,15 +119,15 @@ sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectNear, function () {
|
||||
controlSteering = 0
|
||||
oldControlDrive = controlDrive
|
||||
controlDrive = -10
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
if (Math.randomRange(-1, 1) >= 1) {
|
||||
controlSteering = 70
|
||||
} else {
|
||||
controlSteering = -70
|
||||
}
|
||||
loops.pause(4000)
|
||||
pause(4000)
|
||||
music.playTone(2000, 100)
|
||||
controlSteering = 0
|
||||
controlDrive = oldControlDrive
|
||||
@ -149,8 +149,8 @@ sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {
|
||||
})
|
||||
// apply power to motors
|
||||
function controlMotors() {
|
||||
motors.largeA.setSpeed(power + controlSteering * 0.1)
|
||||
motors.largeD.setSpeed(power - controlSteering * 0.1)
|
||||
motors.largeA.run(power + controlSteering * 0.1)
|
||||
motors.largeD.run(power - controlSteering * 0.1)
|
||||
}
|
||||
sensors.color1.onColorDetected(ColorSensorColor.Yellow, function () {
|
||||
moods.middleLeft.show()
|
||||
@ -162,7 +162,7 @@ sensors.color1.onColorDetected(ColorSensorColor.White, function () {
|
||||
})
|
||||
timestep = 0.014
|
||||
// main loop
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
reset()
|
||||
while (!fallen) {
|
||||
control.timer3.pauseUntil(5)
|
||||
|
@ -36,7 +36,7 @@ function RST() {
|
||||
sensors.gyro2.reset()
|
||||
sensors.gyro2.rate()
|
||||
control.timer2.reset()
|
||||
loops.pause(5000)
|
||||
pause(5000)
|
||||
mSum = 0;
|
||||
mPos = 0;
|
||||
mD = 0;
|
||||
@ -65,7 +65,7 @@ function OS() {
|
||||
gSum = gyro;
|
||||
gMx = Math.max(gMx, gyro)
|
||||
gMn = Math.min(gMn, gyro)
|
||||
loops.pause(4);
|
||||
pause(4);
|
||||
}
|
||||
} while (gMx - gMn > 2);
|
||||
gOS = gSum / 200;
|
||||
@ -121,7 +121,7 @@ function CHK() {
|
||||
}
|
||||
|
||||
// M
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
RST();
|
||||
brick.showImage(images.eyesSleeping)
|
||||
OS()
|
||||
@ -137,12 +137,12 @@ loops.forever(function () {
|
||||
GM();
|
||||
EQ();
|
||||
cntrl();
|
||||
motors.largeA.setSpeed(lpwr)
|
||||
motors.largeD.setSpeed(rpwr)
|
||||
motors.largeA.run(lpwr)
|
||||
motors.largeD.run(rpwr)
|
||||
CHK()
|
||||
let t2 = control.timer1.millis();
|
||||
let p = 5 - (t2 - t1);
|
||||
loops.pause(Math.max(1, p))
|
||||
pause(Math.max(1, p))
|
||||
}
|
||||
motors.stopAll()
|
||||
st = 0;
|
||||
@ -154,7 +154,7 @@ loops.forever(function () {
|
||||
})
|
||||
|
||||
// BHV
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
switch (st) {
|
||||
case 0:
|
||||
Cdrv = 0;
|
||||
@ -162,7 +162,7 @@ loops.forever(function () {
|
||||
break;
|
||||
case 1:
|
||||
Cdrv = 40;
|
||||
loops.pause(4000);
|
||||
pause(4000);
|
||||
Cdrv = 0;
|
||||
music.playTone(1000, 100);
|
||||
st = 2;
|
||||
@ -196,20 +196,20 @@ loops.forever(function () {
|
||||
Cstr = 0;
|
||||
oldDr = Cdrv;
|
||||
Cdrv = -10;
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
if (Math.randomRange(-1, 1) >= 1)
|
||||
Cstr = 70;
|
||||
else
|
||||
Cstr = -70;
|
||||
loops.pause(4000);
|
||||
pause(4000);
|
||||
music.playTone(2000, 100)
|
||||
Cstr = 0;
|
||||
Cdrv = oldDr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
loops.pause(80);
|
||||
pause(80);
|
||||
})
|
||||
```
|
@ -21,7 +21,7 @@ let GTO = 0;
|
||||
function DN() {
|
||||
motors.largeAD.setBrake(true);
|
||||
motors.largeAD.tank(50, 50, 1, MoveUnit.Seconds);
|
||||
loops.pause(100);
|
||||
pause(100);
|
||||
motors.largeA.clearCounts()
|
||||
motors.largeD.clearCounts()
|
||||
}
|
||||
@ -32,9 +32,9 @@ function MNRH() {
|
||||
brick.setStatusLight(StatusLight.OrangePulse)
|
||||
while (!brick.buttonEnter.wasPressed()) {
|
||||
if (brick.buttonUp.wasPressed()) {
|
||||
motors.mediumC.setSpeed(-100);
|
||||
motors.mediumC.run(-100);
|
||||
} else if (brick.buttonDown.wasPressed()) {
|
||||
motors.mediumC.setSpeed(100);
|
||||
motors.mediumC.run(100);
|
||||
} else {
|
||||
motors.mediumC.stop();
|
||||
}
|
||||
@ -83,24 +83,24 @@ function UP() {
|
||||
if (motors.largeA.angle() > -50) {
|
||||
control.runInParallel(function () {
|
||||
motors.largeD.clearCounts()
|
||||
motors.largeD.setSpeed(-35);
|
||||
motors.largeD.run(-35);
|
||||
pauseUntil(() => motors.largeD.angle() < -25);
|
||||
motors.largeD.stop();
|
||||
motors.largeD.setRegulated(false)
|
||||
motors.largeD.setSpeed(-15)
|
||||
motors.largeD.run(-15)
|
||||
pauseUntil(() => motors.largeD.angle() < -65);
|
||||
motors.largeD.stop();
|
||||
})
|
||||
motors.largeA.clearCounts()
|
||||
motors.largeA.setSpeed(-35);
|
||||
motors.largeA.run(-35);
|
||||
pauseUntil(() => motors.largeA.angle() < -25);
|
||||
motors.largeA.stop();
|
||||
motors.largeA.setRegulated(false)
|
||||
motors.largeA.setSpeed(-15)
|
||||
motors.largeA.run(-15)
|
||||
pauseUntil(() => motors.largeA.angle() < -65);
|
||||
motors.largeA.stop();
|
||||
|
||||
loops.pause(500);
|
||||
pause(500);
|
||||
}
|
||||
}
|
||||
|
||||
@ -231,9 +231,9 @@ function IDL() {
|
||||
function MHT(Pos: number) {
|
||||
let _R = Pos - motors.mediumC.angle();
|
||||
if (_R >= 0) {
|
||||
motors.mediumC.setSpeed(100, _R, MoveUnit.Degrees);
|
||||
motors.mediumC.run(100, _R, MoveUnit.Degrees);
|
||||
} else {
|
||||
motors.mediumC.setSpeed(-100, Math.abs(_R), MoveUnit.Degrees);
|
||||
motors.mediumC.run(-100, Math.abs(_R), MoveUnit.Degrees);
|
||||
}
|
||||
}
|
||||
|
||||
@ -277,7 +277,7 @@ function NGR() {
|
||||
IS(4)
|
||||
music.playSoundEffect(sounds.animalsDogGrowl);
|
||||
UP();
|
||||
loops.pause(1500);
|
||||
pause(1500);
|
||||
music.stopAllSounds()
|
||||
music.playSoundEffect(sounds.animalsDogBark1)
|
||||
P_C--;
|
||||
@ -303,16 +303,16 @@ function PPP() {
|
||||
NS = false;
|
||||
IS(2);
|
||||
UP();
|
||||
loops.pause(100)
|
||||
motors.largeA.setSpeed(-30, 70, MoveUnit.Degrees);
|
||||
loops.pause(800);
|
||||
pause(100)
|
||||
motors.largeA.run(-30, 70, MoveUnit.Degrees);
|
||||
pause(800);
|
||||
music.playSoundEffect(sounds.mechanicalHorn1);
|
||||
loops.pause(1000);
|
||||
pause(1000);
|
||||
for(let i = 0; i < 3; ++i) {
|
||||
motors.largeA.setSpeed(-30, 20, MoveUnit.Degrees);
|
||||
motors.largeA.setSpeed(30, 20, MoveUnit.Degrees);
|
||||
motors.largeA.run(-30, 20, MoveUnit.Degrees);
|
||||
motors.largeA.run(30, 20, MoveUnit.Degrees);
|
||||
}
|
||||
motors.largeA.setSpeed(30, 70, MoveUnit.Degrees);
|
||||
motors.largeA.run(30, 70, MoveUnit.Degrees);
|
||||
F_C = 1;
|
||||
CS(0);
|
||||
}
|
||||
@ -320,14 +320,14 @@ function PPP() {
|
||||
function HPY() {
|
||||
IS(8)
|
||||
MHT(0);
|
||||
motors.largeAD.setSpeed(10, 0.8, MoveUnit.Seconds);
|
||||
motors.largeAD.run(10, 0.8, MoveUnit.Seconds);
|
||||
for(let i = 0; i < 3; ++i) {
|
||||
music.playSoundEffect(sounds.animalsDogBark1);
|
||||
motors.largeAD.setSpeed(-100, 0.2, MoveUnit.Seconds);
|
||||
loops.pause(300)
|
||||
motors.largeAD.setSpeed(10, 0.3, MoveUnit.Seconds)
|
||||
motors.largeAD.run(-100, 0.2, MoveUnit.Seconds);
|
||||
pause(300)
|
||||
motors.largeAD.run(10, 0.3, MoveUnit.Seconds)
|
||||
}
|
||||
loops.pause(500);
|
||||
pause(500);
|
||||
music.stopAllSounds();
|
||||
DN();
|
||||
RST();
|
||||
@ -335,9 +335,9 @@ function HPY() {
|
||||
|
||||
function STL() {
|
||||
UP();
|
||||
motors.largeAD.setSpeed(-20, 60, MoveUnit.Degrees);
|
||||
motors.largeAD.run(-20, 60, MoveUnit.Degrees);
|
||||
music.playSoundEffect(sounds.animalsDogWhine);
|
||||
motors.largeAD.setSpeed(20, 60, MoveUnit.Degrees);
|
||||
motors.largeAD.run(20, 60, MoveUnit.Degrees);
|
||||
}
|
||||
|
||||
function WKU() {
|
||||
@ -347,7 +347,7 @@ function WKU() {
|
||||
MHT(0)
|
||||
DN()
|
||||
STL()
|
||||
loops.pause(1000);
|
||||
pause(1000);
|
||||
UP()
|
||||
CS(0;)
|
||||
}
|
||||
@ -358,7 +358,7 @@ MNRH();
|
||||
IS(1);
|
||||
UP();
|
||||
RST();
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
MON();
|
||||
switch (DB_S) {
|
||||
case 0:
|
||||
|
@ -5,20 +5,20 @@ function INI() {
|
||||
motors.largeB.setBrake(true)
|
||||
motors.largeC.setBrake(true)
|
||||
motors.mediumA.setBrake(true)
|
||||
motors.largeB.setSpeed(-50)
|
||||
motors.largeB.run(-50)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop();
|
||||
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds);
|
||||
motors.mediumA.setSpeed(-50, 90, MoveUnit.Degrees);
|
||||
motors.largeC.setSpeed(50)
|
||||
motors.mediumA.run(30, 1, MoveUnit.Seconds);
|
||||
motors.mediumA.run(-50, 90, MoveUnit.Degrees);
|
||||
motors.largeC.run(50)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed);
|
||||
motors.largeC.setSpeed(-50, 0.86, MoveUnit.Rotations);
|
||||
motors.largeC.run(-50, 0.86, MoveUnit.Rotations);
|
||||
}
|
||||
|
||||
INI()
|
||||
|
||||
let down = false;
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
brick.showImage(images.informationQuestionMark)
|
||||
brick.setStatusLight(StatusLight.OrangePulse);
|
||||
pauseUntil(() => (down = brick.buttonDown.wasPressed()) || brick.buttonUp.wasPressed())
|
||||
@ -27,24 +27,24 @@ loops.forever(function () {
|
||||
brick.showImage(images.informationAccept)
|
||||
if (down) {
|
||||
brick.showImage(images.informationForward)
|
||||
motors.largeC.setSpeed(65, 0.85, MoveUnit.Rotations);
|
||||
motors.largeC.run(65, 0.85, MoveUnit.Rotations);
|
||||
} else {
|
||||
brick.showImage(images.informationBackward)
|
||||
motors.largeC.setSpeed(-65, 0.85, MoveUnit.Rotations);
|
||||
motors.largeC.run(-65, 0.85, MoveUnit.Rotations);
|
||||
}
|
||||
motors.largeB.setSpeed(20, 275, MoveUnit.Degrees)
|
||||
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds)
|
||||
motors.largeB.setSpeed(-55)
|
||||
motors.largeB.run(20, 275, MoveUnit.Degrees)
|
||||
motors.mediumA.run(30, 1, MoveUnit.Seconds)
|
||||
motors.largeB.run(-55)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop();
|
||||
if (down) {
|
||||
motors.largeC.setSpeed(-65, 0.86, MoveUnit.Rotations);
|
||||
motors.largeC.run(-65, 0.86, MoveUnit.Rotations);
|
||||
} else {
|
||||
motors.largeC.setSpeed(65, 0.85, MoveUnit.Rotations);
|
||||
motors.largeC.run(65, 0.85, MoveUnit.Rotations);
|
||||
}
|
||||
motors.largeB.setSpeed(20, 275, MoveUnit.Degrees);
|
||||
motors.mediumA.setSpeed(-30, 90, MoveUnit.Degrees);
|
||||
motors.largeB.setSpeed(-55)
|
||||
motors.largeB.run(20, 275, MoveUnit.Degrees);
|
||||
motors.mediumA.run(-30, 90, MoveUnit.Degrees);
|
||||
motors.largeB.run(-55)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop()
|
||||
})
|
||||
|
@ -5,20 +5,20 @@ function INI() {
|
||||
motors.largeB.setBrake(true)
|
||||
motors.largeC.setBrake(true)
|
||||
motors.mediumA.setBrake(true)
|
||||
motors.largeB.setSpeed(-50)
|
||||
motors.largeB.run(-50)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop();
|
||||
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds);
|
||||
motors.mediumA.setSpeed(-50, 90, MoveUnit.Degrees);
|
||||
motors.largeC.setSpeed(50)
|
||||
motors.mediumA.run(30, 1, MoveUnit.Seconds);
|
||||
motors.mediumA.run(-50, 90, MoveUnit.Degrees);
|
||||
motors.largeC.run(50)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed);
|
||||
motors.largeC.setSpeed(-50, 0.86, MoveUnit.Rotations);
|
||||
motors.largeC.run(-50, 0.86, MoveUnit.Rotations);
|
||||
}
|
||||
|
||||
INI()
|
||||
|
||||
let down = false;
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
brick.showImage(images.informationQuestionMark)
|
||||
brick.setStatusLight(StatusLight.OrangePulse);
|
||||
pauseUntil(() => (down = brick.buttonDown.wasPressed()) || brick.buttonUp.wasPressed())
|
||||
@ -27,24 +27,24 @@ loops.forever(function () {
|
||||
brick.showImage(images.informationAccept)
|
||||
if (down) {
|
||||
brick.showImage(images.informationForward)
|
||||
motors.largeC.setSpeed(65, 0.85, MoveUnit.Rotations);
|
||||
motors.largeC.run(65, 0.85, MoveUnit.Rotations);
|
||||
} else {
|
||||
brick.showImage(images.informationBackward)
|
||||
motors.largeC.setSpeed(-65, 0.85, MoveUnit.Rotations);
|
||||
motors.largeC.run(-65, 0.85, MoveUnit.Rotations);
|
||||
}
|
||||
motors.largeB.setSpeed(20, 275, MoveUnit.Degrees)
|
||||
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds)
|
||||
motors.largeB.setSpeed(-55)
|
||||
motors.largeB.run(20, 275, MoveUnit.Degrees)
|
||||
motors.mediumA.run(30, 1, MoveUnit.Seconds)
|
||||
motors.largeB.run(-55)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop();
|
||||
if (down) {
|
||||
motors.largeC.setSpeed(-65, 0.86, MoveUnit.Rotations);
|
||||
motors.largeC.run(-65, 0.86, MoveUnit.Rotations);
|
||||
} else {
|
||||
motors.largeC.setSpeed(65, 0.85, MoveUnit.Rotations);
|
||||
motors.largeC.run(65, 0.85, MoveUnit.Rotations);
|
||||
}
|
||||
motors.largeB.setSpeed(20, 275, MoveUnit.Degrees);
|
||||
motors.mediumA.setSpeed(-30, 90, MoveUnit.Degrees);
|
||||
motors.largeB.setSpeed(-55)
|
||||
motors.largeB.run(20, 275, MoveUnit.Degrees);
|
||||
motors.mediumA.run(-30, 90, MoveUnit.Degrees);
|
||||
motors.largeB.run(-55)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop()
|
||||
})
|
||||
|
34
docs/examples/distance-measurer.md
Normal file
34
docs/examples/distance-measurer.md
Normal file
@ -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)
|
||||
})
|
||||
```
|
@ -36,7 +36,7 @@ function RST() {
|
||||
sensors.gyro2.reset()
|
||||
sensors.gyro2.rate()
|
||||
control.timer2.reset()
|
||||
loops.pause(5000)
|
||||
pause(5000)
|
||||
mSum = 0;
|
||||
mPos = 0;
|
||||
mD = 0;
|
||||
@ -65,7 +65,7 @@ function OS() {
|
||||
gSum = gyro;
|
||||
gMx = Math.max(gMx, gyro)
|
||||
gMn = Math.min(gMn, gyro)
|
||||
loops.pause(4);
|
||||
pause(4);
|
||||
}
|
||||
} while (gMx - gMn > 2);
|
||||
gOS = gSum / 200;
|
||||
@ -121,7 +121,7 @@ function CHK() {
|
||||
}
|
||||
|
||||
// M
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
RST();
|
||||
brick.showImage(images.eyesSleeping)
|
||||
OS()
|
||||
@ -137,12 +137,12 @@ loops.forever(function () {
|
||||
GM();
|
||||
EQ();
|
||||
cntrl();
|
||||
motors.largeA.setSpeed(lpwr)
|
||||
motors.largeD.setSpeed(rpwr)
|
||||
motors.largeA.run(lpwr)
|
||||
motors.largeD.run(rpwr)
|
||||
CHK()
|
||||
let t2 = control.timer1.millis();
|
||||
let p = 5 - (t2 - t1);
|
||||
loops.pause(Math.max(1, p))
|
||||
pause(Math.max(1, p))
|
||||
}
|
||||
motors.stopAll()
|
||||
st = 0;
|
||||
@ -154,7 +154,7 @@ loops.forever(function () {
|
||||
})
|
||||
|
||||
// BHV
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
switch (st) {
|
||||
case 0:
|
||||
Cdrv = 0;
|
||||
@ -162,7 +162,7 @@ loops.forever(function () {
|
||||
break;
|
||||
case 1:
|
||||
Cdrv = 40;
|
||||
loops.pause(4000);
|
||||
pause(4000);
|
||||
Cdrv = 0;
|
||||
music.playTone(1000, 100);
|
||||
st = 2;
|
||||
@ -196,20 +196,20 @@ loops.forever(function () {
|
||||
Cstr = 0;
|
||||
oldDr = Cdrv;
|
||||
Cdrv = -10;
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
if (Math.randomRange(-1, 1) >= 1)
|
||||
Cstr = 70;
|
||||
else
|
||||
Cstr = -70;
|
||||
loops.pause(4000);
|
||||
pause(4000);
|
||||
music.playTone(2000, 100)
|
||||
Cstr = 0;
|
||||
Cdrv = oldDr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
loops.pause(80);
|
||||
pause(80);
|
||||
})
|
||||
```
|
@ -26,9 +26,9 @@ while (!(brick.buttonEnter.wasPressed())) {
|
||||
brick.showValue("min", min, 4)
|
||||
brick.showValue("max", v, 5)
|
||||
brick.showValue("setpoint", setpoint, 6)
|
||||
loops.pause(100)
|
||||
pause(100)
|
||||
}
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
brick.clearScreen()
|
||||
v = sensors.color3.light(LightIntensityMode.Reflected)
|
||||
brick.showValue("light", v, 1)
|
||||
@ -43,7 +43,7 @@ loops.forever(function () {
|
||||
motors.largeBC.steer(P + (I + D), 100)
|
||||
lasterror = error
|
||||
if (brick.buttonEnter.wasPressed()) {
|
||||
motors.largeBC.setSpeed(0)
|
||||
motors.largeBC.run(0)
|
||||
brick.buttonDown.pauseUntil(ButtonEvent.Bumped)
|
||||
}
|
||||
})
|
||||
|
@ -14,16 +14,16 @@ Take a look a the LabView program below: it **starts**, turns on motor A, waits
|
||||
The blocks in MakeCode have similar functions and go together in the same way: they snap into the ``||loops:on start||`` block and then connect to each other vertically.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(50)
|
||||
loops.pause(1000)
|
||||
motors.largeA.run(50)
|
||||
pause(1000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
Any block program can be converted to JavaScript and you can edit it as lines of code too.
|
||||
|
||||
```typescript
|
||||
motors.largeA.setSpeed(50)
|
||||
loops.pause(1000)
|
||||
motors.largeA.run(50)
|
||||
pause(1000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
@ -40,10 +40,10 @@ This program controls a large motor on port A in several different ways. It sets
|
||||

|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(50);
|
||||
motors.largeA.setSpeed(50, 1000, MoveUnit.MilliSeconds);
|
||||
motors.largeA.setSpeed(50, 360, MoveUnit.Degrees);
|
||||
motors.largeA.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeA.run(50);
|
||||
motors.largeA.run(50, 1000, MoveUnit.MilliSeconds);
|
||||
motors.largeA.run(50, 360, MoveUnit.Degrees);
|
||||
motors.largeA.run(50, 1, MoveUnit.Rotations);
|
||||
motors.largeA.stop();
|
||||
```
|
||||
|
||||
@ -83,7 +83,7 @@ By default, all motors coast when any command used to move finishes. You can kee
|
||||
|
||||
```blocks
|
||||
motors.largeD.setBrake(true);
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations)
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations)
|
||||
```
|
||||
|
||||
## Inverting and regulating motors
|
||||
@ -132,15 +132,15 @@ It is quite common to have to wait for a task to finish or for a sensor state to
|
||||

|
||||
|
||||
```blocks
|
||||
motors.largeD.setSpeed(50)
|
||||
loops.pause(1000)
|
||||
motors.largeD.run(50)
|
||||
pause(1000)
|
||||
motors.largeD.stop();
|
||||
```
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
motors.largeD.setSpeed(50)
|
||||
motors.largeD.run(50)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeD.stop();
|
||||
```
|
||||
@ -148,7 +148,7 @@ motors.largeD.stop();
|
||||

|
||||
|
||||
```blocks
|
||||
motors.largeD.setSpeed(50)
|
||||
motors.largeD.run(50)
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear)
|
||||
motors.largeD.stop();
|
||||
```
|
||||
@ -156,7 +156,7 @@ motors.largeD.stop();
|
||||
You can also use the ``||loops:pause until||`` block to wait on any [boolean](/types/boolean) expression. As your program runs, it waits until the condition (expression) inside becomes true.
|
||||
|
||||
```blocks
|
||||
motors.largeD.setSpeed(50)
|
||||
motors.largeD.run(50)
|
||||
pauseUntil(() => sensors.touch1.isPressed())
|
||||
motors.largeD.stop()
|
||||
```
|
||||
@ -166,9 +166,9 @@ motors.largeD.stop()
|
||||

|
||||
|
||||
```blocks
|
||||
loops.forever(() => {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
forever(() => {
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(-50, 1, MoveUnit.Rotations);
|
||||
})
|
||||
```
|
||||
|
||||
@ -176,13 +176,13 @@ loops.forever(() => {
|
||||
|
||||
```blocks
|
||||
for(let i = 0; i < 10; i++) {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(-50, 1, MoveUnit.Rotations);
|
||||
}
|
||||
let k = 0;
|
||||
while(k < 10) {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(-50, 1, MoveUnit.Rotations);
|
||||
k++;
|
||||
}
|
||||
```
|
||||
@ -193,9 +193,9 @@ while(k < 10) {
|
||||
|
||||
```blocks
|
||||
let light = 0;
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
light = sensors.color3.light(LightIntensityMode.Reflected);
|
||||
motors.largeD.setSpeed(light)
|
||||
motors.largeD.run(light)
|
||||
})
|
||||
```
|
||||
|
||||
@ -206,15 +206,15 @@ You can start up multiple ``||loops:forever||`` loops that will run at the same
|
||||

|
||||
|
||||
```blocks
|
||||
loops.forever(() => {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
forever(() => {
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(-50, 1, MoveUnit.Rotations);
|
||||
})
|
||||
loops.forever(() => {
|
||||
forever(() => {
|
||||
brick.showImage(images.eyesMiddleRight)
|
||||
loops.pause(1000)
|
||||
pause(1000)
|
||||
brick.showImage(images.eyesMiddleLeft)
|
||||
loops.pause(1000)
|
||||
pause(1000)
|
||||
})
|
||||
```
|
||||
|
||||
@ -225,9 +225,9 @@ The ``||logic:if||`` block allows you to run different code depending on whether
|
||||

|
||||
|
||||
```blocks
|
||||
loops.forever(function() {
|
||||
forever(function() {
|
||||
if(sensors.touch1.isPressed()) {
|
||||
motors.largeD.setSpeed(50)
|
||||
motors.largeD.run(50)
|
||||
} else {
|
||||
motors.largeD.stop()
|
||||
}
|
||||
@ -241,8 +241,8 @@ The ``||math:pick random||`` block returns a random number selected from a range
|
||||

|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
motors.largeBC.steer(Math.randomRange(-5, 5), 50)
|
||||
loops.pause(100)
|
||||
pause(100)
|
||||
})
|
||||
```
|
@ -213,13 +213,13 @@ music.playSoundEffect(sounds.systemGeneralAlert)
|
||||
}
|
||||
while (true) {
|
||||
while (true) { sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
motors.largeB.setSpeed(10)
|
||||
motors.largeC.setSpeed(-10)
|
||||
motors.largeB.run(10)
|
||||
motors.largeC.run(-10)
|
||||
}
|
||||
while (true) {
|
||||
sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
motors.largeA.setSpeed(-10)
|
||||
motors.largeA.setSpeed(10)
|
||||
motors.largeA.run(-10)
|
||||
motors.largeA.run(10)
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -235,13 +235,13 @@ You will need to constantly debug your program in order to make your robot trave
|
||||
```blocks
|
||||
while (true) {
|
||||
while (true) { sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
motors.largeB.setSpeed(10)
|
||||
motors.largeC.setSpeed(-10)
|
||||
motors.largeB.run(10)
|
||||
motors.largeC.run(-10)
|
||||
}
|
||||
while (true) {
|
||||
sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
motors.largeB.setSpeed(-10)
|
||||
motors.largeC.setSpeed(10)
|
||||
motors.largeB.run(-10)
|
||||
motors.largeC.run(10)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -3,13 +3,13 @@
|
||||
Use this program with the Programmable Brick and Large Motor.
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
motors.largeA.setSpeed(30)
|
||||
loops.pause(100)
|
||||
forever(function () {
|
||||
motors.largeA.run(30)
|
||||
pause(100)
|
||||
motors.largeA.stop()
|
||||
music.playSoundEffectUntilDone(sounds.animalsCatPurr)
|
||||
motors.largeA.setSpeed(-30)
|
||||
loops.pause(100)
|
||||
motors.largeA.run(-30)
|
||||
pause(100)
|
||||
motors.largeA.stop()
|
||||
})
|
||||
```
|
||||
|
@ -3,10 +3,10 @@
|
||||
This example program combined with the small model will make a beat and rhythm on any surface when the program is run.
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
motors.largeA.setSpeed(50)
|
||||
loops.pause(200)
|
||||
motors.largeA.setSpeed(100)
|
||||
loops.pause(200)
|
||||
forever(function () {
|
||||
motors.largeA.run(50)
|
||||
pause(200)
|
||||
motors.largeA.run(100)
|
||||
pause(200)
|
||||
})
|
||||
```
|
@ -16,7 +16,7 @@ Show the battery level percentage on the screen. Also, show a green light if the
|
||||
|
||||
```blocks
|
||||
let battery = 0;
|
||||
loops.forever(function() {
|
||||
forever(function() {
|
||||
brick.showString("Battery level:", 1)
|
||||
brick.showNumber(battery, 2)
|
||||
battery = brick.batteryLevel();
|
||||
@ -28,6 +28,6 @@ loops.forever(function() {
|
||||
} else {
|
||||
brick.setStatusLight(StatusLight.RedPulse)
|
||||
}
|
||||
loops.pause(30000)
|
||||
pause(30000)
|
||||
})
|
||||
```
|
@ -32,7 +32,7 @@ Set the brick light to green when the `down` is pressed. When the button is not
|
||||
|
||||
```blocks
|
||||
let isRed = false;
|
||||
loops.forever(function() {
|
||||
forever(function() {
|
||||
if (brick.buttonLeft.isPressed()) {
|
||||
brick.setStatusLight(StatusLight.Green);
|
||||
isRed = false;
|
||||
|
@ -16,7 +16,7 @@ brick.showString("self-destruct in:", 2);
|
||||
brick.showString("seconds", 5);
|
||||
for (let i = 0; i < 10; i++) {
|
||||
brick.showNumber(10 - i, 4);
|
||||
loops.pause(1000);
|
||||
pause(1000);
|
||||
}
|
||||
brick.clearScreen();
|
||||
```
|
||||
|
@ -24,14 +24,14 @@ brick.setStatusLight(StatusLight.Red);
|
||||
Repeatedly show a different color pattern for the brick light.
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
brick.setStatusLight(StatusLight.Orange)
|
||||
loops.pause(1000)
|
||||
pause(1000)
|
||||
brick.setStatusLight(StatusLight.GreenFlash)
|
||||
loops.pause(2000)
|
||||
pause(2000)
|
||||
brick.setStatusLight(StatusLight.RedPulse)
|
||||
loops.pause(2000)
|
||||
pause(2000)
|
||||
brick.setStatusLight(StatusLight.Off)
|
||||
loops.pause(500)
|
||||
pause(500)
|
||||
})
|
||||
```
|
||||
|
@ -3,7 +3,7 @@
|
||||
## Motion
|
||||
|
||||
```cards
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
motors.largeAB.tank(50, 50)
|
||||
motors.largeAB.steer(0, 50)
|
||||
motors.largeA.pauseUntilReady()
|
||||
|
@ -19,8 +19,8 @@ Reset the motor connected to port **A** and run it for for 2 seconds at a speed
|
||||
```blocks
|
||||
let motorAngle = 0;
|
||||
motors.largeA.reset()
|
||||
motors.largeA.setSpeed(45)
|
||||
loops.pause(2000)
|
||||
motors.largeA.run(45)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
motorAngle = motors.largeA.angle()
|
||||
```
|
||||
|
@ -15,12 +15,12 @@ See if the motor turns the same number of times for each of two count periods. R
|
||||
```blocks
|
||||
let tachoCount = 0;
|
||||
motors.largeA.reset()
|
||||
motors.largeA.setSpeed(50)
|
||||
loops.pause(10000)
|
||||
motors.largeA.run(50)
|
||||
pause(10000)
|
||||
tachoCount = motors.largeA.tacho()
|
||||
motors.largeA.clearCounts()
|
||||
motors.largeA.setSpeed(50)
|
||||
loops.pause(10000)
|
||||
motors.largeA.run(50)
|
||||
pause(10000)
|
||||
if (tachoCount == motors.largeA.tacho()) {
|
||||
brick.showString("Motor turns equal.", 1)
|
||||
} else {
|
||||
|
@ -13,13 +13,13 @@ The motor's speed is set back to `0` and the **tacho**, **angle**, and **speed**
|
||||
See what the angle count is when a motor is stopped. Then, try it again after a reset.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(30)
|
||||
loops.pause(2000)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
brick.showString("Angle count:", 1)
|
||||
brick.showNumber(motors.largeA.angle(), 2)
|
||||
motors.largeA.setSpeed(30)
|
||||
loops.pause(2000)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.reset()
|
||||
brick.showString("Angle count:", 4)
|
||||
brick.showNumber(motors.largeA.angle(), 5)
|
||||
|
@ -1,9 +1,9 @@
|
||||
# set Speed
|
||||
# run
|
||||
|
||||
Set the rotation speed of the motor as a percentage of maximum speed.
|
||||
|
||||
```sig
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
```
|
||||
|
||||
The speed setting is a pecentage of the motor's full speed. Full speed is the speed that the motor runs when the brick supplies maximum output voltage to the port.
|
||||
@ -19,7 +19,7 @@ If you use a number of milliseconds as movement units, then you don't need to in
|
||||
To run the motor for 500 milliseconds:
|
||||
|
||||
```block
|
||||
motors.largeA.setSpeed(50, 500)
|
||||
motors.largeA.run(50, 500)
|
||||
```
|
||||
|
||||
## ~
|
||||
@ -28,19 +28,19 @@ Here is how you use each different movement unit to run the motor for a fixed ro
|
||||
|
||||
```typescript
|
||||
// Run motor for 700 Milliseconds.
|
||||
motors.largeA.setSpeed(25, 700, MoveUnit.MilliSeconds);
|
||||
motors.largeA.run(25, 700, MoveUnit.MilliSeconds);
|
||||
|
||||
// Run motor for 700 Milliseconds again but no units specified.
|
||||
motors.largeA.setSpeed(25, 700);
|
||||
motors.largeA.run(25, 700);
|
||||
|
||||
// Run the motor for 45 seconds
|
||||
motors.largeA.setSpeed(50, 45, MoveUnit.Seconds);
|
||||
motors.largeA.run(50, 45, MoveUnit.Seconds);
|
||||
|
||||
// Turn the motor for 270 degrees
|
||||
motors.largeA.setSpeed(50, 270, MoveUnit.Degrees)
|
||||
motors.largeA.run(50, 270, MoveUnit.Degrees)
|
||||
|
||||
// Turn the motor at full speed for 9 full rotations
|
||||
motors.largeA.setSpeed(100, 9, MoveUnit.Rotations);
|
||||
motors.largeA.run(100, 9, MoveUnit.Rotations);
|
||||
```
|
||||
|
||||
## Parameters
|
||||
@ -56,7 +56,7 @@ motors.largeA.setSpeed(100, 9, MoveUnit.Rotations);
|
||||
Turning the motor in the opposite direction (reverse) is simple. Reverse is just a negative speed setting. To drive the motor in reverse at 25% speed:
|
||||
|
||||
```block
|
||||
motors.largeB.setSpeed(-25)
|
||||
motors.largeB.run(-25)
|
||||
```
|
||||
|
||||
## ~
|
||||
@ -68,8 +68,8 @@ motors.largeB.setSpeed(-25)
|
||||
Run the motor connected to port **A** continuously. Pause 20 seconds and then stop the motor.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(75)
|
||||
loops.pause(20000)
|
||||
motors.largeA.run(75)
|
||||
pause(20000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
@ -78,8 +78,8 @@ motors.largeA.stop()
|
||||
Run the motor connected to port **A** in reverse. Pause 5 seconds and then stop the motor.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(-60)
|
||||
loops.pause(5000)
|
||||
motors.largeA.run(-60)
|
||||
pause(5000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
@ -88,7 +88,7 @@ motors.largeA.stop()
|
||||
Run the motor connected to port **B** for 35 full rotations and then stop.
|
||||
|
||||
```blocks
|
||||
motors.largeB.setSpeed(50, 35, MoveUnit.Rotations)
|
||||
motors.largeB.run(50, 35, MoveUnit.Rotations)
|
||||
```
|
||||
|
||||
## See also
|
@ -19,8 +19,8 @@ Also, you can use the brake to do simple skid steering for your brick.
|
||||
Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and set the brake.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(30)
|
||||
loops.pause(2000)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
motors.largeA.setBrake(true)
|
||||
```
|
||||
|
@ -17,13 +17,13 @@ You use a positive value (some number greater than `0`) to drive you motor in th
|
||||
Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and switch the direciton of rotation. Run the motor at a speed of `-30`. Watch and see if the motor turns in the same direction as before.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(30)
|
||||
loops.pause(2000)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
loops.pause(2000)
|
||||
pause(2000)
|
||||
motors.largeA.setInverted(true)
|
||||
motors.largeA.setSpeed(-30)
|
||||
loops.pause(2000)
|
||||
motors.largeA.run(-30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
|
@ -22,11 +22,11 @@ Turn off the speed regulation for the motor connected to port **A**.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setRegulated(false)
|
||||
motors.largeA.setSpeed(75)
|
||||
loops.pause(20000)
|
||||
motors.largeA.run(75)
|
||||
pause(20000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[set speed](/reference/motors/motor/set-speed), [stop](/reference/motors/motor/stop)
|
||||
[run](/reference/motors/motor/run), [stop](/reference/motors/motor/stop)
|
||||
|
@ -6,7 +6,7 @@ Get the current speed of motor rotation as a percentage of maximum speed.
|
||||
motors.largeA.speed()
|
||||
```
|
||||
|
||||
The actual speed of the motor is the same or very close to it's current speed setting when the motor is regulated. If not regulated, the actual speed can change from the set speed when a force, or load, is applied to it.
|
||||
The actual speed of the motor is the same or very close to it's current speed setting when the motor is regulated. If not regulated, the actual speed can change from the speed you told it to run at (your desired or _set point_ speed) when a force, or load, is applied to it.
|
||||
|
||||
## Returns
|
||||
|
||||
@ -18,10 +18,10 @@ Turn speed regulation off and report the actual speed of the large motor in the
|
||||
|
||||
```blocks
|
||||
motors.largeA.setRegulated(false)
|
||||
motors.largeA.setSpeed(55)
|
||||
motors.largeA.run(55)
|
||||
brick.showString("Actual speed:", 1)
|
||||
for (let i = 0; i < 30; i++) {
|
||||
loops.pause(500)
|
||||
pause(500)
|
||||
brick.showNumber(motors.largeA.speed(), 3)
|
||||
}
|
||||
motors.largeA.stop()
|
||||
|
@ -13,11 +13,11 @@ The motor stops but any motion caused from previously running the motor continue
|
||||
Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and wait for 2 seconds, then continue at a speed of `50`.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(30)
|
||||
loops.pause(2000)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
loops.pause(2000)
|
||||
motors.largeA.setSpeed(50)
|
||||
pause(2000)
|
||||
motors.largeA.run(50)
|
||||
```
|
||||
|
||||
## See also
|
||||
|
@ -33,12 +33,12 @@ A standard way to know how fast a motor is turning is by measuring its _revoluti
|
||||
Run the motor connected to port **A** at half speed for 5 seconds. Display the number of full rotations on the screen.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(50)
|
||||
loops.pause(5000)
|
||||
motors.largeA.run(50)
|
||||
pause(5000)
|
||||
motors.largeA.stop()
|
||||
brick.showString("Motor rotations:", 1)
|
||||
brick.showNumber(motors.largeA.tacho() / 360, 3)
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
```
|
||||
|
||||
## See also
|
||||
|
@ -14,7 +14,7 @@ Tank the @boardname@ forward at half speed for 5 seconds and then stop.
|
||||
|
||||
```blocks
|
||||
motors.largeAB.tank(50, 50);
|
||||
loops.pause(5000);
|
||||
pause(5000);
|
||||
motors.stopAll();
|
||||
```
|
||||
|
||||
|
@ -18,7 +18,7 @@ The speed setting is a pecentage of the motor's full speed. Full speed is the sp
|
||||
|
||||
If you use just the **speed** number, the motors run continously and won't stop unless you tell them to. You can also give a value for a certain amount of distance you want the motors to rotate for. The **value** can be an amount of time, a turn angle in degrees, or a number of full rotations.
|
||||
|
||||
If you decide to use a **value** of rotation distance, you need to choose a type of movement **unit**. Also, if you use a number of milliseconds as movement units, then you don't need to include the unit type. The description in [set speed](/reference/motors/motor/set-speed) shows how to use different movement units.
|
||||
If you decide to use a **value** of rotation distance, you need to choose a type of movement **unit**. Also, if you use a number of milliseconds as movement units, then you don't need to include the unit type. The description in [run](/reference/motors/motor/run) shows how to use different movement units.
|
||||
|
||||
## Parameters
|
||||
|
||||
@ -72,13 +72,13 @@ Steer the brick in a snake pattern for a short time.
|
||||
```block
|
||||
for (let i = 0; i < 4; i++) {
|
||||
motors.largeBC.steer(30, 30)
|
||||
loops.pause(5000)
|
||||
pause(5000)
|
||||
motors.largeBC.steer(-30, 30)
|
||||
loops.pause(5000)
|
||||
pause(5000)
|
||||
}
|
||||
motors.stopAll()
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[tank](/reference/motors/synced/tank), [set speed](/reference/motors/motor/set-speed)
|
||||
[tank](/reference/motors/synced/tank), [run](/reference/motors/motor/run)
|
@ -14,7 +14,7 @@ The speed setting is a pecentage of the motor's full speed. Full speed is the sp
|
||||
|
||||
If you use just the **speed** number, the motors run continously and won't stop unless you tell them to. You can also give a value for a certain amount of distance you want the motors to rotate for. The **value** can be an amount of time, a turn angle in degrees, or a number of full rotations.
|
||||
|
||||
If you decide to use a **value** of rotation distance, you need to choose a type of movement **unit**. Also, if you use a number of milliseconds as movement units, then you don't need to include the unit type. The description in [set speed](/reference/motors/motor/set-speed) shows how to use different movement units.
|
||||
If you decide to use a **value** of rotation distance, you need to choose a type of movement **unit**. Also, if you use a number of milliseconds as movement units, then you don't need to include the unit type. The description in [run](/reference/motors/motor/run) shows how to use different movement units.
|
||||
|
||||
## Parameters
|
||||
|
||||
@ -43,9 +43,9 @@ Move the brick straight ahead and then go backward.
|
||||
|
||||
```blocks
|
||||
motors.largeAB.tank(75, 75)
|
||||
loops.pause(10000)
|
||||
pause(10000)
|
||||
motors.largeAB.tank(-55, -55)
|
||||
loops.pause(10000)
|
||||
pause(10000)
|
||||
motors.stopAll()
|
||||
```
|
||||
|
||||
@ -72,10 +72,10 @@ Run both motors in opposite directions to spin the brick around to the left.
|
||||
|
||||
```blocks
|
||||
motors.largeAB.tank(-30, 30)
|
||||
loops.pause(5000)
|
||||
pause(5000)
|
||||
motors.stopAll()
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[steer](/reference/motors/synced/steer), [set speed](/reference/motors/motor/set-speed)
|
||||
[steer](/reference/motors/synced/steer), [run](/reference/motors/motor/run)
|
@ -24,3 +24,12 @@ sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectDetected, function () {}
|
||||
sensors.ultrasonic1.distance();
|
||||
sensors.ultrasonic1.pauseUntil(UltrasonicSensorEvent.ObjectDetected);
|
||||
```
|
||||
|
||||
## Infrared
|
||||
|
||||
```cards
|
||||
sensors.infraredSensor1.onEvent(null, function () {});
|
||||
sensors.infraredSensor1.pauseUntil(null);
|
||||
sensors.infraredSensor1.proximity();
|
||||
|
||||
```
|
||||
|
BIN
docs/static/lessons/make-it-communicate.png
vendored
Normal file
BIN
docs/static/lessons/make-it-communicate.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 83 KiB |
BIN
docs/static/lessons/make-it-communicate/hero.png
vendored
Normal file
BIN
docs/static/lessons/make-it-communicate/hero.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 83 KiB |
BIN
docs/static/lessons/make-it-communicate/trackrover.mp4
vendored
Normal file
BIN
docs/static/lessons/make-it-communicate/trackrover.mp4
vendored
Normal file
Binary file not shown.
8
libs/base/shims.d.ts
vendored
8
libs/base/shims.d.ts
vendored
@ -70,17 +70,17 @@ declare namespace loops {
|
||||
* Repeats the code forever in the background. On each iteration, allows other codes to run.
|
||||
* @param body code to execute
|
||||
*/
|
||||
//% help=loops/forever weight=100 afterOnStart=true
|
||||
//% blockId=forever block="forever" blockAllowMultiple=1 shim=loops::forever
|
||||
//% help=loops/forever weight=100 afterOnStart=true deprecated=true
|
||||
//% blockId=forever_deprecated block="forever" blockAllowMultiple=1 shim=loops::forever
|
||||
function forever(a: () => void): void;
|
||||
|
||||
/**
|
||||
* Pause for the specified time in milliseconds
|
||||
* @param ms how long to pause for, eg: 100, 200, 500, 1000, 2000
|
||||
*/
|
||||
//% help=loops/pause weight=99
|
||||
//% help=loops/pause weight=99 deprecated=true
|
||||
//% async block="pause %pause=timePicker|ms"
|
||||
//% blockId=device_pause shim=loops::pause
|
||||
//% blockId=device_pause_deprecated shim=loops::pause
|
||||
function pause(ms: int32): void;
|
||||
}
|
||||
declare namespace control {
|
||||
|
@ -19,21 +19,21 @@ enum LightIntensityMode {
|
||||
}
|
||||
|
||||
const enum ColorSensorColor {
|
||||
//% block="none" jres=colors.none
|
||||
//% block="none" jres=colors.none blockIdentity=sensors.color
|
||||
None,
|
||||
//% block="black" jres=colors.black
|
||||
//% block="black" jres=colors.black blockIdentity=sensors.color
|
||||
Black,
|
||||
//% block="blue" jres=colors.blue
|
||||
//% block="blue" jres=colors.blue blockIdentity=sensors.color
|
||||
Blue,
|
||||
//% block="green" jres=colors.green
|
||||
//% block="green" jres=colors.green blockIdentity=sensors.color
|
||||
Green,
|
||||
//% block="yellow" jres=colors.yellow
|
||||
//% block="yellow" jres=colors.yellow blockIdentity=sensors.color
|
||||
Yellow,
|
||||
//% block="red" jres=colors.red
|
||||
//% block="red" jres=colors.red blockIdentity=sensors.color
|
||||
Red,
|
||||
//% block="white" jres=colors.white
|
||||
//% block="white" jres=colors.white blockIdentity=sensors.color
|
||||
White,
|
||||
//% block="brown" jres=colors.brown
|
||||
//% block="brown" jres=colors.brown blockIdentity=sensors.color
|
||||
Brown
|
||||
}
|
||||
|
||||
@ -294,7 +294,7 @@ namespace sensors {
|
||||
}
|
||||
|
||||
// wait a bit
|
||||
loops.pause(50);
|
||||
pause(50);
|
||||
}
|
||||
|
||||
// apply tolerance
|
||||
@ -318,6 +318,11 @@ namespace sensors {
|
||||
//% blockId=colorSensorColor block="color %color"
|
||||
//% group="Color Sensor"
|
||||
//% weight=97
|
||||
//% color.fieldEditor="gridpicker"
|
||||
//% color.fieldOptions.columns=4
|
||||
//% color.fieldOptions.tooltips=true
|
||||
//% color.fieldOptions.hideRect=true
|
||||
//% color.fieldOptions.width=268
|
||||
export function color(color: ColorSensorColor): ColorSensorColor {
|
||||
return color;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Ambient Light
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
if (sensors.color1.ambientLight() > 20) {
|
||||
brick.setStatusLight(StatusLight.Green)
|
||||
} else {
|
||||
|
@ -1,7 +1,7 @@
|
||||
# color
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
if (sensors.color1.color() == ColorSensorColor.Green) {
|
||||
brick.setStatusLight(StatusLight.Green)
|
||||
} else {
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Reflected Light
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
if (sensors.color1.reflectedLight() > 20) {
|
||||
brick.setStatusLight(StatusLight.Green)
|
||||
} else {
|
||||
|
@ -248,7 +248,7 @@ namespace brick {
|
||||
|
||||
/**
|
||||
* Set lights.
|
||||
* @param pattern the lights pattern to use. eg: BrickLight.Orange
|
||||
* @param pattern the lights pattern to use. eg: StatusLight.Orange
|
||||
*/
|
||||
//% blockId=setLights block="set status light to %pattern"
|
||||
//% weight=100 group="Buttons"
|
||||
|
@ -15,7 +15,7 @@ namespace sensors.internal {
|
||||
let prev = query()
|
||||
changeHandler(prev, prev)
|
||||
while (true) {
|
||||
loops.pause(periodMs)
|
||||
pause(periodMs)
|
||||
let curr = query()
|
||||
if (prev !== curr) {
|
||||
changeHandler(prev, curr)
|
||||
@ -57,9 +57,9 @@ namespace sensors.internal {
|
||||
uartMM = control.mmap("/dev/lms_uart", UartOff.Size, 0)
|
||||
if (!uartMM) control.fail("no uart sensor")
|
||||
|
||||
loops.forever(() => {
|
||||
forever(() => {
|
||||
detectDevices()
|
||||
loops.pause(500)
|
||||
pause(500)
|
||||
})
|
||||
|
||||
for (let info_ of sensorInfos) {
|
||||
@ -258,7 +258,7 @@ namespace sensors.internal {
|
||||
if (port < 0) return 0
|
||||
let s = getUartStatus(port)
|
||||
if (s) return s
|
||||
loops.pause(25)
|
||||
pause(25)
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,7 +280,7 @@ namespace sensors.internal {
|
||||
|
||||
uartMM.setNumber(NumberFormat.Int8LE, UartOff.Status + port,
|
||||
getUartStatus(port) & 0xfffe)
|
||||
loops.pause(10)
|
||||
pause(10)
|
||||
}
|
||||
}
|
||||
|
||||
@ -299,7 +299,7 @@ namespace sensors.internal {
|
||||
} else {
|
||||
break
|
||||
}
|
||||
loops.pause(10)
|
||||
pause(10)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,17 +134,17 @@ namespace motors {
|
||||
protected _brake: boolean;
|
||||
private _initialized: boolean;
|
||||
private _init: () => void;
|
||||
private _setSpeed: (speed: number) => void;
|
||||
private _run: (speed: number) => void;
|
||||
private _move: (steps: boolean, stepsOrTime: number, speed: number) => void;
|
||||
|
||||
constructor(port: Output, init: () => void, setSpeed: (speed: number) => void, move: (steps: boolean, stepsOrTime: number, speed: number) => void) {
|
||||
constructor(port: Output, init: () => void, run: (speed: number) => void, move: (steps: boolean, stepsOrTime: number, speed: number) => void) {
|
||||
super();
|
||||
this._port = port;
|
||||
this._portName = outputToName(this._port);
|
||||
this._brake = false;
|
||||
this._initialized = false;
|
||||
this._init = init;
|
||||
this._setSpeed = setSpeed;
|
||||
this._run = run;
|
||||
this._move = move;
|
||||
}
|
||||
|
||||
@ -202,7 +202,7 @@ namespace motors {
|
||||
// if we've recently completed a motor command with brake
|
||||
// allow 500ms for robot to settle
|
||||
if(this._brake)
|
||||
loops.pause(500);
|
||||
pause(500);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -218,17 +218,17 @@ namespace motors {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the motor speed for limited time or distance.
|
||||
* Runs the motor at a given speed for limited time or distance.
|
||||
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
|
||||
* @param value (optional) measured distance or rotation
|
||||
* @param unit (optional) unit of the value
|
||||
*/
|
||||
//% blockId=motorSetSpeed block="set %motor speed to %speed=motorSpeedPicker|\\%||for %value %unit"
|
||||
//% blockId=motorRun block="run %motor at %speed=motorSpeedPicker|\\%||for %value %unit"
|
||||
//% weight=100 blockGap=8
|
||||
//% group="Move"
|
||||
//% expandableArgumentMode=toggle
|
||||
//% help=motors/motor/set-speed
|
||||
setSpeed(speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
|
||||
//% help=motors/motor/run
|
||||
run(speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
|
||||
this.init();
|
||||
speed = Math.clamp(-100, 100, speed >> 0);
|
||||
// stop if speed is 0
|
||||
@ -238,7 +238,7 @@ namespace motors {
|
||||
}
|
||||
// special: 0 is infinity
|
||||
if (value == 0) {
|
||||
this._setSpeed(speed);
|
||||
this._run(speed);
|
||||
return;
|
||||
}
|
||||
// timed motor moves
|
||||
|
@ -31,15 +31,15 @@ brick.buttonUp.onEvent(ButtonEvent.Bumped, () => {
|
||||
|
||||
let num = 0
|
||||
|
||||
loops.forever(() => {
|
||||
forever(() => {
|
||||
serial.writeDmesg()
|
||||
loops.pause(100)
|
||||
pause(100)
|
||||
})
|
||||
|
||||
/*
|
||||
loops.forever(() => {
|
||||
forever(() => {
|
||||
let v = input.color.getColor()
|
||||
screen.print(10, 60, v + " ")
|
||||
loops.pause(200)
|
||||
pause(200)
|
||||
})
|
||||
*/
|
||||
|
@ -41,7 +41,7 @@ namespace control {
|
||||
//% blockId=timerPauseUntil block="%timer|pause until (ms) %ms"
|
||||
pauseUntil(ms: number) {
|
||||
const remaining = this.millis() - ms;
|
||||
loops.pause(Math.max(0, remaining));
|
||||
pause(Math.max(0, remaining));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// This is the last thing executed before user code
|
||||
|
||||
// We pause for 100ms to give time to read sensor values, so they work in on_start block
|
||||
loops.pause(100)
|
||||
pause(100)
|
||||
|
@ -18,7 +18,7 @@ When the brick is in motion, it moves in the direction of one of axes used to me
|
||||
Flash the status light to red if the roll rate of `gyro 2` is more that `30` degrees per second.
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
if (sensors.gyro2.rate() > 30) {
|
||||
brick.setStatusLight(StatusLight.RedFlash)
|
||||
} else {
|
||||
|
@ -95,7 +95,7 @@ namespace sensors {
|
||||
this.calibrating = true;
|
||||
// may be triggered by a button click,
|
||||
// give time for robot to settle
|
||||
loops.pause(700);
|
||||
pause(700);
|
||||
// send a reset command
|
||||
super.reset();
|
||||
// switch back to the desired mode
|
||||
@ -103,13 +103,13 @@ namespace sensors {
|
||||
// wait till sensor is live
|
||||
pauseUntil(() => this.isActive());
|
||||
// give it a bit of time to init
|
||||
loops.pause(1000)
|
||||
pause(1000)
|
||||
// compute drift
|
||||
this._drift = 0;
|
||||
if (this.mode == GyroSensorMode.Rate) {
|
||||
for (let i = 0; i < 200; ++i) {
|
||||
this._drift += this._query();
|
||||
loops.pause(4);
|
||||
pause(4);
|
||||
}
|
||||
this._drift /= 200;
|
||||
}
|
||||
|
13
libs/infrared-sensor/docs/reference/sensors/infrared.md
Normal file
13
libs/infrared-sensor/docs/reference/sensors/infrared.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Infrared sensor
|
||||
|
||||
```cards
|
||||
sensors.infraredSensor1.onEvent(null, function () {});
|
||||
sensors.infraredSensor1.pauseUntil(null);
|
||||
sensors.infraredSensor1.proximity();
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[on event](/reference/sensors/infrared/on-event),
|
||||
[pause until](/reference/sensors/infrared/pause-until),
|
||||
[proximity](/reference/sensors/infrared/proximity)
|
@ -0,0 +1,35 @@
|
||||
# on Event
|
||||
|
||||
Run some code when an object is detected by the infrared sensor.
|
||||
|
||||
```sig
|
||||
sensors.infraredSensor4.onEvent(InfraredSensorEvent.ObjectNear, function () {});
|
||||
```
|
||||
|
||||
How an object is detected depends on the light _thresholds_ set for the sensor. A threshold is a number for relative distance of the a return of reflected infrared light. The brighter the light, the nearer the object is. The value for what _near_ means is determined by this threshold. A certain minimum amount of light returned is also set to determine that an object is detected. The two thresholds you can set are:
|
||||
|
||||
* **near**: a distance to set to detect objects coming close
|
||||
* **detected**: the brightness of infrared light to needed to detect presence of another infrared transmitter.
|
||||
|
||||
## Parameters
|
||||
|
||||
* **event**: the object detection action to wait for. The detection types (events) are:
|
||||
> * ``detected``: some other object is sending out infrared light
|
||||
> * ``near``: the sensor detected something within the distance of the near threshold
|
||||
* **body**: the code you want to run when something is detected by infrared sensor.
|
||||
|
||||
## Example
|
||||
|
||||
When the ultrasonic sensor on port 4 detects a near object, display its distance on the screen.
|
||||
|
||||
```blocks
|
||||
sensors.infraredSensor4.onEvent(InfraredSensorEvent.ObjectNear, function () {
|
||||
brick.showString("Object detected at:", 1)
|
||||
brick.showNumber(sensors.infraredSensor4.proximity(), 2)
|
||||
brick.showString("percent of range", 3)
|
||||
})
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[pause until](/reference/sensors/infrared/pause-until)
|
@ -0,0 +1,34 @@
|
||||
# pause Until
|
||||
|
||||
Make your program wait until an some object is detected in proximity of the infrared sensor.
|
||||
|
||||
```sig
|
||||
sensors.infraredSensor1.pauseUntil(InfraredSensorEvent.ObjectDetected);
|
||||
```
|
||||
|
||||
How an object is detected depends on the light _thresholds_ set for the sensor. A threshold is a number for relative distance of the a return of reflected infrared light. The brighter the light, the nearer the object is. The value for what _near_ means is determined by this threshold. A certain minimum amount of light returned is also set to determine that an object is detected. The two thresholds you can set are:
|
||||
|
||||
* **near**: a distance to set to detect objects coming close
|
||||
* **detected**: the brightness of infrared light to needed to detect presence of another infrared transmitter.
|
||||
|
||||
## Parameters
|
||||
|
||||
* **event**: the object detection action to wait for. The detection types (events) are:
|
||||
> * ``detected``: some other object is sending out infrared light
|
||||
> * ``near``: the sensor detected something within the distance of the near threshold
|
||||
|
||||
## Example
|
||||
|
||||
Wait for another object sending out infrared light. Show a message on the screen when it's dectected.
|
||||
|
||||
```blocks
|
||||
brick.showString("Waiting for another", 1);
|
||||
brick.showString("robot to appear...", 2);
|
||||
sensors.infraredSensor1.pauseUntil(InfraredSensorEvent.ObjectDetected);
|
||||
brick.showString("Hey, I just saw", 1)
|
||||
brick.showString("Something!", 2);
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[on event](/reference/sensors/ultrasonic/on-event)
|
@ -0,0 +1,30 @@
|
||||
# proximity
|
||||
|
||||
Get the promixity of an object measured by the infrared sensor.
|
||||
|
||||
```sig
|
||||
sensors.infraredSensor1.proximity();
|
||||
```
|
||||
|
||||
The proximity value returned is a number between `0` and `100` which is a _relative_ measurment of distance to an object. A value of `0` means something is very close and `100` means something is far away. The proximity is determined by the amount of infrared light reflected back by an object. The proximity value for an object that has a lighter color and smooth surface will be less than an object at the same distance with a darker color and a rough surface.
|
||||
|
||||
Proximity isn't an actual measurement units of distance, like in centimeters or meters, but it gives you an idea whether something is close or not so close.
|
||||
|
||||
## Returns
|
||||
|
||||
* a [number](/types/number) that is `0` for (very near) to `100` (far). The value is relative to the range of the infrared sensor.
|
||||
|
||||
## Example
|
||||
|
||||
When the infrared sensor on port 4 detects a near object, display its proximity value on the screen.
|
||||
|
||||
```blocks
|
||||
sensors.infraredSensor4.onEvent(InfraredSensorEvent.ObjectNear, function () {
|
||||
brick.clearScreen()
|
||||
brick.showValue("proximity", sensors.infraredSensor4.proximity(), 1)
|
||||
})
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[on event](/reference/sensors/infrared/on-event), [pause until](/reference/sensors/infrared/pause-until)
|
@ -184,7 +184,7 @@ namespace sensors {
|
||||
* Registers code to run when an object is getting near.
|
||||
* @param handler the code to run when detected
|
||||
*/
|
||||
//% help=input/infrared/on
|
||||
//% help=sensors/infrared/on-event
|
||||
//% block="on %sensor|%event"
|
||||
//% blockId=infraredOn
|
||||
//% parts="infraredsensor"
|
||||
@ -199,7 +199,7 @@ namespace sensors {
|
||||
/**
|
||||
* Waits for the event to occur
|
||||
*/
|
||||
//% help=input/ultrasonic/wait
|
||||
//% help=sensors/infrared/pause-until
|
||||
//% block="pause until %sensor| %event"
|
||||
//% blockId=infraredwait
|
||||
//% parts="infraredsensor"
|
||||
@ -215,7 +215,7 @@ namespace sensors {
|
||||
* Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)
|
||||
* @param sensor the infrared sensor
|
||||
*/
|
||||
//% help=input/infrared/proximity
|
||||
//% help=sensors/infrared/proximity
|
||||
//% block="%sensor|proximity"
|
||||
//% blockId=infraredGetProximity
|
||||
//% parts="infrared"
|
||||
|
@ -33,7 +33,7 @@ namespace brick {
|
||||
brick.setStatusLight(this.light);
|
||||
brick.showImage(this.image);
|
||||
music.playSoundEffectUntilDone(this.sound);
|
||||
loops.pause(20);
|
||||
pause(20);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
music.setVolume(3)
|
||||
music.playTone(440, 500)
|
||||
loops.pause(500)
|
||||
pause(500)
|
||||
music.playTone(1440, 500)
|
||||
loops.pause(500)
|
||||
pause(500)
|
||||
music.playTone(2440, 500)
|
||||
loops.pause(500)
|
||||
pause(500)
|
||||
|
@ -7,9 +7,9 @@ A unit test framework
|
||||
Tests are registered as event handlers. They will automatically run once ``on start`` is finished.
|
||||
|
||||
```blocks
|
||||
tests.test("lgB set speed 10", () => {
|
||||
motors.largeB.setSpeed(10);
|
||||
loops.pause(100)
|
||||
tests.test("lgB run 10", () => {
|
||||
motors.largeB.run(10);
|
||||
pause(100)
|
||||
tests.assertClose("speedB", 10, motors.largeB.speed(), 2)
|
||||
});
|
||||
```
|
||||
|
@ -14,7 +14,7 @@ sensors.touch1.isPressed()
|
||||
If the touch sensor ``touch 1`` is pressed, show a `green` status light. Otherwise, set the status light to `orange`.
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
if (sensors.touch1.isPressed()) {
|
||||
brick.setStatusLight(StatusLight.Green)
|
||||
} else {
|
||||
|
@ -17,13 +17,13 @@ If a touch sensor was pressed, then that event is remembered. Once you check if
|
||||
If the touch sensor ``touch 1`` was pressed, show a `green` status light. Otherwise, set the status light to `orange`.
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
if (sensors.touch1.wasPressed()) {
|
||||
brick.setStatusLight(StatusLight.Green)
|
||||
} else {
|
||||
brick.setStatusLight(StatusLight.Orange)
|
||||
}
|
||||
loops.pause(500)
|
||||
pause(500)
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -20,7 +20,7 @@ Both **near** and **far** have distance thresholds set in centimeters. The **det
|
||||
> * ``object detected``: some other object is sending out an ultrasonic sound
|
||||
> * ``object near``: the sensor detected something within the distance of the near threshold
|
||||
> * ``object far``: the sensor detected somethin within the distance of the far threshold
|
||||
* **body**: the code you want to run when something happens to the touch sensor.
|
||||
* **body**: the code you want to run when something is dectected by the ultrasonic sensor.
|
||||
|
||||
## Example
|
||||
|
||||
|
@ -17,9 +17,9 @@ Both **near** and **far** have distance thresholds set in centimeters. The **det
|
||||
## Parameters
|
||||
|
||||
* **event**: the object detection action to wait for. The detection types (events) are:
|
||||
> * ``object detected``: some other object is sending out an ultrasonic sound
|
||||
> * ``object near``: the sensor detected something within the distance of the near threshold
|
||||
> * ``object far``: the sensor detected somethin within the distance of the far threshold
|
||||
> * ``detected``: some other object is sending out an ultrasonic sound
|
||||
> * ``near``: the sensor detected something within the distance of the near threshold
|
||||
> * ``far``: the sensor detected somethin within the distance of the far threshold
|
||||
|
||||
## Example
|
||||
|
||||
|
128
package-lock.json
generated
128
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-ev3",
|
||||
"version": "0.0.101",
|
||||
"version": "0.0.104",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -3274,19 +3274,19 @@
|
||||
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4="
|
||||
},
|
||||
"pxt-common-packages": {
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/pxt-common-packages/-/pxt-common-packages-0.19.1.tgz",
|
||||
"integrity": "sha512-I+4nnq/QaGTMyZctUXBGBAB+I09a4VfaxShPtjZjx7oS9dNYg+95yUHl/izPZhmCq4W8pcJ2D7x4//E7nXw5Iw==",
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/pxt-common-packages/-/pxt-common-packages-0.19.4.tgz",
|
||||
"integrity": "sha512-sAccQrTh+LNuuDuQlkeuGaRu99+7iORfiREJV7eemqzr5yuspgA9aLif0FYFIPas37RD8Uoz+n36RxgsKZoLJg==",
|
||||
"requires": {
|
||||
"autoprefixer": "6.7.7",
|
||||
"pxt-core": "3.4.1",
|
||||
"pxt-core": "3.4.3",
|
||||
"rtlcss": "2.2.1"
|
||||
}
|
||||
},
|
||||
"pxt-core": {
|
||||
"version": "3.4.1",
|
||||
"resolved": "https://registry.npmjs.org/pxt-core/-/pxt-core-3.4.1.tgz",
|
||||
"integrity": "sha512-xP386XsMFejInYwtzz7FWuE2hbA0gjtxOZjFzxUb8RfZKIDLjoHSod/q/TUKcmWXU0ytepuTtNbC7a4Hp8Ndmw==",
|
||||
"version": "3.4.3",
|
||||
"resolved": "https://registry.npmjs.org/pxt-core/-/pxt-core-3.4.3.tgz",
|
||||
"integrity": "sha512-zsBf5/pf9B5vS4THqTQLOFodi+o0GtX2npvT3efF6Cql29dXtzVYKUAxSclzGCtNljI34dC++CLaaPfYfzMOnQ==",
|
||||
"requires": {
|
||||
"bluebird": "3.5.1",
|
||||
"browserify": "13.3.0",
|
||||
@ -3315,75 +3315,28 @@
|
||||
}
|
||||
},
|
||||
"chalk": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.0.tgz",
|
||||
"integrity": "sha512-Az5zJR2CBujap2rqXGaJKaPHyJ0IrUimvYNX+ncCy8PJP4ltOGTrHUIo097ZaL2zMeKYpiCdqDvS6zdrTFok3Q==",
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.1.tgz",
|
||||
"integrity": "sha512-QUU4ofkDoMIVO7hcx1iPTISs88wsO8jA92RQIm4JAwZvFGGAV2hSAA1NX7oVj2Ej2Q6NDTcRDjPTFrMCRZoJ6g==",
|
||||
"requires": {
|
||||
"ansi-styles": "3.2.0",
|
||||
"escape-string-regexp": "1.0.5",
|
||||
"supports-color": "4.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"supports-color": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz",
|
||||
"integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=",
|
||||
"requires": {
|
||||
"has-flag": "2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"commander": {
|
||||
"version": "2.14.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.14.1.tgz",
|
||||
"integrity": "sha512-+YR16o3rK53SmWHU3rEM3tPAh2rwb1yPcQX5irVn7mb0gXbwuCCrnkbV5+PBfETdfg1vui07nM6PCG1zndcjQw==",
|
||||
"optional": true
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
"supports-color": "5.2.0"
|
||||
}
|
||||
},
|
||||
"has-flag": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz",
|
||||
"integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE="
|
||||
},
|
||||
"nan": {
|
||||
"version": "2.8.0",
|
||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.8.0.tgz",
|
||||
"integrity": "sha1-7XFfP+neArV6XmJS2QqWZ14fCFo=",
|
||||
"optional": true
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
||||
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
|
||||
},
|
||||
"postcss": {
|
||||
"version": "6.0.17",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-6.0.17.tgz",
|
||||
"integrity": "sha512-Bl1nybsSzWYbP8O4gAVD8JIjZIul9hLNOPTGBIlVmZNUnNAGL+W0cpYWzVwfImZOwumct4c1SDvSbncVWKtXUw==",
|
||||
"requires": {
|
||||
"chalk": "2.3.0",
|
||||
"chalk": "2.3.1",
|
||||
"source-map": "0.6.1",
|
||||
"supports-color": "5.1.0"
|
||||
}
|
||||
},
|
||||
"serialport": {
|
||||
"version": "6.0.5",
|
||||
"resolved": "https://registry.npmjs.org/serialport/-/serialport-6.0.5.tgz",
|
||||
"integrity": "sha512-ZYof3a9m08LTgDU82TFAbjRADIZ1GQTrqXY6JYnCHk8NFv0bEU0qL/MMX8F4wB9oNVbtkaYYeJc6E+gl2bSXpw==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"bindings": "1.3.0",
|
||||
"commander": "2.14.1",
|
||||
"debug": "3.1.0",
|
||||
"nan": "2.8.0",
|
||||
"prebuild-install": "2.4.1",
|
||||
"promirepl": "1.0.1",
|
||||
"prompt-list": "3.1.2",
|
||||
"safe-buffer": "5.1.1"
|
||||
"supports-color": "5.2.0"
|
||||
}
|
||||
},
|
||||
"source-map": {
|
||||
@ -3392,11 +3345,11 @@
|
||||
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.1.0.tgz",
|
||||
"integrity": "sha512-Ry0AwkoKjDpVKK4sV4h6o3UJmNRbjYm2uXhwfj3J56lMVdvnUNqzQVRztOOMGQ++w1K/TjNDFvpJk0F/LoeBCQ==",
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.2.0.tgz",
|
||||
"integrity": "sha512-F39vS48la4YvTZUPVeTqsjsFNrvcMwrV3RLZINsmHo+7djCvuUzSIeXOnZ5hmjef4bajL1dNccN+tg5XAliO5Q==",
|
||||
"requires": {
|
||||
"has-flag": "2.0.0"
|
||||
"has-flag": "3.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3771,6 +3724,45 @@
|
||||
"integrity": "sha512-WfG/X9+oATh81XtllIo/I8gOiY9EXRdv1cQdyykeXK17YcUW3EXUAi2To4pcH6nZtJPr7ZOpM5OMyWJZm+8Rsg==",
|
||||
"optional": true
|
||||
},
|
||||
"serialport": {
|
||||
"version": "6.0.5",
|
||||
"resolved": "https://registry.npmjs.org/serialport/-/serialport-6.0.5.tgz",
|
||||
"integrity": "sha512-ZYof3a9m08LTgDU82TFAbjRADIZ1GQTrqXY6JYnCHk8NFv0bEU0qL/MMX8F4wB9oNVbtkaYYeJc6E+gl2bSXpw==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"bindings": "1.3.0",
|
||||
"commander": "2.14.1",
|
||||
"debug": "3.1.0",
|
||||
"nan": "2.8.0",
|
||||
"prebuild-install": "2.4.1",
|
||||
"promirepl": "1.0.1",
|
||||
"prompt-list": "3.1.2",
|
||||
"safe-buffer": "5.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"commander": {
|
||||
"version": "2.14.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.14.1.tgz",
|
||||
"integrity": "sha512-+YR16o3rK53SmWHU3rEM3tPAh2rwb1yPcQX5irVn7mb0gXbwuCCrnkbV5+PBfETdfg1vui07nM6PCG1zndcjQw==",
|
||||
"optional": true
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"nan": {
|
||||
"version": "2.8.0",
|
||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.8.0.tgz",
|
||||
"integrity": "sha1-7XFfP+neArV6XmJS2QqWZ14fCFo=",
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"set-blocking": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-ev3",
|
||||
"version": "0.0.101",
|
||||
"version": "0.0.104",
|
||||
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
|
||||
"private": true,
|
||||
"keywords": [
|
||||
@ -45,8 +45,8 @@
|
||||
"webfonts-generator": "^0.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-common-packages": "0.19.4",
|
||||
"pxt-core": "3.4.3"
|
||||
"pxt-common-packages": "0.19.5",
|
||||
"pxt-core": "3.4.6"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
||||
|
@ -15,7 +15,7 @@ tests.test("Bright ambient light", function () {
|
||||
let actualLight: number
|
||||
for (let i = 0; i < 4; i++) {
|
||||
actualLight = sensors.color1.ambientLight()
|
||||
loops.pause(500)
|
||||
pause(500)
|
||||
}
|
||||
tests.assertClose("Light", actualLight, 20, 15)
|
||||
})
|
||||
@ -29,7 +29,7 @@ tests.test("Bright reflected light", function () {
|
||||
let actualLight: number
|
||||
for (let i = 0; i < 4; i++) {
|
||||
actualLight = sensors.color1.reflectedLight()
|
||||
loops.pause(500)
|
||||
pause(500)
|
||||
}
|
||||
tests.assertClose("Light", actualLight, 17, 14)
|
||||
})
|
@ -1,42 +1,42 @@
|
||||
// add tests package
|
||||
tests.test("lgB set speed 10", () => {
|
||||
motors.largeB.setSpeed(10);
|
||||
loops.pause(500)
|
||||
tests.test("lgB run 10", () => {
|
||||
motors.largeB.run(10);
|
||||
pause(500)
|
||||
tests.assertClose("speedB", 10, motors.largeB.speed(), 2)
|
||||
});
|
||||
tests.test("lgB set speed 25 (reversed)", () => {
|
||||
tests.test("lgB run 25 (reversed)", () => {
|
||||
motors.largeB.setInverted(true)
|
||||
motors.largeB.setSpeed(25)
|
||||
loops.pause(500)
|
||||
motors.largeB.run(25)
|
||||
pause(500)
|
||||
tests.assertClose("speedB", -25, motors.largeB.speed(), 2)
|
||||
});
|
||||
tests.test("lgBC set speed 5", () => {
|
||||
motors.largeBC.setSpeed(5)
|
||||
loops.pause(500)
|
||||
tests.test("lgBC run 5", () => {
|
||||
motors.largeBC.run(5)
|
||||
pause(500)
|
||||
tests.assertClose("speedB", 5, motors.largeB.speed(), 1);
|
||||
tests.assertClose("speedC", 5, motors.largeC.speed(), 1);
|
||||
});
|
||||
tests.test("lgBC steer 50% 2x", () => {
|
||||
motors.largeBC.setBrake(true)
|
||||
motors.largeBC.steer(50, 50, 1, MoveUnit.Rotations)
|
||||
loops.pause(2000)
|
||||
pause(2000)
|
||||
tests.assertClose("largeB", 360, motors.largeB.angle(), 5)
|
||||
motors.largeBC.setBrake(false)
|
||||
})
|
||||
tests.test("lgBC steer 360deg", () => {
|
||||
motors.largeBC.setBrake(true)
|
||||
motors.largeBC.steer(50, 50, 360, MoveUnit.Degrees)
|
||||
loops.pause(2000)
|
||||
pause(2000)
|
||||
tests.assertClose("largeB", 360, motors.largeB.angle(), 5)
|
||||
});
|
||||
tests.test("lgBC steer 50% 1s", () => {
|
||||
motors.largeBC.setBrake(true)
|
||||
motors.largeBC.steer(10, 50, 1000, MoveUnit.MilliSeconds)
|
||||
loops.pause(2000)
|
||||
pause(2000)
|
||||
})
|
||||
tests.test("lgBC tank 50% 180deg", () => {
|
||||
motors.largeBC.setBrake(true)
|
||||
motors.largeBC.tank(50, 50, 180, MoveUnit.Degrees)
|
||||
loops.pause(1000)
|
||||
pause(1000)
|
||||
tests.assertClose("largeB", 180, motors.largeB.angle(), 5)
|
||||
});
|
||||
|
Reference in New Issue
Block a user