Compare commits

...

29 Commits

Author SHA1 Message Date
f16549d7cd 0.0.108 2018-02-26 13:38:20 -08:00
a021c0b292 Use a color picker for the color field (color enum picker) (#346) 2018-02-26 13:37:58 -08:00
cda7013e96 fixing links 2018-02-26 13:27:03 -08:00
2f0fefbeaf updated images 2018-02-26 13:25:53 -08:00
b5303a660b 0.0.107 2018-02-26 11:22:44 -08:00
a60958f72a Update search icon and avatar SVG (#345) 2018-02-26 10:43:29 -08:00
33dcb6deee renaming infraredSensor to infrared (#344) 2018-02-26 10:39:15 -08:00
130a47d684 Sensor names are now part of the block text (#341)
* Sensor names are now part of the block text

* Use ports field editor
2018-02-26 11:33:50 -05:00
2d355bb2ca Merge branch 'master' of https://github.com/microsoft/pxt-ev3 2018-02-23 20:38:53 -08:00
8ee63df325 Add in 'console' doc stuff (#342)
* Add 'playSound' api docs

* Add in 'console' doc stuff

* Add 'send to screen' in summary\
2018-02-23 14:13:08 -08:00
7d16cf10ac added make it smarter 2018-02-23 07:37:32 -08:00
60ec3f1c99 Add 'playSound' api docs (#340)
* Add 'playSound' api docs

* Linkup summary
2018-02-22 16:23:07 -08:00
6524b0a841 Add 'timer' api docs (#339) 2018-02-22 14:56:15 -08:00
d778232155 removing .mp4 file 2018-02-22 10:24:40 -08:00
c157b4d922 0.0.106 2018-02-22 10:18:13 -08:00
0837123828 bumping pxt 2018-02-22 10:15:58 -08:00
e51a32b69f use full motor names (#338) 2018-02-22 10:03:25 -08:00
029066000d updated style 2018-02-22 08:28:42 -08:00
7e35abeff3 lock on 0.0.104 2018-02-22 06:54:18 -08:00
0166785c1b 0.0.105 2018-02-22 06:36:41 -08:00
ea0f6a4734 updated pxt 2018-02-22 06:36:26 -08:00
271721561d turn sample into blocks 2018-02-21 22:39:35 -08:00
ed8f8bafa7 Add 'infrared beacon' api topics (#330)
* Add 'infrared beacon' api topics

* Include note about channel selection
2018-02-21 22:35:51 -08:00
8cfb70c97b Threshold api docs - 01 (#336)
* Local commit

* Throw on more topics

* Throw in threshold topics for infrared
2018-02-21 22:35:25 -08:00
84c8e31ff5 First burst of 'color' pages (#335)
* Add 'color sensor' api topics

* Last set of edits/adds
2018-02-21 14:03:55 -08:00
ceb9b7fabf 0.0.104 2018-02-21 06:45:29 -08:00
9e0670551f upgrading pxt 2018-02-21 06:45:14 -08:00
6613607503 Make it comm lesson (#331)
* integrating lego lesson

* fixed link

* adding various solutions

* updatring to 3.4.6

* using play sound effect until done

* revert pxtversion

* fixing link
2018-02-21 06:43:53 -08:00
3a67190914 Add some 'infrared' api docs (#326)
* Add some 'infrared' api docs

* Fix display messages

* Change discussion of distance to relative

* Include motor speed note
2018-02-20 10:38:41 -08:00
97 changed files with 7776 additions and 4989 deletions

View File

@ -13,7 +13,7 @@
* [Design Engineering](/design-engineering)
* [Make It Move Without Wheels](/design-engineering/make-it-move)
* [Make It Smarter and Faster](/design-engineering/make-it-faster)
* [Make It Smarter and Faster](/design-engineering/make-it-smarter)
* [Make a System that Communicates](/design-engineering/make-it-communicate)
* [Maker](/maker)
@ -91,6 +91,45 @@
* [rate](/reference/sensors/gyro/rate)
* [reset](/reference/sensors/gyro/reset)
* [Ultrasonic](/reference/sensors/ultrasonic)
* [on event](/reference/sensors/ultrasonic/on-event),
* [distance](reference/sensors/ultrasonic/distance),
* [pause until](reference/sensors/ultrasonic/pause-until)
* [on event](/reference/sensors/ultrasonic/on-event)
* [distance](reference/sensors/ultrasonic/distance)
* [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)
* [Infrared beacon](/reference/sensors/beacon)
* [on event](/reference/sensors/beacon/on-event)
* [pause until](/reference/sensors/beacon/pause-until)
* [is pressed](/reference/sensors/beacon/is-pressed)
* [was pressed](/reference/sensors/beacon/was-pressed)
* [set remote channel](/reference/sensors/beacon/set-remote-channel)
* [Color](/reference/sensors/color-sensor)
* [on color detected](/reference/sensors/color-sensor/on-color-detected)
* [pause for color](/reference/sensors/color-sensor/pause-for-color)
* [on light changed](/reference/sensors/color-sensor/on-light-changed)
* [pause for light](/reference/sensors/color-sensor/pause-for-light)
* [color](/reference/sensors/color-sensor/color)
* [light](/reference/sensors/color-sensor/ambient-light)
* [Music](/reference/music)
* [play sound effect](/reference/music/play-sound-effect)
* [play sound effect until done](/reference/music/play-sound-effect-until-done)
* [play tone](/reference/music/play-tone)
* [ring tone](/reference/music/ring-tone)
* [stop all sounds](/reference/music/stop-all-sounds)
* [rest](/reference/music/rest)
* [change tempo by](/reference/music/change-tempo-by)
* [set tempo](/reference/music/set-tempo)
* [note frequency](/reference/music/note-frequency)
* [beat](/reference/music/beat)
* [set volume](/reference/music/set-volume)
* [Control](/reference/control)
* [Timer](/reference/control/timer)
* [seconds](/reference/control/timer/seconds)
* [millis](/reference/control/timer/millis)
* [reset](/reference/control/timer/reset)
* [pause until](/reference/control/timer/pause-until)
* [Console](/reference/console)
* [log](/reference/console/log)
* [log value](/reference/console/log-value)
* [send to screen](/reference/console/send-to-screen)

View File

@ -9,6 +9,7 @@
"name": "Autonomous Parking",
"description": "TBD",
"url":"/coding/autonomous-parking",
"imageUrl": "/static/lessons/parking.png",
"cardType": "side"
}, {
"name": "Object Detection",

View File

@ -7,22 +7,22 @@
{
"name": "Make It Move Without Wheels",
"description": "TBD",
"imageUrl": "/static/lessons/make-it-move.png",
"imageUrl": "/static/lessons/make-it-move-1.png",
"url": "/design-engineering/make-it-move",
"cardType": "side"
},
{
"name": "Make It Smarter and Faster",
"description": "TBD",
"imageUrl": "/static/lessons/make-it-smarter.png",
"url": "/design-engineering/make-it-move",
"imageUrl": "/static/lessons/make-it-smarter-1.png",
"url": "/design-engineering/make-it-smarter",
"cardType": "side"
},
{
"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"
}
]

View 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?
![EV3 + LEGO Bricks](/static/lessons/make-it-communicate/hero.png)
## 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 robots 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 robots 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?

View File

@ -0,0 +1,192 @@
# Make It Smarter and Faster
## Connect
### Design Brief
Design, build and program a robotic creature that can sense its environment and respond by moving.
https://www.youtube.com/watch?v=y9-A_C_08KY
* What do the robots in the video need to be able to sense, plan, and act?
* What senses do humans have and why are they important to us?
* How many human-like senses do you see the robots demonstrating?
### Brainstorm
Discuss different solutions to the design brief.
Think about:
* What kind of creature can it be?
* How can it move?
* What does it need to be aware so that it stays safe, well fed and warm (or cool)?
* Is it looking for food, a safe place to hide or a warm place to soak up the sun?
* Will the creature need to move fast or slow?
* Will it need to turn?
* Will it need to go backward?
![EV3 and bricks](/static/lessons/make-it-smarter/bricks.png)
## Construct
### Build
Think about a creatures movement for inspiration. Your mechanism can be attached or unattached to the EV3 brick. You can start by tinkering with the LEGO elements in the picture add 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)
* [Color Sensor 1](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/color%20sensor_v1-16a7231bdc187cd88a8da120c68f58d5.pdf)
* [Gyro Sensor](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/gyro%20sensor-6f0fdbd82ae45fe0effa0ebf3f460f3d.pdf)
* [Ultrasonic Sensor](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/ultrasonic%20sensor-a56156c72e8946ed4c58c5e69f3520d3.pdf)
* [Touch Sensor](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/touch%20sensor-868fda1b9d6070a0a034fb22456a7fc9.pdf)
* [Jaw](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/jaw-ee93e8f3243e4d30cd34b0c337c33653.pdf)
* [Leg 1](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/leg%201-c14624046ea3a95148820ed404f5ac65.pdf)
* [Leg 2](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/leg%202-8855c35b990205f6b9d7130687a3d4db.pdf)
* [Leg 3](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/leg%203-575d52ef15fb79f1e4d3350d36607160.pdf)
### Program
Before you program, think about:
* How will you program the robot to sense?
* How will you program the robot to respond?
* Which programming blocks will you use?
### ~ hint
**Hint:** Explore the different Sensor blocks in the Sensors Menu
### ~
## SCREEN 5
Sample Solution
[Video: EV3 Insect]
This Insect uses its Ultrasonic Sensor to sense danger and move away from threat.
The Insect solution combines these building ideas:
* EV3 Frames
* Leg 2
* Leg 3
* Ultrasonic Sensor
Four copies of Leg 3 were built: one for the front left, one for the back right, and two mirror copies for the front right and back left.
* [Building Instructions](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/insect-94b8a46f0dc5082c9d78ddb734626dc9.pdf)
### Sample Solution
This program checks if the Ultrasonic Sensor senses something near.
This program:
* Turns on the green EV3 brick Status Light
```block
brick.setStatusLight(StatusLight.Green)
```
* Waits for Ultrasonic Sensor to detect an object
```block
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectDetected)
```
* Turns on Motors A and D in opposite directions
```block
motors.largeAD.tank(50, -50)
```
* Waits for one half of a second (1500 milli seconds)
```block
pause(1500)
```
* Reverses the direction of Motors A and D
```block
motors.largeAD.tank(-50, 50)
```
* Waits for one half of a second
* Stops all motors
```block
motors.stopAll()
```
* Makes an insect chirping sound
```block
music.playSoundEffectUntilDone(sounds.animalsInsectChirp)
```
* Loops so the insect wanders around when the Ultrasonic Sensor is triggered
```blocks
forever(function () {
brick.setStatusLight(StatusLight.Green)
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectDetected)
motors.largeAD.tank(50, -50)
pause(1500)
motors.largeAD.tank(-50, 50)
pause(1500)
motors.stopAll()
music.playSoundEffectUntilDone(sounds.animalsInsectChirp)
})
```
### 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:
* Does your robot move when the sensor is activated?
* If not, what will you change to make the robots ability to sense and respond more obvious?
* What other behaviors can you add to the robot to make it more realistic?
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.
* Does your robot resemble a creature? Add arts and crafts materials to you project.
## Communicate
Here are some ideas:
* Create a video of your project, especially your final presentation and your robots 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?

View File

@ -1,3 +1,3 @@
{
"appref": "v"
"appref": "v0.0.104"
}

View File

@ -1,9 +1,16 @@
# Reference
```namespaces
brick.showMood(moods.sleeping);
sensors.color(null);
motors.stopAll();
brick.showMood(moods.sleeping);
```
## Advanced
```namespaces
console.log("");
control.runInParallel(function(){});
```
## See Also
@ -11,5 +18,5 @@ motors.stopAll();
[brick](/reference/brick),
[sensors](/reference/sensors),
[motors](/reference/motors),
[touch sensor](/reference/sensors/touch-sensor),
[color sensor](/reference/sensors/color-sensor)
[control](/reference/control),
[console](/reference/console)

15
docs/reference/console.md Normal file
View File

@ -0,0 +1,15 @@
# Console
Output text and data values to the console.
```cards
console.log("");
console.logValue("x", 0);
console.sendToScreen();
```
## See also
[log](/reference/console/log),
[log value](/reference/console/log-value),
[send to screen](/reference/console/send-to-screen)

View File

@ -0,0 +1,26 @@
# send To Screen
Direct the console output to go to the @boardname@ screen.
```sig
console.sendToScreen();
```
A "console" is a place for a user to see special messages from a device. It could be something connected to a serial port, a display that shows text, or even a text file. A console is typically used as a place to send information that is added to a message _log_ (a record of messages that are sent from a device). Your program can send log messages using the [console](/reference/console) functions. The MakeCode editor has a console view that lets you see the console output when your program runs in the simulator.
On the @boardname@, the screen can serve as a console too and you can make your console output go there. Before using the console log functions, set the screen as the console output location.
## Example
Direct the console output to go to the screen. Show 20 values on the screen. Use the up and down buttons to scroll through the values.
```blocks
console.sendToScreen()
for (let index = 0; index <= 20; index++) {
console.logValue("index", index)
}
```
## See also
[log](reference/console/log), [log value](/reference/console/log-value)

33
docs/reference/control.md Normal file
View File

@ -0,0 +1,33 @@
# Control
Program controls and events.
```cards
control.millis();
control.runInParallel(() => {
});
control.reset();
control.waitMicros(4);
control.deviceSerialNumber();
```
## Timer
```cards
control.timer1.reset()
control.timer1.pauseUntil(5)
control.timer1.millis()
control.timer1.seconds()
```
## Advanced #advanced
```cards
control.raiseEvent(0, 0);
control.onEvent(0, 0, () => {
});
control.assert(false, 0);
control.panic(0);
```

View File

@ -0,0 +1,8 @@
# Timer
```cards
control.timer1.reset()
control.timer1.pauseUntil(5)
control.timer1.millis()
control.timer1.seconds()
```

View File

@ -0,0 +1,25 @@
# millis
Get the amount of time counted by the timer in milliseconds.
The timer count begins from `0` when you program starts or is [reset](/reference/control/timer/reset).
## Returns
* a [number](/types/number) that is the amount of time elapsed, in milliseconds, since the timer was started or reset.
## Example
Find out how many milliseconds go by between presses of the `down` button on the brick.
```blocks
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
brick.showValue("DownButtonTime", control.timer1.millis(), 1)
control.timer1.reset()
})
```
## See also
[seconds](/reference/control/timer/seconds), [reset](/reference/control/timer/reset)

View File

@ -0,0 +1,32 @@
# pauseUntil
Pause until the timer counts up to a number of milliseconds.
```sig
control.timer1.pauseUntil(0)
```
When code in a block comes to a **pauseUntil**, it will wait until the timer count reaches the number of milliseconds you say. Code in blocks like **forever** and **runInParallel** will keep running while the current code is paused.
The time number you give is the number of milliseconds past the running timer count. If the timer is currently at `25000` milliseconds and you want to pause for `10` seconds, then use a pause time of `35000`. If you want your pause time number to match the actual wait time, then [reset](/reference/control/timer/reset) the timer first.
## Parameters
* **ms**: the [number](/types/number) of milliseconds that you want the timer to count up to. For seconds, convert to milliseconds: 100 milliseconds = 1/10 second and 1000 milliseconds = 1 second.
## Example
Pause between messages on the screen by `5` seconds.
```blocks
brick.clearScreen()
brick.showString("Testing my pause...", 1)
let startTime = control.timer1.millis()
brick.showValue("StartTime", startTime, 3)
control.timer1.pauseUntil(startTime + 5000)
brick.showValue("EndTime", control.timer1.millis() - startTime, 4)
```
## See also
[millis](/reference/control/timer/millis), [reset](/reference/control/timer/reset)

View File

@ -0,0 +1,49 @@
# reset
Reset the elapsed time of the timer back to `0`.
```sig
control.timer1.reset()
```
A timer starts counting from `0` when your program starts. It's time value always gets larger as your program runs. Maybe you want to meausure how long some task takes to finish or you want to do some action only for a little while. A timer can keep track of the time it takes to do it.
Resetting the timer sets the time value to `0` so the next time you check the time it's exactly the amount of time that has _elapsed_. Otherwise, you need to remember a start time value and then subtract it from the current time.
## Examples
### Press time
Find out how much time goes by between presses of the `enter` button on the brick.
```blocks
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
brick.showValue("PressTime", control.timer1.seconds(), 1)
control.timer1.reset()
})
```
### Difference timer
Use a difference timer and compare it to a timer that resets. Use the ``left`` button to start timing and the ``right`` button to stop.
```blocks
let startTime = 0
let timing = false
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
brick.clearScreen()
brick.showString("Starting timers...", 1)
startTime = control.timer1.seconds()
control.timer2.reset()
timing = true
})
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
if (timing) {
brick.clearScreen()
brick.showString("Timer results...", 1)
brick.showValue("timer 1", control.timer1.seconds() - startTime, 3)
brick.showValue("timer 2", control.timer2.seconds(), 4)
timing = false;
}
})
```

View File

@ -0,0 +1,25 @@
# seconds
Get the amount of time counted by the timer in seconds.
The timer count begins from `0` when you program starts or is [reset](/reference/control/timer/reset). The number of seconds returned also includes milliseconds if there is a fractional part of a second too.
## Returns
* a [number](/types/number) that is the amount of time elapsed, in seconds, since the timer was started or reset.
## Example
Find out how many seconds go by between presses of the `down` button on the brick.
```blocks
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
brick.showValue("DownButtonTime", control.timer1.seconds(), 1)
control.timer1.reset()
})
```
## See also
[millis](/reference/control/timer/millis), [reset](/reference/control/timer/reset)

View File

@ -26,7 +26,7 @@ motors.largeA.run(50, 500)
Here is how you use each different movement unit to run the motor for a fixed rotation distance.
```typescript
```blocks
// Run motor for 700 Milliseconds.
motors.largeA.run(25, 700, MoveUnit.MilliSeconds);

View File

@ -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 point 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

View File

@ -1,5 +1,17 @@
# Sensors
# Color
```cards
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {})
sensors.color1.onLightChanged(LightIntensityMode.Reflected, LightCondition.Dark, function () {})
sensors.color1.pauseForLight(LightIntensityMode.Reflected, LightCondition.Dark)
sensors.color1.pauseForColor(ColorSensorColor.Blue)
sensors.color1.color();
sensors.color1.light(LightIntensityMode.Ambient)
sensors.color(ColorSensorColor.Blue)
```
## Touch
```cards
@ -24,3 +36,22 @@ sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectDetected, function () {}
sensors.ultrasonic1.distance();
sensors.ultrasonic1.pauseUntil(UltrasonicSensorEvent.ObjectDetected);
```
## Infrared
```cards
sensors.infrared1.onEvent(null, function () {});
sensors.infrared1.pauseUntil(null);
sensors.infrared1.proximity();
```
## Infrared beacon button
```cards
sensors.remoteButtonCenter.onEvent(ButtonEvent.Pressed, function () {})
sensors.remoteButtonCenter.pauseUntil(ButtonEvent.Pressed);
sensors.remoteButtonCenter.isPressed()
sensors.remoteButtonCenter.wasPressed()
sensors.infrared1.setRemoteChannel(null)
```

142
docs/static/avatar.svg vendored
View File

@ -5,105 +5,53 @@
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 32 32"
style="enable-background:new 0 0 32 32;" xml:space="preserve">
<style type="text/css">
.st0{fill:#303030;}
.st0{fill:#DE0612;}
.st1{fill:#FFFFFF;stroke:#FFFFFF;stroke-width:0.4;stroke-miterlimit:10;}
</style>
<sodipodi:namedview bordercolor="#666666" borderopacity="1" gridtolerance="10" guidetolerance="10" id="namedview15" inkscape:current-layer="svg2" inkscape:cx="16" inkscape:cy="16" inkscape:pageopacity="0" inkscape:pageshadow="2" inkscape:window-height="661" inkscape:window-maximized="0" inkscape:window-width="997" inkscape:window-x="0" inkscape:window-y="0" inkscape:zoom="5.2149125" objecttolerance="10" pagecolor="#ffffff" showgrid="false">
</sodipodi:namedview>
<g id="avatar_mf" transform="translate(-5304.979 8145.745)">
<path id="Path_180" class="st0" d="M5317.1-8125.6c0.2,0,0.3-0.1,0.5-0.1l2.9-0.6c1.3-0.3,2.5-0.5,3.8-0.8c0.5-0.1,1-0.2,1.5-0.3
c0.1,0,0.1,0,0.1-0.1c0-0.5,0-1-0.1-1.5c-0.1-0.6-0.2-1.1-0.3-1.7c-0.1-0.4-0.1-0.8-0.2-1.2c-0.1-0.7-0.2-1.4-0.3-2
c-0.1-0.6-0.2-1.1-0.3-1.7c0-0.2-0.2-0.4-0.4-0.4c0,0,0,0-0.1,0c-0.2,0-0.5,0.1-0.7,0.1c-0.5,0.1-1,0.1-1.5,0.2
c-0.5,0.1-1,0.1-1.6,0.2c-0.5,0.1-1,0.1-1.4,0.2c-0.2,0-0.3,0-0.5,0.1c-0.2,0-0.4,0.2-0.5,0.4c0,0.2-0.1,0.4-0.1,0.5
c0,0.4-0.1,0.8-0.1,1.2c-0.1,0.5-0.1,1-0.2,1.5c0,0.4-0.1,0.9-0.1,1.3l-0.1,1.3l-0.1,1.3c-0.1,0.5-0.1,1-0.2,1.5
C5317.1-8126,5317.1-8125.8,5317.1-8125.6z"/>
<path id="Path_181" class="st0" d="M5316.1-8140c0,0.6,0.1,1.2,0.1,1.8c0,0.4,0.2,0.8,0.6,1c0.3,0.2,0.7,0.3,1.1,0.3
c0.7,0.1,1.4,0.1,2.1,0c0.6,0,1.2-0.1,1.8-0.2c0.4,0,0.9-0.2,1.2-0.5c0.3-0.3,0.5-0.7,0.5-1.1c0-1.2,0-2.3-0.1-3.5
c0-0.3-0.1-0.6-0.3-0.8c-0.3-0.4-0.8-0.6-1.4-0.6c0,0,0,0-0.1,0c-0.2,0.1-0.4,0.1-0.6,0.1c-0.9,0-1.8,0.1-2.7,0.1
c-0.1,0-0.3,0-0.4,0c-0.4-0.1-0.8,0-1.2,0.2c-0.4,0.2-0.6,0.6-0.7,1c0,0.1,0,0.2,0,0.3C5316-8141.2,5316.1-8140.6,5316.1-8140
L5316.1-8140z"/>
<path id="Path_182" class="st0" d="M5312-8129.2c0,0.6,0,1.2,0,1.8c0,0.1,0,0.1,0.1,0.1c0.3,0,0.6,0.1,0.9,0.1c0.3,0,0.7,0,1,0
c0.1,0,0.2,0,0.3,0c0.1,0,0.1,0,0.1-0.1c0.1-0.4,0.2-0.8,0.2-1.2c0.1-0.5,0.2-1,0.3-1.4c0-0.1,0.1-0.1,0.1-0.1
c0.4-0.2,0.8-0.5,1.2-0.8c0.4-0.4,0.7-0.9,0.8-1.5c0.1-0.6,0-1.2-0.4-1.7c-0.2-0.3-0.6-0.4-0.9-0.3c-0.3,0.1-0.6,0.3-0.9,0.5
c-0.7,0.6-1.5,1.2-2.2,1.8c-0.3,0.2-0.5,0.5-0.6,0.8c0,0.2-0.1,0.4-0.1,0.6C5311.9-8130.2,5311.9-8129.7,5312-8129.2
C5311.9-8129.2,5312-8129.2,5312-8129.2z"/>
<path id="Path_183" class="st0" d="M5315.5-8124.7c0,0.2-0.1,0.5-0.1,0.7c-0.1,0.5-0.4,0.9-0.8,1.1c0,0,0,0,0,0
c-0.1,0-0.2,0.2-0.2,0.3c-0.4,1.4-0.9,2.7-1.3,4.1c0,0,0,0.1,0,0.1c0.8,1.1,1.6,2.2,2.4,3.3c0,0,0,0,0.1,0.1
c0.1-0.2,0.1-0.3,0.2-0.5c0.1-0.3,0.2-0.5,0.3-0.8c0,0,0-0.1,0-0.1c-0.2-0.3-0.5-0.7-0.7-1c0,0,0-0.1,0-0.2
c0.3-0.9,0.6-1.7,0.9-2.6c0,0,0-0.1,0.1-0.1c0.5-0.2,0.9-0.6,1.1-1.1c0.1-0.3,0.1-0.7,0.1-1.1c0-0.4-0.1-0.8-0.3-1.2
c-0.2-0.4-0.5-0.8-1-1C5315.9-8124.7,5315.7-8124.7,5315.5-8124.7z"/>
<path id="Path_184" class="st0" d="M5314.7-8134.2c0.1-0.1,0.2-0.1,0.3-0.2c0.3-0.2,0.7-0.3,1-0.3c0.4,0,0.7,0.2,0.8,0.6
c0.6,1.1,0.5,2.4-0.4,3.3c-0.4,0.4-0.8,0.7-1.3,1c0,0-0.1,0.1-0.1,0.1c-0.2,0.8-0.3,1.6-0.5,2.5c0,0,0,0.1,0,0.1
c0,0.2,0,0.2-0.2,0.2c-0.1,0-0.1,0-0.2,0c0,0.1,0,0.2,0,0.3c0,0,0,0,0.1,0.1l1.9,0.7c0.2,0.1,0.4,0.2,0.7,0.2c0-0.1,0-0.2,0-0.2
c0-0.3,0-0.6,0-0.8l0.2-1.5l0.2-1.5c0.1-0.5,0.1-1,0.2-1.5c0.1-0.5,0.1-1.1,0.2-1.6c0.1-0.5,0.1-1,0.2-1.5c0-0.2,0-0.4,0-0.6
c0-0.2-0.1-0.4-0.3-0.4c0,0,0,0,0,0c-0.1,0-0.1,0-0.2,0c-0.6-0.1-1.2-0.2-1.9-0.3c-0.1,0-0.2,0-0.3,0c-0.1,0-0.2,0.1-0.3,0.3
C5314.8-8135,5314.7-8134.6,5314.7-8134.2z"/>
<path id="Path_185" class="st0" d="M5324.5-8117.2c-0.2-0.7-0.5-1.3-0.7-2l-0.7,0.3c0,0-0.1,0-0.1,0c-0.1,0.1-0.2,0-0.2-0.1
c-0.1-0.3-0.2-0.5-0.3-0.8c-0.2-0.7-0.5-1.4-0.7-2.1c0,0,0-0.1,0-0.1c0,0,0,0.1-0.1,0.1c-0.1,0.2-0.3,0.3-0.5,0.5c0,0-0.1,0-0.1,0
c-0.3,0.1-0.6,0.1-0.8,0.2c0,0-0.1,0-0.1,0c0,0.2-0.1,0.3-0.1,0.5c0.6,1.5,1.1,3.1,1.7,4.6c0,0,0,0,0,0.1
C5322.7-8116.3,5323.6-8116.7,5324.5-8117.2z"/>
<path id="Path_186" class="st0" d="M5325.4-8123.1c-0.7,0.2-1.3,0.3-2,0.5c-0.5,0.1-0.9,0.2-1.4,0.3c-0.1,0-0.2,0.1-0.1,0.2
c0,0,0,0,0,0.1c0.2,0.5,0.3,0.9,0.5,1.4c0.2,0.5,0.4,1.1,0.6,1.6c0,0,0,0,0,0c0.1-0.1,0.2-0.1,0.3-0.2c0.2-0.1,0.3-0.2,0.5-0.2
c0.2-0.1,0.4-0.1,0.6-0.2c0.7-0.2,1.5-0.4,2.2-0.6c0,0,0,0,0.1,0C5326.3-8121.1,5325.9-8122.1,5325.4-8123.1z"/>
<path id="Path_187" class="st0" d="M5320.7-8124.4c-0.4,0.1-0.8,0.2-1.2,0.3c-0.6,0.1-1.3,0.3-1.9,0.4c0,0-0.1,0-0.1,0
c-0.1,0-0.2-0.1-0.3-0.1c0,0,0,0.1,0,0.1c0.3,0.7,0.4,1.5,0.3,2.2c-0.1,0.4-0.3,0.8-0.5,1.1c0,0,0,0-0.1,0.1
c0.2-0.1,0.4-0.1,0.6-0.1l2.5-0.6c0.5-0.1,0.9-0.6,1-1.1c0.1-0.5,0-1-0.1-1.5C5320.8-8124,5320.8-8124.2,5320.7-8124.4z"/>
<path id="Path_188" class="st0" d="M5325.5-8127c-2.7,0.5-5.3,1.1-7.9,1.6c0,0.5,0,0.9,0.1,1.4c0.1,0,0.2,0,0.3-0.1
c1.2-0.3,2.3-0.5,3.5-0.8c1.2-0.3,2.4-0.5,3.6-0.8c0.1,0,0.3-0.1,0.4-0.1c0,0,0.1,0,0.1-0.1
C5325.6-8126.2,5325.5-8126.6,5325.5-8127z"/>
<path id="Path_189" class="st0" d="M5328.6-8118.4c-0.2-0.4-0.3-0.7-0.5-1.1c-0.1-0.2-0.2-0.5-0.3-0.7c0-0.1,0-0.1-0.1,0
c-1.2,0.3-2.4,0.6-3.6,1c0,0,0,0-0.1,0c0.2,0.7,0.5,1.3,0.7,2C5326-8117.6,5327.3-8118,5328.6-8118.4z"/>
<path id="Path_190" class="st0" d="M5319.9-8120.9l-0.6,0.1c-1,0.2-2,0.5-3,0.7c-0.1,0-0.1,0.1-0.1,0.1c-0.3,0.7-0.5,1.5-0.8,2.2
c0,0,0,0,0,0.1c0.2,0,0.4-0.1,0.5-0.1c1-0.3,2-0.5,3.1-0.8c0.1,0,0.2-0.1,0.3-0.2C5319.5-8119.5,5319.7-8120.2,5319.9-8120.9z"/>
<path id="Path_191" class="st0" d="M5325.1-8125.4c-1.1,0.2-2.2,0.5-3.3,0.7c0.3,0.7,0.4,1.4,0.3,2.2c0.2,0,0.4-0.1,0.5-0.1
c0.9-0.2,1.8-0.4,2.7-0.6c0.1,0,0.1,0,0.1-0.1c0.1-0.4,0-0.9-0.1-1.3C5325.3-8124.9,5325.2-8125.1,5325.1-8125.4
C5325.1-8125.3,5325.1-8125.4,5325.1-8125.4z"/>
<path id="Path_192" class="st0" d="M5325.6-8132c0.2,0,0.4,0,0.5,0c0.2,0,0.4,0,0.6,0c0.3,0,0.6-0.2,0.8-0.4c0.3-0.4,0.7-0.8,1-1.2
c-0.1-0.1-0.1-0.1-0.1-0.2c0,0,0,0-0.1,0c-0.7-0.1-1.3-0.5-1.4-1.2c-0.1-0.2-0.1-0.4-0.1-0.6c-0.2,0.1-0.3,0.3-0.5,0.4
c-0.1,0.1-0.2,0.1-0.3,0.2c0,0-0.1,0.1-0.2,0c-0.2,0-0.5-0.1-0.7-0.1c0,0,0,0-0.1,0C5325.3-8134.1,5325.4-8133.1,5325.6-8132z"/>
<path id="Path_193" class="st0" d="M5328.4-8134.2c0.2-0.3,0.5-0.5,0.8-0.7c0.4-0.4,0.6-0.8,0.7-1.4c0-0.1,0-0.2-0.1-0.3
c-0.3-0.5-0.7-1.1-1-1.6c0-0.1-0.1-0.1-0.1,0c-0.4,0.2-0.8,0.5-1.1,0.8c-0.2,0.2-0.4,0.4-0.6,0.6c-0.1,0.1-0.1,0.3,0,0.4
c0.5,0.7,1,1.5,1.4,2.2C5328.4-8134.2,5328.4-8134.2,5328.4-8134.2z"/>
<path id="Path_194" class="st0" d="M5314.3-8126.1c-0.1-0.1-0.1-0.1-0.2-0.2c-0.1,0-0.1-0.1-0.1-0.2c0-0.1,0-0.3,0-0.4h-0.1
c-0.6,0-1.2-0.1-1.7-0.2c0,0-0.1,0-0.1,0c-0.4,0.2-0.7,0.4-1,0.8c-0.4,0.6-0.4,1.4,0.1,1.9c0.2,0.2,0.4,0.4,0.6,0.6
c0.1,0.1,0.2,0.2,0.3,0.2c-0.2-0.6,0-1.3,0.5-1.8C5313-8125.9,5313.6-8126.2,5314.3-8126.1z"/>
<path id="Path_195" class="st0" d="M5315.7-8114.9c0.5-0.1,0.9-0.3,1.4-0.4c0.8-0.2,1.6-0.4,2.4-0.7c0.1,0,0.1,0,0.1-0.1
c0.1-0.4,0.2-0.7,0.4-1.1c0,0,0,0,0-0.1c-0.1,0-0.2,0-0.3,0.1c-1.2,0.3-2.3,0.6-3.5,1c-0.1,0-0.1,0.1-0.1,0.1
c-0.1,0.4-0.3,0.7-0.4,1.1C5315.7-8115,5315.7-8115,5315.7-8114.9z"/>
<path id="Path_196" class="st0" d="M5315.4-8117.4c0.2,0.3,0.4,0.6,0.6,0.9c0,0,0.1,0,0.1,0c1-0.3,1.9-0.5,2.9-0.8
c0.3-0.1,0.6-0.2,0.9-0.2c-0.1-0.1-0.1-0.2-0.2-0.2c-0.2-0.2-0.3-0.4-0.5-0.6c0,0-0.1-0.1-0.1,0c-0.9,0.3-1.9,0.5-2.8,0.8
C5316-8117.5,5315.7-8117.5,5315.4-8117.4z"/>
<path id="Path_197" class="st0" d="M5321.3-8143.6c0-0.3,0-0.7,0-1c0,0-0.1,0-0.1,0c-0.7,0-1.5,0-2.2,0.1c-0.4,0-0.7,0-1.1,0.1
c-0.1,0-0.1,0-0.1,0.1c0,0.3,0,0.6,0,0.8c0,0,0,0.1,0.1,0.1c0.4,0,0.8,0,1.1,0c0.5,0,1.1,0,1.6-0.1
C5320.9-8143.5,5321.1-8143.6,5321.3-8143.6z"/>
<path id="Path_198" class="st0" d="M5329.2-8134.3c0.1,0,0.2,0,0.2-0.1c0.4-0.2,0.8-0.4,1.1-0.7c0.3-0.2,0.4-0.5,0.6-0.8
c0.1-0.3,0.1-0.6-0.1-0.9c-0.4-0.5-0.7-1-1.1-1.6c0,0,0,0-0.1-0.1c-0.2,0.2-0.4,0.4-0.6,0.6c0,0,0,0,0,0c0,0,0,0.1,0,0.1
c0.2,0.4,0.5,0.7,0.7,1c0.1,0.2,0.2,0.4,0.1,0.6c0,0.5-0.1,0.9-0.4,1.3c-0.1,0.1-0.2,0.2-0.3,0.3
C5329.4-8134.5,5329.3-8134.4,5329.2-8134.3C5329.2-8134.3,5329.2-8134.3,5329.2-8134.3z"/>
<path id="Path_199" class="st0" d="M5317.5-8136.7c0,0.2,0,0.3,0,0.5c0,0,0,0.1,0.1,0.1c0.2,0,0.3,0.1,0.5,0.1c0.7,0.1,1.4,0.1,2,0
c0.4,0,0.8-0.1,1.2-0.1c0.2,0,0.5-0.1,0.7-0.1c0.1,0,0.1,0,0.1-0.1c0-0.2,0-0.3,0-0.5C5320.5-8136.6,5319-8136.5,5317.5-8136.7z"/>
<path id="Path_200" class="st0" d="M5312.5-8123.2c0.1-0.4,0.1-0.8,0.2-1.2c0.1-0.6,0.6-1,1.2-1c0.3,0,0.5,0.1,0.7,0.3
c0.2,0.2,0.2,0.4,0.2,0.7c-0.1,0.3-0.2,0.6-0.2,0.9c0,0.1-0.1,0.2-0.1,0.4c0,0,0,0,0,0c0.1-0.1,0.2-0.2,0.3-0.3
c0.3-0.4,0.4-0.9,0.4-1.4c0-0.6-0.4-1-0.9-1.1c-0.1,0-0.1,0-0.2,0c-0.5,0-1,0.3-1.4,0.7c-0.3,0.3-0.4,0.6-0.5,1
c-0.1,0.3,0,0.7,0.2,1C5312.5-8123.2,5312.5-8123.2,5312.5-8123.2z"/>
<path id="Path_201" class="st0" d="M5314.3-8123.2c0.1-0.5,0.3-0.9,0.4-1.4c0.1-0.2,0-0.4-0.2-0.5c-0.4-0.2-0.9-0.1-1.2,0.2
c0,0,0,0,0,0.1c0,0.2,0,0.4,0.1,0.6c0,0.1,0.1,0.2,0.2,0.3C5313.7-8123.6,5314-8123.4,5314.3-8123.2
C5314.2-8123.2,5314.3-8123.2,5314.3-8123.2z"/>
<path id="Path_202" class="st0" d="M5317.4-8124.1c0-0.4,0-0.9-0.1-1.3c-0.1,0-0.1,0-0.2,0c-0.1,0-0.2,0-0.3,0
c-0.7-0.3-1.4-0.5-2.1-0.8c0,0,0,0,0,0c0.1,0.1,0.1,0.1,0.2,0.2c0.3,0.2,0.5,0.6,0.6,0.9c0,0,0,0,0,0c0.1,0,0.3,0,0.4,0.1
c0.3,0.1,0.6,0.3,0.9,0.5c0,0,0.1,0.1,0.1,0.1C5317.1-8124.2,5317.2-8124.1,5317.4-8124.1z"/>
<path id="Path_203" class="st0" d="M5321.6-8124.6c-0.2,0-0.4,0.1-0.6,0.1c0.1,0.2,0.1,0.4,0.2,0.6c0.1,0.4,0.2,0.8,0.1,1.2
c0,0.5-0.1,0.9-0.4,1.3c0,0,0,0,0,0c0.3,0,0.6-0.2,0.7-0.5c0.2-0.3,0.3-0.6,0.3-0.9C5321.9-8123.4,5321.8-8124,5321.6-8124.6z"/>
<path id="Path_204" class="st0" d="M5315.7-8135.8c0.2,0,0.3,0.1,0.5,0.1c0.5,0.1,1,0.2,1.5,0.2c0.2,0,0.5,0,0.7,0
c0.7-0.1,1.4-0.2,2.1-0.2c0.6-0.1,1.2-0.2,1.8-0.2c0.5-0.1,1.1-0.1,1.6-0.2l-1.5-0.2c0,0,0,0,0,0c0,0.2-0.1,0.3-0.2,0.3
c0,0,0,0,0,0c-0.3,0.1-0.5,0.1-0.8,0.2c-0.8,0.1-1.6,0.1-2.3,0.1c-0.4,0-0.9,0-1.3-0.1c-0.1,0-0.2-0.1-0.3-0.2c0,0-0.1,0-0.1,0
c-0.3,0-0.6,0.1-0.9,0.1L5315.7-8135.8L5315.7-8135.8z"/>
<path id="Path_205" class="st0" d="M5327.3-8117.7c-0.3,0.1-0.5,0.2-0.8,0.2c-0.6,0.2-1.1,0.3-1.7,0.5c0,0-0.1,0-0.1,0.1
c-0.5,0.2-1,0.5-1.5,0.7c0,0,0,0,0,0c0.3-0.1,0.5-0.1,0.8-0.2c0.5-0.2,1.1-0.3,1.6-0.5c0.1,0,0.2-0.1,0.2-0.1
C5326.2-8117.2,5326.8-8117.5,5327.3-8117.7C5327.3-8117.7,5327.3-8117.7,5327.3-8117.7C5327.3-8117.7,5327.3-8117.7,5327.3-8117.7
z"/>
<path id="Path_206" class="st0" d="M5327-8135.8c0,0.1,0,0.2,0,0.4c0.1,0.5,0.3,0.9,0.7,1.1c0.1,0.1,0.3,0.1,0.4,0.2l0,0
C5327.8-8134.7,5327.4-8135.2,5327-8135.8L5327-8135.8z"/>
<path id="Path_207" class="st0" d="M5329-8134.4c-0.1,0.1-0.2,0.2-0.3,0.4c0,0,0,0,0,0.1c0,0.1,0,0.1,0.1,0.1c0.1,0,0.2,0,0.3-0.1
c0.1,0,0.2-0.1,0.3-0.1c-0.1,0-0.1-0.1-0.2-0.1C5329-8134.2,5329-8134.3,5329-8134.4z"/>
<g>
<polygon class="st0" points="2,9.9 5.8,8.2 5.8,8 6.2,7.4 6.9,6.9 8,6.6 9.1,6.5 9.5,6.6 13.1,5 13.1,4.8 13.4,4.3 14,3.9
14.9,3.6 16,3.5 17.1,3.6 18,3.9 18.6,4.3 18.9,4.8 18.9,5 22.4,6.6 23,6.6 24,6.7 25,7 25.8,7.5 26.2,8 26.2,8.3 29.9,10
28.8,19.3 15.9,28.5 3.1,19.2 "/>
<g>
<path class="st1" d="M15.9,28.6C15.9,28.6,15.9,28.6,15.9,28.6L15.9,28.6C15.9,28.6,15.9,28.6,15.9,28.6
C15.9,28.6,15.9,28.6,15.9,28.6L15.9,28.6C15.9,28.6,15.9,28.6,15.9,28.6L15.9,28.6C15.9,28.6,15.9,28.6,15.9,28.6L15.9,28.6
C15.9,28.6,15.9,28.6,15.9,28.6L15.9,28.6C15.9,28.6,15.9,28.6,15.9,28.6C15.9,28.6,15.9,28.6,15.9,28.6
C15.9,28.6,15.9,28.6,15.9,28.6C15.9,28.6,15.9,28.6,15.9,28.6L3.1,19.3c0,0,0,0,0,0L2,9.9c0,0,0,0,0,0c0,0,0,0,0,0l0,0
c0,0,0,0,0,0c0,0,0,0,0,0c0,0,0,0,0,0l0,0c0,0,0,0,0,0v0c0,0,0,0,0,0c0,0,0,0,0,0c0,0,0,0,0,0h0c0,0,0,0,0,0c0,0,0,0,0,0
c0,0,0,0,0,0l3.8-1.7l0-0.1l0-0.1c0,0,0,0,0,0l0.4-0.6c0,0,0,0,0,0l0.7-0.5c0,0,0,0,0,0l1-0.3c0,0,0,0,0,0l1.2-0.1c0,0,0,0,0,0
l0.4,0l3.6-1.6l0-0.1c0,0,0,0,0,0c0,0,0,0,0,0l0,0l0.2-0.5c0,0,0,0,0,0L14,3.8c0,0,0,0,0,0l0.9-0.3c0,0,0,0,0,0L16,3.4
c0,0,0,0,0,0l1.1,0.1c0,0,0,0,0,0L18,3.8c0,0,0,0,0,0l0.6,0.4c0,0,0,0,0,0l0.3,0.5c0,0,0,0,0,0v0c0,0,0,0,0,0l0,0.2l3.6,1.6l0.4,0
c0,0,0,0,0,0L24,6.6c0,0,0,0,0,0l1,0.3c0,0,0,0,0,0l0.8,0.5c0,0,0,0,0,0L26.2,8c0,0,0,0,0,0c0,0,0,0,0,0l0,0.2L30,9.9c0,0,0,0,0,0
l0,0c0,0,0,0,0,0l0,0c0,0,0,0,0,0c0,0,0,0,0,0c0,0,0,0,0,0c0,0,0,0,0,0l0,0c0,0,0,0,0,0c0,0,0,0,0,0c0,0,0,0,0,0c0,0,0,0,0,0
c0,0,0,0,0,0c0,0,0,0,0,0c0,0,0,0,0,0c0,0,0,0,0,0l-1.2,9.3c0,0,0,0,0,0L15.9,28.6C15.9,28.6,15.9,28.6,15.9,28.6
C15.9,28.6,15.9,28.6,15.9,28.6L15.9,28.6C15.9,28.6,15.9,28.6,15.9,28.6z M16,18.5L16,28.4l12.8-9.1l1.2-9.2L16,18.5z M3.2,19.2
l12.7,9.2l0.1-9.9L2.1,10L3.2,19.2z M2.1,9.9L16,18.4L29.9,10l-3.6-1.6L26.1,10L26,10.6c0,0,0,0,0,0l-0.6,0.5c0,0,0,0,0,0
l-0.9,0.4c0,0,0,0,0,0l-1.2,0.1c0,0,0,0,0,0L22,11.5c0,0,0,0,0,0l-1.1-0.4c0,0,0,0,0,0l-0.7-0.5c0,0,0,0,0,0L19.9,10c0,0,0,0,0,0
L20,8c0,0,0,0,0,0v0c0,0,0,0,0,0s0,0,0,0v0c0,0,0,0,0,0l0.2-0.6c0,0,0,0,0,0l0.6-0.5c0,0,0,0,0,0l0.9-0.3c0,0,0,0,0,0l0.5-0.1
l-3.3-1.5l0,1.5c0,0,0,0,0,0l-0.2,0.5c0,0,0,0,0,0l-0.6,0.4c0,0,0,0,0,0l-0.9,0.3c0,0,0,0,0,0L16,8c0,0,0,0,0,0l-1.1-0.1
c0,0,0,0,0,0l-0.9-0.3c0,0,0,0,0,0l-0.6-0.5c0,0,0,0,0,0l-0.2-0.5c0,0,0,0,0,0l0-1.5L9.7,6.5l0.5,0.1c0,0,0,0,0,0l0.9,0.3
c0,0,0,0,0,0l0,0c0,0,0,0,0,0l0.6,0.5c0,0,0,0,0,0L12,8c0,0,0,0,0,0l0.1,1.9c0,0,0,0,0,0l-0.3,0.5l0,0.1c0,0,0,0,0,0L11,11.1
c0,0,0,0,0,0L10,11.5c0,0,0,0,0,0l-1.2,0.1c0,0,0,0,0,0l-1.2-0.1c0,0,0,0,0,0l-0.9-0.4c0,0,0,0,0,0L6,10.5c0,0,0,0,0,0L5.9,9.9
L5.8,8.3L2.1,9.9z M22,11.4l1.2,0.1l1.2-0.1l0.9-0.3l0.5-0.5L26,9.9l0.1-1.2L26,8.8l-0.1,0.1l-0.3,0.3c0,0,0,0,0,0l-1,0.3
c0,0,0,0,0,0l-1.2,0.1c0,0,0,0,0,0l-1.2-0.1c0,0,0,0,0,0L21,9.2c0,0,0,0,0,0l-0.7-0.5c0,0,0,0,0,0l-0.2-0.4L20,9.9l0.3,0.6L21,11
L22,11.4z M7.6,11.3l1.2,0.1l1.2-0.1l1-0.3l0.7-0.5l0,0L12,9.9l-0.1-1.7l-0.2,0.4c0,0,0,0,0,0L11,9.2c0,0,0,0,0,0L9.9,9.5
c0,0,0,0,0,0L8.7,9.6c0,0,0,0,0,0L7.4,9.5c0,0,0,0,0,0l-1-0.4c0,0,0,0,0,0L5.9,8.7L6,9.9l0.1,0.6L6.7,11L7.6,11.3z M22.1,9.4
l1.2,0.1l1.2-0.1l1-0.3l0.3-0.3l0.1-0.1L26,8.6l0.1-0.5l0,0l-0.3-0.5L25,7l-1-0.3l-1.2-0.1l-0.4,0l-0.7,0.1L20.8,7l-0.6,0.5
L20.1,8l0.3,0.5l0.7,0.5L22.1,9.4z M7.4,9.4l1.2,0.1l1.2-0.1l1.1-0.3l0.7-0.5L11.9,8l-0.2-0.5L11.1,7l-0.9-0.3L9.5,6.6
c0,0,0,0,0,0l-0.4,0l0,0L8,6.7L6.9,7L6.2,7.4L5.9,8l0,0c0,0,0,0,0,0L6,8.5L6.5,9L7.4,9.4z M14.9,7.8L16,7.9l1.1-0.1l0.1,0L18,7.5
l0.6-0.4l0.2-0.5l0-1.4l-0.1,0.2c0,0,0,0,0,0l-0.6,0.4c0,0,0,0,0,0l-0.9,0.3c0,0,0,0,0,0L16,6.2c0,0,0,0,0,0l-1.1-0.1c0,0,0,0,0,0
l-0.9-0.3c0,0,0,0,0,0l-0.6-0.4c0,0,0,0,0,0l-0.1-0.2l0,1.5l0.2,0.5L14,7.5L14.9,7.8z M14.9,5.9L16,6.1L17.1,6L18,5.7l0.6-0.4
l0.2-0.5l-0.2-0.5L18,3.9L17,3.6L16,3.6l-1.1,0.1L14,3.9l-0.6,0.4l-0.2,0.5l0.2,0.5L14,5.7L14.9,5.9z M16,15.8
C16,15.8,16,15.8,16,15.8l-1.3-0.2c0,0,0,0,0,0l-1.1-0.4c0,0,0,0,0,0l-0.7-0.6c0,0,0,0,0,0l-0.2-0.7c0,0,0,0,0,0l0-2l0,0
c0,0,0,0,0,0l0.3-0.7c0,0,0,0,0,0l0.7-0.6c0,0,0,0,0,0l1.1-0.4c0,0,0,0,0,0L16,10c0,0,0,0,0,0l1.3,0.1c0,0,0,0,0,0l1.1,0.4
c0,0,0,0,0,0l0.7,0.6c0,0,0,0,0,0l0.3,0.7c0,0,0,0,0,0l0,0l-0.1,2c0,0,0,0,0,0l-0.2,0.7c0,0,0,0,0,0l-0.7,0.6c0,0,0,0,0,0
l-1.1,0.4c0,0,0,0,0,0L16,15.8C16,15.8,16,15.8,16,15.8z M14.7,15.5l1.3,0.1l1.3-0.1l1.1-0.4l0.7-0.6l0.2-0.7v0l0-1.5l-0.1,0.2
c0,0,0,0,0,0l-0.7,0.6c0,0,0,0,0,0l-1.1,0.4c0,0,0,0,0,0L16,13.7c0,0,0,0,0,0l-1.3-0.1c0,0,0,0,0,0l-1.1-0.4c0,0,0,0,0,0l-0.7-0.6
c0,0,0,0,0,0l-0.1-0.3l0,1.5l0.2,0.7l0.7,0.6L14.7,15.5z M14.7,13.5l1.3,0.1l1.3-0.1l1.1-0.4l0.7-0.6l0.1-0.3l0,0c0,0,0,0,0,0
l0-0.1l0,0c0,0,0,0,0,0l0,0l0-0.1L19,11.2l-0.7-0.5l-1.1-0.4L16,10.2l-1.2,0.1l-1.1,0.4L13,11.2l-0.3,0.6l0,0c0,0,0,0,0,0l0.2,0.7
l0.7,0.6L14.7,13.5z"/>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

@ -1,8 +1,8 @@
@font-face {
font-family: "iconfont";
src: url("iconfont.eot?8b7e57577c2d1f1ae9e810b9e010bc84?#iefix") format("embedded-opentype"),
url("iconfont.woff2?8b7e57577c2d1f1ae9e810b9e010bc84") format("woff2"),
url("iconfont.woff?8b7e57577c2d1f1ae9e810b9e010bc84") format("woff");
src: url("iconfont.eot?92b07c6c5392088e45983d845234d068?#iefix") format("embedded-opentype"),
url("iconfont.woff2?92b07c6c5392088e45983d845234d068") format("woff2"),
url("iconfont.woff?92b07c6c5392088e45983d845234d068") format("woff");
}
.icon {
@ -91,3 +91,6 @@ url("iconfont.woff?8b7e57577c2d1f1ae9e810b9e010bc84") format("woff");
.icon-blocks:before {
content: "\f119";
}
.icon-search:before {
content: "\f11a";
}

Binary file not shown.

View File

@ -82,6 +82,9 @@
<glyph glyph-name="blocks"
unicode="&#xF119;"
horiz-adv-x="40" d=" M10.9 23H39V16.9H10.9V23z M39.2 27.1L39.2 33L0.9 33L0.9 31.1L0.9 27.1L0.9 12.9L0.9 7L39.2 7L39.2 12.9L6.9 12.9L6.9 27.1z" />
<glyph glyph-name="search"
unicode="&#xF11A;"
horiz-adv-x="40" d=" M38.6 4.9L29.6 13.9C31.5 16.5 32.7 19.7 32.7 23.1C32.7 31.8 25.7 38.8 17 38.8C8.3 38.8 1.4 31.8 1.4 23.1C1.4 14.4 8.3 7.5 17 7.5C20.3 7.5 23.3 8.5 25.9 10.3L35 1.2L38.6 4.9zM17 12.7C11.3 12.7 6.6 17.4 6.6 23.1S11.3 33.6 17 33.6S27.5 28.9 27.5 23.1S22.8 12.7 17 12.7z" />
</font>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 592 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

BIN
docs/static/lessons/make-it-move-1.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
docs/static/lessons/make-it-move-2.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
docs/static/lessons/make-it-move-3.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 357 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 413 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

BIN
docs/static/lessons/parking.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
docs/static/lessons/sound-machine.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 236 KiB

After

Width:  |  Height:  |  Size: 48 KiB

View File

@ -7,6 +7,7 @@ import { FieldImages } from "./field_images";
import { FieldSpeed } from "./field_speed";
import { FieldBrickButtons } from "./field_brickbuttons";
import { FieldTurnRatio } from "./field_turnratio";
import { FieldColorEnum } from "./field_color";
pxt.editor.initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): Promise<pxt.editor.ExtensionResult> {
pxt.debug('loading pxt-ev3 target extensions...')
@ -27,6 +28,9 @@ pxt.editor.initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): P
}, {
selector: "turnratio",
editor: FieldTurnRatio
}, {
selector: "colorenum",
editor: FieldColorEnum
}],
deployCoreAsync,
showUploadInstructionsAsync: (fn: string, url: string, confirmAsync: (options: any) => Promise<number>) => {

71
editor/field_color.ts Normal file
View File

@ -0,0 +1,71 @@
/// <reference path="../node_modules/pxt-core/localtypings/blockly.d.ts"/>
/// <reference path="../node_modules/pxt-core/built/pxtsim.d.ts"/>
export interface FieldColorEnumOptions extends pxtblockly.FieldColourNumberOptions {
}
export class FieldColorEnum extends pxtblockly.FieldColorNumber implements Blockly.FieldCustom {
public isFieldCustom_ = true;
constructor(text: string, params: FieldColorEnumOptions, opt_validator?: Function) {
super(text, params, opt_validator);
}
mapColour(enumString: string) {
switch(enumString) {
case '#000000': return 'ColorSensorColor.Black';
case '#006db3': return 'ColorSensorColor.Blue';
case '#00934b': return 'ColorSensorColor.Green';
case '#ffd01b': return 'ColorSensorColor.Yellow';
case '#f12a21': return 'ColorSensorColor.Red';
case '#ffffff': return 'ColorSensorColor.White';
case '#6c2d00': return 'ColorSensorColor.Brown';
default: return 'ColorSensorColor.None';
}
}
mapEnum(colorString: string) {
console.log(colorString);
switch(colorString) {
case 'ColorSensorColor.Black': return '#000000';
case 'ColorSensorColor.Blue': return '#006db3';
case 'ColorSensorColor.Green': return '#00934b';
case 'ColorSensorColor.Yellow': return '#ffd01b';
case 'ColorSensorColor.Red': return '#f12a21';
case 'ColorSensorColor.White': return '#ffffff';
case 'ColorSensorColor.Brown': return '#6c2d00';
case 'ColorSensorColor.None': return '#dfe6e9'; // Grey
default: return colorString;
}
}
/**
* Return the current colour.
* @param {boolean} opt_asHex optional field if the returned value should be a hex
* @return {string} Current colour in '#rrggbb' format.
*/
getValue(opt_asHex?: boolean) {
var colour = this.mapColour(this.colour_);
if (!opt_asHex && colour.indexOf('#') > -1) {
return `0x${colour.replace(/^#/, '')}`;
}
return colour;
}
/**
* Set the colour.
* @param {string} colour The new colour in '#rrggbb' format.
*/
setValue(colorStr: string) {
var colour = this.mapEnum(colorStr);
if (this.sourceBlock_ && Blockly.Events.isEnabled() &&
this.colour_ != colour) {
Blockly.Events.fire(new (Blockly as any).Events.BlockChange(
this.sourceBlock_, 'field', this.name, this.colour_, colour));
}
this.colour_ = colour;
if (this.sourceBlock_) {
this.sourceBlock_.setColour(colour, colour, colour);
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -19,28 +19,28 @@ enum LightIntensityMode {
}
const enum ColorSensorColor {
//% block="none" jres=colors.none
//% block="none" blockIdentity=sensors.__colorEnumPicker
None,
//% block="black" jres=colors.black
//% block="black" blockIdentity=sensors.__colorEnumPicker
Black,
//% block="blue" jres=colors.blue
//% block="blue" blockIdentity=sensors.__colorEnumPicker
Blue,
//% block="green" jres=colors.green
//% block="green" blockIdentity=sensors.__colorEnumPicker
Green,
//% block="yellow" jres=colors.yellow
//% block="yellow" blockIdentity=sensors.__colorEnumPicker
Yellow,
//% block="red" jres=colors.red
//% block="red" blockIdentity=sensors.__colorEnumPicker
Red,
//% block="white" jres=colors.white
//% block="white" blockIdentity=sensors.__colorEnumPicker
White,
//% block="brown" jres=colors.brown
//% block="brown" blockIdentity=sensors.__colorEnumPicker
Brown
}
enum LightCondition {
//% block="dark"
Dark = sensors.ThresholdState.Low,
//$ block="bright"
//% block="bright"
Bright = sensors.ThresholdState.High
}
@ -110,19 +110,14 @@ namespace sensors {
* @param handler the code to run when detected
*/
//% help=sensors/color-sensor/on-color-detected
//% block="on %sensor|detected color %color"
//% block="on **color** %this|detected color %color=colorEnumPicker"
//% blockId=colorOnColorDetected
//% parts="colorsensor"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% weight=100 blockGap=12
//% group="Color Sensor"
//% color.fieldEditor="gridpicker"
//% color.fieldOptions.columns=4
//% color.fieldOptions.tooltips=true
//% color.fieldOptions.hideRect=true
//% color.fieldOptions.width=268
onColorDetected(color: ColorSensorColor, handler: () => void) {
onColorDetected(color: number, handler: () => void) {
this.setMode(ColorSensorMode.Color)
const v = this._colorEventValue(<number>color);
control.onEvent(this._id, v, handler);
@ -135,19 +130,14 @@ namespace sensors {
* @param color the color to detect
*/
//% help=sensors/color-sensor/pause-for-color
//% block="pause %sensor|for color %color"
//% block="pause **color** %this|for color %color=colorEnumPicker"
//% blockId=colorPauseForColorDetected
//% parts="colorsensor"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% weight=99 blockGap=8
//% group="Color Sensor"
//% color.fieldEditor="gridpicker"
//% color.fieldOptions.columns=4
//% color.fieldOptions.tooltips=true
//% color.fieldOptions.hideRect=true
//% color.fieldOptions.width=268
pauseForColor(color: ColorSensorColor) {
pauseForColor(color: number) {
this.setMode(ColorSensorMode.Color);
if (this.color() != color) {
const v = this._colorEventValue(<number>color);
@ -160,11 +150,11 @@ namespace sensors {
* @param sensor the color sensor to query the request
*/
//% help=sensors/color-sensor/color
//% block="%sensor| color"
//% block="**color** %this| color"
//% blockId=colorGetColor
//% parts="colorsensor"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% weight=98
//% group="Color Sensor"
//% blockGap=8
@ -179,11 +169,11 @@ namespace sensors {
* @param handler the code to run when detected
*/
//% help=sensors/color-sensor/on-light-changed
//% block="on %sensor|%mode|%condition"
//% block="on **color** %this|%mode|%condition"
//% blockId=colorOnLightChanged
//% parts="colorsensor"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% weight=89 blockGap=12
//% group="Color Sensor"
onLightChanged(mode: LightIntensityMode, condition: LightCondition, handler: () => void) {
@ -192,15 +182,15 @@ namespace sensors {
}
/**
* Waits for the given color to be detected
* Wait for the given color to be detected
* @param color the color to detect
*/
//% help=sensors/color-sensor/pause-for-light
//% block="pause %sensor|for %mode|%condition"
//% block="pause **color** %this|for %mode|%condition"
//% blockId=colorPauseForLight
//% parts="colorsensor"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% weight=88 blockGap=8
//% group="Color Sensor"
pauseForLight(mode: LightIntensityMode, condition: LightCondition) {
@ -210,15 +200,15 @@ namespace sensors {
}
/**
* Measures the ambient or reflected light value from 0 (darkest) to 100 (brightest).
* Measure the ambient or reflected light value from 0 (darkest) to 100 (brightest).
* @param sensor the color sensor port
*/
//% help=sensors/color-sensor/light
//% block="%sensor|%mode"
//% block="**color** %this|%mode"
//% blockId=colorLight
//% parts="colorsensor"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% weight=87
//% group="Color Sensor"
light(mode: LightIntensityMode) {
@ -237,14 +227,15 @@ namespace sensors {
}
/**
* Sets a threshold value
* Set a threshold value
* @param condition the dark or bright light condition
* @param value the value threshold
*/
//% blockId=colorSetThreshold block="set %sensor|%condition|to %value"
//% blockId=colorSetThreshold block="set **color** %this|%condition|to %value"
//% group="Threshold" blockGap=8 weight=90
//% value.min=0 value.max=100
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% help=sensors/color-sensor/set-threshold
setThreshold(condition: LightCondition, value: number) {
if (condition == LightCondition.Dark)
this.thresholdDetector.setLowThreshold(value)
@ -253,12 +244,13 @@ namespace sensors {
}
/**
* Gets the threshold value
* Get a threshold value
* @param condition the light condition
*/
//% blockId=colorGetThreshold block="%sensor|%condition"
//% blockId=colorGetThreshold block="**color** %this|%condition"
//% group="Threshold" blockGap=8 weight=89
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% help=sensors/color-sensor/threshold
threshold(condition: LightCondition): number {
return this.thresholdDetector.threshold(<ThresholdState><number>LightCondition.Dark);
}
@ -266,9 +258,10 @@ namespace sensors {
/**
* Collects measurement of the light condition and adjusts the threshold to 10% / 90%.
*/
//% blockId=colorCalibrateLight block="calibrate|%sensor|for %mode|light"
//% blockId=colorCalibrateLight block="calibrate **color** %this|for %mode"
//% group="Threshold" weight=91 blockGap=8
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% help=sensors/color-sensor/calibrate-light
calibrateLight(mode: LightIntensityMode, deviation: number = 8) {
this.calibrating = true; // prevent events
@ -313,24 +306,26 @@ namespace sensors {
/**
* Returns a color that the sensor can detect
* @param color the color sensed by the sensor, eg: ColorSensorColor.Red
*/
//% shim=TD_ID
//% blockId=colorSensorColor block="color %color"
//% blockId=colorSensorColor block="color %color=colorEnumPicker"
//% group="Color Sensor"
//% weight=97
export function color(color: ColorSensorColor): ColorSensorColor {
//% help=sensors/color
export function color(color: number): ColorSensorColor {
return color;
}
//% whenUsed block="color 3" weight=95 fixedInstance jres=icons.port3
//% whenUsed block="3" weight=95 fixedInstance jres=icons.port3
export const color3: ColorSensor = new ColorSensor(3)
//% whenUsed block="color 1" weight=90 fixedInstance jres=icons.port1
//% whenUsed block="1" weight=90 fixedInstance jres=icons.port1
export const color1: ColorSensor = new ColorSensor(1)
//% whenUsed block="color 2" weight=90 fixedInstance jres=icons.port2
//% whenUsed block="2" weight=90 fixedInstance jres=icons.port2
export const color2: ColorSensor = new ColorSensor(2)
//% whenUsed block="color 4" weight=90 fixedInstance jres=icons.port4
//% whenUsed block="4" weight=90 fixedInstance jres=icons.port4
export const color4: ColorSensor = new ColorSensor(4)
}

View File

@ -1,16 +1,19 @@
# Color Sensor
# Color sensor
```cards
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {
})
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {})
sensors.color1.onLightChanged(LightIntensityMode.Reflected, LightCondition.Dark, function () {})
sensors.color1.pauseForLight(LightIntensityMode.Reflected, LightCondition.Dark)
sensors.color1.pauseForColor(ColorSensorColor.Blue)
sensors.color1.color();
sensors.color1.ambientLight();
sensors.color1.reflectedLight();
sensors.color1.light(LightIntensityMode.Ambient)
```
## See Also
## See slso
[on color detected](/reference/sensors/color-sensor/on-color-detected),
[pause for color](/reference/sensors/color-sensor/pause-for-color),
[on light changed](/reference/sensors/color-sensor/on-light-changed),
[pause for light](/reference/sensors/color-sensor/pause-for-light),
[color](/reference/sensors/color-sensor/color),
[ambient light](/reference/sensors/color-sensor/ambient-light),
[reflected light](/reference/sensors/color-sensor/reflected-light),
[light](/reference/sensors/color-sensor/ambient-light)

View File

@ -1,4 +1,20 @@
# Ambient Light
# ambient Light
Get the amount of ambient light dectected.
```sig
sensors.color1.ambientLight()
```
The amount of ambient light measured is in the range of `0` (darkest) to `100` (brightest).
## Returns
* a [number](/types/number) that is the amount of ambiernt light measured. No light (darkness) is `0` and the brightest light is `100`.
## Example
Make the status light show ``green`` if the ambient light is greater than `20`.
```blocks
forever(function () {
@ -8,4 +24,8 @@ forever(function () {
brick.setStatusLight(StatusLight.Orange)
}
})
```
```
## See also
[reflected light](/reference/sensors/color-sensor/reflected-light)

View File

@ -0,0 +1,26 @@
# calibrate Light
Calibrate the thresholds for dark and bright in current lighting conditions.
```sig
sensors.color1.calibrateLight(LightIntensityMode.Ambient, 0)
```
Sometimes when external lighting conditions change, the light sensor measures light intensty differently than when its thresholds were set before. You can calibrate the light sensor to adjust the thresholds slightly for current conditions. This is so that both the ``dark`` and ``bright`` threshold conditions happen with a similar amount of light to what you set the thresholds before.
## Parameters
* **mode**: the type of light threshold to calibrate. This is either ``ambient`` or ``reflected`` light.
* **deviation**: a [number](/types/number) that is the amount of light level change to adjust in a measurement.
## Example
Calibrate the ``dark`` and ``light`` thresholds for the ``color 2`` sensor using reflected light.
```blocks
sensors.color2.calibrateLight(LightIntensityMode.Reflected)
```
## See also
[set threshold](/reference/sensors/color-sensor/set-threshold)

View File

@ -1,5 +1,29 @@
# color
Get the current color detected by the sensor.
```sig
sensors.color1.color()
```
The [color](/reference/sensors/color) value returned is one of the colors that the sensor can detect. If you want to use colors for tracking, it's best to use a color that is the same or very close to the ones the sensor detects.
## Returns
* a color value for the current color detected by the color sensor. The colors detected are:
>* ``none``: no color is detected.
>* ``blue``
>* ``green``
>* ``yellow``
>* ``red``
>* ``white``
>* ``brown``
## Example
Turn the status light to ``green`` if the color detected by the ``color 1`` sensor is green.
```blocks
forever(function () {
if (sensors.color1.color() == ColorSensorColor.Green) {
@ -8,4 +32,8 @@ forever(function () {
brick.setStatusLight(StatusLight.Orange)
}
})
```
```
## See also
[color](/reference/sensors/color-sensor/color)

View File

@ -0,0 +1,35 @@
# light
Get the amount of ambient or reflected light measured by the sensor.
```sig
sensors.color1.light(LightIntensityMode.Ambient)
```
The light sensor adjusts itself to more accurately measure light depending on the source of the light. You decide if you want to measure _ambient_ light (light all around or direct light) or if you want to know how much light is reflected from a surface. The amount of light measured is in the range of `0` (darkest) to `100` (brightest).
## Parameters
* **mode**: the type of measurement for light. This is either ``ambient`` or ``reflected`` light.
## Returns
* a number that is the amount of light measured. No light (darkness) is `0` and the brightest light is `100`.
## Example
Make the status light show ``green`` if the ambient light is greater than `20`.
```blocks
forever(function () {
if (sensors.color1.light(LightIntensityMode.Ambient) > 20) {
brick.setStatusLight(StatusLight.Green)
} else {
brick.setStatusLight(StatusLight.Orange)
}
})
```
## See also
[calibrate light](/reference/sensors/color-sensor/calibrate-light)

View File

@ -1,16 +1,27 @@
# On Color Detected
# on Color Detected
Run some code when the color you want to watch for is detected.
```sig
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () { })
```
# Parameters
The [color](/reference/sensors/color) you choose to look for is one of the colors that the sensor can detect. If you want to use colors for tracking, it's best to use a color that is the same or very close to the ones the sensor detects.
## Examples
## Parameters
* **color**: the [color](/reference/sensors/color) to watch for.
* **handler**: the code you want to run when the color is detected.
## Example
Show an expression on the screen when the color sensor ``color 1`` sees ``blue``.
```blocks
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {
brick.showImage(images.expressionsSick)
})
```
## See also
[pause for color](/reference/sensors/color-sensor/pause-for-color), [color](/reference/sensors/color)

View File

@ -0,0 +1,33 @@
# on Light Changed
Run some code when the amount of light dectected changes.
```sig
sensors.color1.onLightChanged(LightIntensityMode.Reflected, LightCondition.Dark, function () {
})
```
You can check for a change in either _ambient_ or _reflected_ light and run some code when it happens. This event happens when the sensor detects light going to ``dark`` or to ``bright``. You choose what condition you will run your code for.
## Parameters
* **mode**: lighting mode to use for detection. This is for either ``ambient`` or ``reflected`` light.
* **condition**: the condition that the light changed to: ``dark`` or ``bright``.
* **handler**: the code you want to run when the light changes.
## Example
Show a message on the screen when the ambient light goes dark.
```blocks
sensors.color1.onLightChanged(LightIntensityMode.Ambient, LightCondition.Dark, function() {
brick.clearScreen();
brick.showString("It just got dark", 1)
brick.showString("Can you see me?", 2)
})
```
## See also
[light](/reference/sensors/color-sensor/light), [on color detected](/reference/sensors/color-sensor/on-color-detected)

View File

@ -0,0 +1,28 @@
# pause For Color
Wait for the sensor to see a certain color.
```sig
sensors.color1.pauseForColor(ColorSensorColor.Blue)
```
The [color](/reference/sensors/color) you choose to look for is one of the colors that the sensor can detect. If you want to use colors for tracking, it's best to use a color that is the same or very close to the ones the sensor detects.
## Parameters
* **color**: the [color](/reference/sensors/color) to watch for.
## Example
Wait for the sensor to see ``blue``. Then, show an expression on the screen.
```blocks
brick.showString("Waiting for blue", 1)
sensors.color1.pauseForColor(ColorSensorColor.Blue)
brick.clearScreen()
brick.showImage(images.expressionsSick)
```
## See also
[on color detected](/reference/sensors/color-sensor/on-color-detected), [color](/reference/sensors/color)

View File

@ -0,0 +1,29 @@
# pause For Light
Wait for the light condition to change.
```sig
sensors.color1.pauseForLight(LightIntensityMode.Reflected, LightCondition.Dark)
```
You can wait for a change in either _ambient_ or _reflected_ light. This event happens when the sensor detects light going to ``dark`` or to ``bright``. You choose what condition you will wait for.
## Parameters
* **mode**: lighting mode to use for detection. This is for either ``ambient`` or ``reflected`` light.
* **condition**: the condition that the light changed to: ``dark`` or ``bright``.
## Example
Wait for the ambient light to go dark, then show an expression on the screen.
```blocks
brick.showString("Waiting for dark", 1)
sensors.color1.pauseForLight(LightIntensityMode.Reflected, LightCondition.Dark)
brick.clearScreen()
brick.showImage(images.expressionsSick)
```
## See also
[on light changed](/reference/sensors/color-sensor/on-light-changed)

View File

@ -1,4 +1,20 @@
# Reflected Light
# reflected Light
Get the amount of reflected light dectected.
```sig
sensors.color1.reflectedLight()
```
The amount of reflected light measured is in the range of `0` (darkest) to `100` (brightest).
## Returns
* a [number](/types/number) that is the amount of ambiernt light measured. No light (darkness) is `0` and the brightest light is `100`.
## Example
Make the status light show ``green`` if the reflected light is greater than `20`.
```blocks
forever(function () {
@ -8,4 +24,8 @@ forever(function () {
brick.setStatusLight(StatusLight.Orange)
}
})
```
```
## See also
[ambient light](/reference/sensors/color-sensor/ambient-light)

View File

@ -0,0 +1,41 @@
# set Threshold
Set the threshold value for dark or bright light.
```sig
sensors.color1.setThreshold(LightCondition.Dark, 0)
```
Light intensity is measured from `0` (very dark) to `100` (very bright). You can decide what dark and bright mean for your purposes and set a _threshold_ for them. A threshold is a boundary or a limit. If you want a light intensity of `20` mean that it's dark, then you set the sensor threshold for ``dark`` to `20`. Also, if you think that `75` is bright, then you can set the threshold for ``bright`` to that.
After setting a threshold, any event for that light condition won't happen until the amount of light reaches your threshold value:
```block
sensors.color1.setThreshold(LightCondition.Dark, 20)
sensors.color1.onLightChanged(LightIntensityMode.Reflected, LightCondition.Dark, function () {
brick.showMood(moods.sleeping)
})
```
## Parameters
* **condition**: the light intensity threshold to set, ``dark`` or ``bright``.
* **value**: the value of light intensity for the threshold: `0` for very dark to `100` for very bright.
## Example
Make a daylight alarm. When the ambient light reaches `70` flash the status light and play a sound.
```blocks
sensors.color3.setThreshold(LightCondition.Bright, 70)
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Bright, function () {
brick.setStatusLight(StatusLight.GreenFlash)
for (let i = 0; i < 5; i++) {
music.playSoundEffectUntilDone(sounds.mechanicalBackingAlert)
}
})
```
## See also
[threshold](/reference/sensors/color-sensor/threshold)

View File

@ -0,0 +1,27 @@
# threshold
Get the threshold value for dark or bright light.
```sig
sensors.color1.threshold(LightCondition.Dark)
```
Light intensity is measured from `0` (very dark) to `100` (very bright). A _threshold_ sets what dark and bright mean for your purposes. A threshold is a boundary or a limit. If a light intensity of `20` means that it's dark, then the sensor threshold for ``dark`` is `20`. Also, if `75` means bright, then the threshold value for ``bright`` is `75`.
## Returns
* a [number](/types/number) that is the amount of light set for the threshold. No light (darkness) is `0` and the brightest light is `100`.
## Example
Find out what light level is set as the ``dark`` threshold when a dark light event happens.
```blocks
sensors.color3.onLightChanged(LightIntensityMode.Reflected, LightCondition.Dark, function () {
brick.showValue("DarknessThresholdValue", sensors.color3.threshold(LightCondition.Dark), 1)
})
```
## See also
[set threshold](/reference/sensors/color-sensor/set-threshold)

View File

@ -0,0 +1,55 @@
# color
Get a color that the sensor can detect that is close to the color you asked for.
```sig
sensors.color(ColorSensorColor.Blue)
```
Since the color sensor can accurately detect some basic colors, you can't just tell it to look for any color. The sensor may recoginze some color component of the color you ask for. So, you can get a simple color that matches some of your color and tell the sensor to look for that.
## Parameters
* **color**: a color to match with a detectable color. The colors to choose from are:
>* ``blue``
>* ``green``
>* ``yellow``
>* ``red``
>* ``white``
>* ``brown``
## Returns
* a color value that the color sensor can detect. The detectable colors are:
>* ``blue``
>* ``green``
>* ``yellow``
>* ``red``
>* ``white``
>* ``brown``
## ~hint
Currently, the colors you can ask for (input colors) and the colors returned are the same.
## ~
## Example
Turn the status light to ``green`` if the color detected by the ``color 1`` sensor is green.
```blocks
forever(function () {
if (sensors.color1.color() == sensors.color(ColorSensorColor.Green)) {
brick.setStatusLight(StatusLight.Green)
} else {
brick.setStatusLight(StatusLight.Orange)
}
})
```
## See also
[color](/reference/sensors/color-sensor/color)

17
libs/color-sensor/ns.ts Normal file
View File

@ -0,0 +1,17 @@
namespace sensors {
/**
* A color enum picker
* @param color to use, eg: ColorSensorColor.Blue
*/
//% blockId=colorEnumPicker block="%color" shim=TD_ID
//% weight=0 blockHidden=1 turnRatio.fieldOptions.decompileLiterals=1
//% color.fieldEditor="colorenum"
//% color.fieldOptions.colours='["#f12a21", "#ffd01b", "#006db3", "#00934b", "#ffffff", "#6c2d00", "#000000"]'
//% color.fieldOptions.columns=2 color.fieldOptions.className='legoColorPicker'
export function __colorEnumPicker(color: ColorSensorColor): number {
return color;
}
}

View File

@ -4,7 +4,8 @@
"files": [
"README.md",
"colors.jres",
"color.ts"
"color.ts",
"ns.ts"
],
"testFiles": [
"test.ts"

View File

@ -51,6 +51,7 @@ namespace console {
*/
//% blockId=logsendtostreen block="send console to screen"
//% weight=1
//% help=console/send-to-screen
export function sendToScreen(): void {
console.screen.attach();
}

View File

@ -10,6 +10,7 @@ namespace control {
*/
//% weight=21 blockGap=12 blockId="control_raise_event"
//% block="raise event|from %src|with value %value" blockExternalInputs=1
//% help=control/raise-event
void raiseEvent(int src, int value) {
pxt::raiseEvent(src, value);
}

View File

@ -421,28 +421,28 @@ namespace motors {
}
}
//% whenUsed fixedInstance block="large A"
//% whenUsed fixedInstance block="large motor A"
export const largeA = new Motor(Output.A, true);
//% whenUsed fixedInstance block="large B"
//% whenUsed fixedInstance block="large motor B"
export const largeB = new Motor(Output.B, true);
//% whenUsed fixedInstance block="large C"
//% whenUsed fixedInstance block="large motor C"
export const largeC = new Motor(Output.C, true);
//% whenUsed fixedInstance block="large D"
//% whenUsed fixedInstance block="large motor D"
export const largeD = new Motor(Output.D, true);
//% whenUsed fixedInstance block="medium A"
//% whenUsed fixedInstance block="medium motor A"
export const mediumA = new Motor(Output.A, false);
//% whenUsed fixedInstance block="medium B"
//% whenUsed fixedInstance block="medium motor B"
export const mediumB = new Motor(Output.B, false);
//% whenUsed fixedInstance block="medium C"
//% whenUsed fixedInstance block="medium motor C"
export const mediumC = new Motor(Output.C, false);
//% whenUsed fixedInstance block="medium D"
//% whenUsed fixedInstance block="medium motor D"
export const mediumD = new Motor(Output.D, false);
//% fixedInstances
@ -586,16 +586,16 @@ namespace motors {
}
}
//% whenUsed fixedInstance block="large B+C"
//% whenUsed fixedInstance block="large motors B+C"
export const largeBC = new SynchedMotorPair(Output.BC);
//% whenUsed fixedInstance block="large A+D"
//% whenUsed fixedInstance block="large motors A+D"
export const largeAD = new SynchedMotorPair(Output.AD);
//% whenUsed fixedInstance block="large A+B"
//% whenUsed fixedInstance block="large motors A+B"
export const largeAB = new SynchedMotorPair(Output.AB);
//% whenUsed fixedInstance block="large C+D"
//% whenUsed fixedInstance block="large motors C+D"
export const largeCD = new SynchedMotorPair(Output.CD);
function reset(out: Output) {

View File

@ -55,7 +55,8 @@ declare namespace control {
* @param mode optional definition of how the event should be processed after construction.
*/
//% weight=21 blockGap=12 blockId="control_raise_event"
//% block="raise event|from %src|with value %value" blockExternalInputs=1 shim=control::raiseEvent
//% block="raise event|from %src|with value %value" blockExternalInputs=1
//% help=control/raise-event shim=control::raiseEvent
function raiseEvent(src: int32, value: int32): void;
/**

View File

@ -11,36 +11,40 @@ namespace control {
}
/**
* Gets the elapsed time in millis since the last reset
* Get the elapsed time in millis since the last reset
*/
//% blockId=timerMillis block="%timer|millis"
//% help=control/timer/millis
millis(): number {
return control.millis() - this.start;
}
/**
* Gets the elapsed time in seconds since the last reset
* Get the elapsed time in seconds since the last reset
*/
//% blockId=timerSeconds block="%timer|seconds"
//% help=control/timer/seconds
seconds(): number {
return this.millis() / 1000;
}
/**
* Resets the timer
* Reset the timer
*/
//% blockId=timerRest block="%timer|reset"
//% help=control/timer/reset
reset() {
this.start = control.millis();
}
/**
* Pauses until the timer reaches the given amount of milliseconds
* Pause until the timer reaches the given amount of milliseconds
* @param ms how long to pause for, eg: 5, 100, 200, 500, 1000, 2000
*/
//% blockId=timerPauseUntil block="%timer|pause until (ms) %ms"
//% help=control/timer/pause-until
pauseUntil(ms: number) {
const remaining = this.millis() - ms;
const remaining = ms - this.millis();
pause(Math.max(0, remaining));
}
}

View File

@ -37,11 +37,11 @@ namespace sensors {
* @param sensor the gyroscope to query the request
*/
//% help=sensors/gyro/angle
//% block="%sensor|angle"
//% block="**gyro** %this|angle"
//% blockId=gyroGetAngle
//% parts="gyroscope"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% weight=64 blockGap=8
//% group="Gyro Sensor"
angle(): number {
@ -57,12 +57,12 @@ namespace sensors {
* @param sensor the gyroscope to query the request
*/
//% help=sensors/gyro/rate
//% block="%sensor|rate"
//% block="**gyro** %this|rate"
//% blockId=gyroGetRate
//% parts="gyroscope"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% weight=65 blockGap=8
//% this.fieldEditor="ports"
//% weight=65 blockGap=8
//% group="Gyro Sensor"
rate(): number {
if (this.calibrating)
@ -82,18 +82,18 @@ namespace sensors {
* Forces a calibration of the gyro. Must be called when the sensor is completely still.
*/
//% help=sensors/gyro/reset
//% block="reset %sensor|"
//% blockId=gyroReset
//% block="reset **gyro** %this|"
//% blockId=gyroReset
//% parts="gyroscope"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% weight=50
//% this.fieldEditor="ports"
//% weight=50
//% group="Gyro Sensor"
reset(): void {
if (this.calibrating) return; // already in calibration mode
this.calibrating = true;
// may be triggered by a button click,
// may be triggered by a button click,
// give time for robot to settle
pause(700);
// send a reset command
@ -127,7 +127,7 @@ namespace sensors {
/**
* Enables or disable drift correction
* @param enabled
* @param enabled
*/
//%
setDriftCorrection(enabled: boolean) {
@ -135,15 +135,15 @@ namespace sensors {
}
}
//% fixedInstance whenUsed block="gyro 2" weight=95 jres=icons.port2
//% fixedInstance whenUsed block="2" weight=95 jres=icons.port2
export const gyro2: GyroSensor = new GyroSensor(2)
//% fixedInstance whenUsed block="gyro 1" jres=icons.port1
//% fixedInstance whenUsed block="1" jres=icons.port1
export const gyro1: GyroSensor = new GyroSensor(1)
//% fixedInstance whenUsed block="gyro 3" jres=icons.port3
//% fixedInstance whenUsed block="3" jres=icons.port3
export const gyro3: GyroSensor = new GyroSensor(3)
//% fixedInstance whenUsed block="gyro 4" jres=icons.port4
//% fixedInstance whenUsed block="4" jres=icons.port4
export const gyro4: GyroSensor = new GyroSensor(4)
}

View File

@ -0,0 +1,17 @@
# Infrared beacon
```cards
sensors.remoteButtonCenter.onEvent(ButtonEvent.Pressed, function () {})
sensors.remoteButtonCenter.pauseUntil(ButtonEvent.Pressed);
sensors.remoteButtonCenter.isPressed()
sensors.remoteButtonCenter.wasPressed()
sensors.infrared1.setRemoteChannel(null)
```
## See also
[on event](/reference/sensors/beacon/on-event),
[pause until](/reference/sensors/beacon/pause-until),
[is pressed](/reference/sensors/beacon/is-pressed)
[was pressed](/reference/sensors/beacon/was-pressed)
[set remote channel](/reference/sensors/beacon/set-remote-channel)

View File

@ -0,0 +1,44 @@
# is Pressed
Check to see if a remote beacon button is currently pressed or not.
```sig
sensors.remoteButtonBottomLeft.isPressed()
```
An [infrared beacon][lego beacon] works with an infrared sensor connected to the @boardname@. The beacon sends a signal over infrared with information about button presses on the beacon. The infrared sensor receives the signal from the beacon and records a button event.
## Returns
* a [boolean](/types/boolean) value that is `true` if the beacon button is currently pressed. It's `false` if the button is not pressed.
## ~hint
**Remote channel**
In order to recognize a button event signalled from a remote beacon, an infrared sensor must know what channel to listen on for messages from that beacon. An infrared sensor needs to set the channel first, then it can receive messages transmitted by the beacon. Before waiting for, or checking on an button event from a beacon, use [set remote channel](/reference/sensors/beacon/set-remote-channel).
## ~
## Example
If the beacon button ``center`` is pressed, show a `green` status light. Otherwise, set the status light to `orange`.
```blocks
sensors.infrared1.setRemoteChannel(InfraredRemoteChannel.Ch0)
forever(function () {
if (sensors.remoteButtonCenter.isPressed()) {
brick.setStatusLight(StatusLight.Green)
} else {
brick.setStatusLight(StatusLight.Orange)
}
})
```
## See also
[was pressed](/reference/sensors/beacon/was-pressed), [on event](/reference/sensors/beacon/on-event)
[EV3 Infrared Beacon][lego beacon]
[lego beacon]: https://education.lego.com/en-us/products/ev3-infrared-beacon/45508

View File

@ -0,0 +1,46 @@
# on Event
Run some code when a remote beacon button is pressed, bumped, or released.
```sig
sensors.remoteButtonBottomLeft.onEvent(ButtonEvent.Bumped, function () {});
```
An [infrared beacon][lego beacon] works with an infrared sensor connected to the @boardname@. The beacon sends a signal over infrared with information about button presses on the beacon. The infrared sensor receives the signal from the beacon and records a button event.
## Parameters
* **ev**: the beacon button action to run some code for. The button actions (events) are:
> * ``pressed``: the button was pressed, or pressed and released
> * ``bumped``: the button was just bumped
> * ``released``: the button was just released
* **body**: the code you want to run when something happens to the beacon button.
## ~hint
**Remote channel**
In order to recognize a button event signalled from a remote beacon, an infrared sensor must know what channel to listen on for messages from that beacon. An infrared sensor needs to set the channel first, then it can receive messages transmitted by the beacon. Before waiting for, or checking on an button event from a beacon, use [set remote channel](/reference/sensors/beacon/set-remote-channel).
## ~
## Example
Check for an event on beacon button sensor ``center``. Put an expression on the screen when the button is released.
```blocks
sensors.infrared1.setRemoteChannel(InfraredRemoteChannel.Ch0)
sensors.remoteButtonCenter.onEvent(ButtonEvent.Released, function () {
brick.showImage(images.expressionsSick)
})
```
### See also
[is pressed](/reference/sensors/beacon/is-pressed),
[was pressed](/reference/sensors/beacon/was-pressed),
[pause until](/reference/sensors/beacon/pause-until)
[EV3 Infrared Beacon][lego beacon]
[lego beacon]: https://education.lego.com/en-us/products/ev3-infrared-beacon/45508

View File

@ -0,0 +1,53 @@
# pause Until
Make your program wait until a button event from a remote beacon happens.
```sig
sensors.remoteButtonBottomLeft.pauseUntil(ButtonEvent.Bumped);
```
An [infrared beacon][lego beacon] works with an infrared sensor connected to the @boardname@. The beacon sends a signal over infrared with information about button presses on the beacon. The infrared sensor receives the signal from the beacon and records a button event.
## Parameters
* **ev**: the beacon button action to wait for. The button actions (events) are:
> * ``pressed``: the button was pressed, or pressed and released
> * ``bumped``: the button was just bumped
> * ``released``: the button was just released
## ~hint
**Remote channel**
In order to recognize a button event signalled from a remote beacon, an infrared sensor must know what channel to listen on for messages from that beacon. An infrared sensor needs to set the channel first, then it can receive messages transmitted by the beacon. Before waiting for, or checking on an button event from a beacon, use [set remote channel](/reference/sensors/beacon/set-remote-channel).
## ~
## Example
Wait for a bump to beacon button `center` before continuing with displaying a message on the screen.
```blocks
let waitTime = 0;
brick.clearScreen();
brick.showString("We're going to wait", 1);
brick.showString("for you to bump the", 2);
brick.showString("touch sensor on port 1", 3);
waitTime = control.millis();
sensors.infrared1.setRemoteChannel(InfraredRemoteChannel.Ch0)
sensors.remoteButtonCenter.pauseUntil(ButtonEvent.Bumped);
brick.clearScreen();
if (control.millis() - waitTime > 5000) {
brick.showString("Ok, that took awhile!", 1);
} else {
brick.showString("Ah, you let go!", 1);
}
```
## See also
[on event](/reference/sensors/beacon/on-event)
[EV3 Infrared Beacon][lego beacon]
[lego beacon]: https://education.lego.com/en-us/products/ev3-infrared-beacon/45508

View File

@ -0,0 +1,35 @@
# set Remote Channel
Set the remote infrared signal channel for an infrared sensor.
```sig
sensors.infrared1.setRemoteChannel(InfraredRemoteChannel.Ch0)
```
An infrared sensor connected to the @boardname@ can receive messages (signals for button events) from a remote infrared beacon. In order for the sensor to know which beacon to receive messages from, a _channel_ is used. The beacon has a switch on it to select a particular channel to transmit on. The sensor needs to know which channel to receive ("listen" for) messages from the beacon.
A sensor is not automatically set to listen for infrared messages on a channel. To avoid confusion on which sensor receives signals from a beacon, each sensor (if you have more than one), sets a remote channel for itself. The channel number matches the channel selected on the beacon.
## Parameters
* **channel**: the channel for the infrared sensor to "listen" on. You can choose to use one of 4 channels: ``0``, ``1``, ``2``, and ``3``.
## Example
Select channel **2** on an infrared beacon. Set the remote channel for infrared sensor ``infrared 3`` to channel ``2``. Wait for the ``center`` button press on the beacon using channel ``2``.
```blocks
sensors.infrared3.setRemoteChannel(InfraredRemoteChannel.Ch2);
sensors.remoteButtonCenter.pauseUntil(ButtonEvent.Pressed);
brick.clearScreen();
brick.showString("Center button on", 1);
brick.showString("channel 2 beacon", 2);
brick.showString("was pressed.", 3);
```
## See also
[was pressed](/reference/sensors/beacon/was-pressed), [on event](/reference/sensors/beacon/on-event)
[EV3 Infrared Beacon][lego beacon]
[lego beacon]: https://education.lego.com/en-us/products/ev3-infrared-beacon/45508

View File

@ -0,0 +1,47 @@
# was Pressed
See if a button on a remote infrared beacon was pressed since the last time it was checked.
```sig
sensors.remoteButtonBottomLeft.wasPressed()
```
An [infrared beacon][lego beacon] works with an infrared sensor connected to the @boardname@. The beacon sends a signal over infrared with information about button presses on the beacon. The infrared sensor receives the signal from the beacon and records a button event.
If a button was pressed, then that event is remembered. Once you check if a beacon button **was pressed**, that status is set back to `false`. If you check again before the beacon button is pressed another time, the **was pressed** status is `false`. Only when the button is pressed will the **was pressed** status go to `true`.
## Returns
* a [boolean](/types/boolean) value that is `true` if the beacon button was pressed before. It's `false` if the button was not pressed.
## ~hint
**Remote channel**
In order to recognize a button event signalled from a remote beacon, an infrared sensor must know what channel to listen on for messages from that beacon. An infrared sensor needs to set the channel first, then it can receive messages transmitted by the beacon. Before waiting for, or checking on an button event from a beacon, use [set remote channel](/reference/sensors/beacon/set-remote-channel).
## ~
## Example
If the beacon button ``top left`` was pressed, show a `green` status light. Otherwise, set the status light to `orange`.
```blocks
sensors.infrared1.setRemoteChannel(InfraredRemoteChannel.Ch0)
forever(function () {
if (sensors.remoteButtonTopLeft.wasPressed()) {
brick.setStatusLight(StatusLight.Green)
} else {
brick.setStatusLight(StatusLight.Orange)
}
pause(500)
})
```
## See also
[is pressed](/reference/sensors/beacon/is-pressed), [on event](/reference/sensors/beacon/on-event)
[EV3 Infrared Beacon][lego beacon]
[lego beacon]: https://education.lego.com/en-us/products/ev3-infrared-beacon/45508

View File

@ -0,0 +1,13 @@
# Infrared sensor
```cards
sensors.infrared1.onEvent(null, function () {});
sensors.infrared1.pauseUntil(null);
sensors.infrared1.proximity();
```
## See Also
[on event](/reference/sensors/infrared/on-event),
[pause until](/reference/sensors/infrared/pause-until),
[proximity](/reference/sensors/infrared/proximity)

View File

@ -0,0 +1,35 @@
# on Event
Run some code when an object is detected by the infrared sensor.
```sig
sensors.infrared4.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.infrared4.onEvent(InfraredSensorEvent.ObjectNear, function () {
brick.showString("Object detected at:", 1)
brick.showNumber(sensors.infrared4.proximity(), 2)
brick.showString("percent of range", 3)
})
```
## See also
[pause until](/reference/sensors/infrared/pause-until)

View File

@ -0,0 +1,34 @@
# pause Until
Make your program wait until an some object is detected in proximity of the infrared sensor.
```sig
sensors.infrared1.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.infrared1.pauseUntil(InfraredSensorEvent.ObjectDetected);
brick.showString("Hey, I just saw", 1)
brick.showString("Something!", 2);
```
## See also
[on event](/reference/sensors/ultrasonic/on-event)

View File

@ -0,0 +1,32 @@
# proximity Threshold
Get the proximity threshold for when objects are near and detected.
```sig
sensors.infrared1.proximityThreshold(InfraredSensorEvent.ObjectNear)
```
Infrared sensors determine proximity of an object by measuring the intensity of the infrared light reflected from it. The proximity range of measurment is from `0` to `100`. Proximity _thresholds_ use a value in this range to decide when a proximity event should happen for a detected object.
## Parameters
* **condition**: the proximity threshold to return a value for. These are: ``near`` and ``detected``.
## Returns
* a [number](/types/number) that is the proximity value for the threshold. This is a number between `0` and `100`.
## Example
When an object with near proximity is detected, show what the threshold is.
```blocks
sensors.infrared1.onEvent(InfraredSensorEvent.ObjectNear, function () {
brick.showValue("NearObjectThreshold", sensors.infrared1.proximityThreshold(InfraredSensorEvent.ObjectNear)
, 1)
})
```
## See also
[set proximity threshold](/reference/sensors/infrared/set-proximity-threshold)

View File

@ -0,0 +1,30 @@
# proximity
Get the promixity of an object measured by the infrared sensor.
```sig
sensors.infrared1.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.infrared4.onEvent(InfraredSensorEvent.ObjectNear, function () {
brick.clearScreen()
brick.showValue("proximity", sensors.infrared4.proximity(), 1)
})
```
## See also
[on event](/reference/sensors/infrared/on-event), [pause until](/reference/sensors/infrared/pause-until)

View File

@ -0,0 +1,35 @@
# set Proximity Threshold
Set the proximity threshold for when objects are near or detected.
```sig
sensors.infrared1.setPromixityThreshold(InfraredSensorEvent.ObjectNear, 0)
```
Infrared sensors determine proximity of an object by measuring the intensity of the infrared light reflected from it. The proximity range of measurment is from `0` to `100`. You can decide what value in that range you want mean that something is near or that something was detected.
If you want a proximity value of `32` to mean that a detected object is near, then the ``near`` threshold is set to that value. If you want any object within a proximity of `95` to cause a detection event, then the ``detected`` threshold is set to `95`.
## Parameters
* **condition**: the threshold condition to use this proximity. These are: ``near`` and ``detected``.
* **value**: a proximity [number](/types/number) to set the threshold for.
## Example
Set a threshold for detecting something moving within a proximity `30`. Wait for an object to show up. When it does, flash the status light and make noise as an alarm.
```blocks
sensors.infrared1.setPromixityThreshold(InfraredSensorEvent.ObjectDetected, 30)
sensors.infrared1.pauseUntil(InfraredSensorEvent.ObjectDetected)
brick.clearScreen()
brick.showString("Perimeter Breach!!!", 3)
brick.setStatusLight(StatusLight.RedFlash)
for (let i = 0; i < 10; i++) {
music.playSoundEffectUntilDone(sounds.mechanicalHorn2)
}
```
## See also
[proximity threshold](/reference/sensors/infrared/proximity-threshold)

View File

@ -83,8 +83,8 @@ namespace sensors {
* Check if a remote button is currently pressed or not.
* @param button the remote button to query the request
*/
//% help=input/remote-infrared-beacon/is-pressed
//% block="%button|is pressed"
//% help=sensors/beacon/is-pressed
//% block="**remote button** %button|is pressed"
//% blockId=remoteButtonIsPressed
//% parts="remote"
//% blockNamespace=sensors
@ -98,8 +98,8 @@ namespace sensors {
* See if the remote button was pressed again since the last time you checked.
* @param button the remote button to query the request
*/
//% help=input/remote-infrared-beacon/was-pressed
//% block="%button|was pressed"
//% help=sensors/beacon/was-pressed
//% block="**remote button** %button|was pressed"
//% blockId=remotebuttonWasPressed
//% parts="remote"
//% blockNamespace=sensors
@ -110,13 +110,13 @@ namespace sensors {
}
/**
* Do something when a button or sensor is clicked, up or down
* Do something when a remote button is pressed, bumped, or released
* @param button the button that needs to be clicked or used
* @param event the kind of button gesture that needs to be detected
* @param body code to run when the event is raised
*/
//% help=input/remote-infrared-beacon/on-event
//% blockId=remotebuttonEvent block="on %button|%event"
//% help=sensors/beacon/on-event
//% blockId=remotebuttonEvent block="on **remote button** %button|%event"
//% parts="remote"
//% blockNamespace=sensors
//% weight=99 blockGap=8
@ -126,11 +126,11 @@ namespace sensors {
}
/**
* Pauses until the given event is raised
* Pause until a remote button event happens
* @param ev the event to wait for
*/
//% help=input/remote-infrared-beacon/pause-until
//% blockId=remoteButtonPauseUntil block="pause until %button|%event"
//% help=sensors/beacon/pause-until
//% blockId=remoteButtonPauseUntil block="pause until **remote button** %button|%event"
//% parts="remote"
//% blockNamespace=sensors
//% weight=99 blockGap=8
@ -181,31 +181,33 @@ namespace sensors {
}
/**
* Registers code to run when an object is getting near.
* Register code to run when an object is getting near.
* @param handler the code to run when detected
*/
//% help=input/infrared/on
//% block="on %sensor|%event"
//% help=sensors/infrared/on-event
//% block="on **infrared** %this|%event"
//% blockId=infraredOn
//% parts="infraredsensor"
//% blockNamespace=sensors
//% weight=100 blockGap=8
//% group="Infrared Sensor"
//% this.fieldEditor="ports"
onEvent(event: InfraredSensorEvent, handler: () => void) {
this._setMode(InfraredSensorMode.Proximity)
control.onEvent(this._id, event, handler);
}
/**
* Waits for the event to occur
* Wait until the infrared sensor detects something
*/
//% help=input/ultrasonic/wait
//% block="pause until %sensor| %event"
//% help=sensors/infrared/pause-until
//% block="pause until **infrared** %this| %event"
//% blockId=infraredwait
//% parts="infraredsensor"
//% blockNamespace=sensors
//% weight=99 blockGap=8
//% group="Infrared Sensor"
//% this.fieldEditor="ports"
pauseUntil(event: InfraredSensorEvent) {
this._setMode(InfraredSensorMode.Proximity)
control.waitForEvent(this._id, event);
@ -215,26 +217,29 @@ 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
//% block="%sensor|proximity"
//% help=sensors/infrared/proximity
//% block="**infrared** %this|proximity"
//% blockId=infraredGetProximity
//% parts="infrared"
//% blockNamespace=sensors
//% weight=98 blockGap=8
//% group="Infrared Sensor"
//% weight=98 blockGap=8
//% group="Infrared Sensor"
//% this.fieldEditor="ports"
proximity(): number {
this._setMode(InfraredSensorMode.Proximity)
return this.getNumber(NumberFormat.UInt8LE, 0)
}
/**
* Sets the remote channel to listen from
* Set the remote channel to listen to
* @param channel the channel to listen
*/
//% blockNamespace=sensors
//% blockId=irSetRemoteChannel block="set %sensor|remote channel to %channel"
//% weight=99
//% blockId=irSetRemoteChannel block="set **infrared** %this|remote channel to %channel"
//% weight=99
//% group="Remote Infrared Beacon"
//% this.fieldEditor="ports"
//% help=sensors/beacon/set-remote-channel
setRemoteChannel(channel: InfraredRemoteChannel) {
this.setMode(InfraredSensorMode.RemoteControl)
channel = Math.clamp(0, 3, channel | 0)
@ -246,9 +251,10 @@ namespace sensors {
* @param condition the dark or bright light condition
* @param value the value threshold
*/
//% blockId=irSetThreshold block="set %sensor|%condition|to %value"
//% blockId=irSetThreshold block="set **infrared** %this|%condition|to %value"
//% group="Threshold" blockGap=8 weight=49
//% value.min=0 value.max=100
//% this.fieldEditor="ports"
setPromixityThreshold(condition: InfraredSensorEvent, value: number) {
if (condition == InfraredSensorEvent.ObjectNear)
this._proximityThreshold.setLowThreshold(value)
@ -257,12 +263,12 @@ namespace sensors {
}
/**
* Gets the threshold value
* Get a threshold value
* @param condition the proximity condition
*/
//% blockId=irGetThreshold block="%sensor|%condition"
//% blockId=irGetThreshold block="**infrared** %this|%condition"
//% group="Threshold" blockGap=8 weight=49
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
proximityThreshold(condition: InfraredSensorEvent): number {
return this._proximityThreshold.threshold(<ThresholdState><number>LightCondition.Dark);
}
@ -274,45 +280,45 @@ namespace sensors {
}
}
//% fixedInstance whenUsed block="infrared 1" jres=icons.port1
export const infraredSensor1: InfraredSensor = new InfraredSensor(1)
//% fixedInstance whenUsed block="1" jres=icons.port1
export const infrared1: InfraredSensor = new InfraredSensor(1)
//% fixedInstance whenUsed block="infrared 2" jres=icons.port2
export const infraredSensor2: InfraredSensor = new InfraredSensor(2)
//% fixedInstance whenUsed block="2" jres=icons.port2
export const infrared2: InfraredSensor = new InfraredSensor(2)
//% fixedInstance whenUsed block="infrared 3" jres=icons.port3
export const infraredSensor3: InfraredSensor = new InfraredSensor(3)
//% fixedInstance whenUsed block="3" jres=icons.port3
export const infrared3: InfraredSensor = new InfraredSensor(3)
//% fixedInstance whenUsed block="infrared 4" jres=icons.port4
export const infraredSensor4: InfraredSensor = new InfraredSensor(4)
//% fixedInstance whenUsed block="4" jres=icons.port4
export const infrared4: InfraredSensor = new InfraredSensor(4)
/**
* Remote beacon (center) button.
*/
//% whenUsed block="remote button center" weight=95 fixedInstance
//% whenUsed block="center" weight=95 fixedInstance
export const remoteButtonCenter = __irButton(InfraredRemoteButton.CenterBeacon)
/**
* Remote top-left button.
*/
//% whenUsed block="remote button top left" weight=95 fixedInstance
//% whenUsed block="top left" weight=95 fixedInstance
export const remoteButtonTopLeft = __irButton(InfraredRemoteButton.TopLeft)
/**
* Remote top-right button.
*/
//% whenUsed block="remote button top right" weight=95 fixedInstance
//% whenUsed block="top right" weight=95 fixedInstance
export const remoteButtonTopRight = __irButton(InfraredRemoteButton.TopRight)
/**
* Remote bottom-left button.
*/
//% whenUsed block="remote button bottom left" weight=95 fixedInstance
//% whenUsed block="bottom left" weight=95 fixedInstance
export const remoteButtonBottomLeft = __irButton(InfraredRemoteButton.BottomLeft)
/**
* Remote bottom-right button.
*/
//% whenUsed block="remote button bottom right" weight=95 fixedInstance
//% whenUsed block="bottom right" weight=95 fixedInstance
export const remoteButtonBottomRight = __irButton(InfraredRemoteButton.BottomRight)
}

View File

@ -0,0 +1,15 @@
# Music
```cards
music.playSoundEffect(null)
music.playSoundEffectUntilDone(null)
music.stopAllSounds()
music.playTone(0, 0)
music.ringTone(Note.C)
music.rest(100)
music.changeTempoBy(20)
music.setTempo(120)
music.noteFrequency(Note.C)
music.beat()
music.setVolume(50)
```

View File

@ -0,0 +1,54 @@
# play Sound Effect Until Done
Play a sound from one of the built-in sound effect until it completes.
```sig
music.playSoundEffectUntilDone(null)
```
There are several sound effects you can play. Use the sounds list in the block to pick the sound you want to play. The sound plays and this part of your program waits until the sound finishes. Other parts of your program, like code in **forever** loops and **runInParallel** blocks will continue to run though.
Many of the built-in sound effects make sounds match to the actions that your @boardname@ is doing. For example, you can add the ``mechanical motor start`` sound your program to indicate that your motors are running.
## Parameters
* **sound**: a built-in sound effect from the list of available sounds.
## Example
Make a game where the buttons on the brick are used to guess a number from `1` to `4` that your program randomly chooses. On the correct guess, flash a ``green`` status light and play a cheering sound. The ``enter`` button resets the game to play again.
```blocks
let pick = 0
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
pick = 0
music.stopAllSounds()
brick.setStatusLight(StatusLight.Off)
})
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
pick = 1
})
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
pick = 2
})
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
pick = 3
})
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
pick = 4
})
forever(function () {
if (pick > 0) {
if (Math.randomRange(0, 3) + 1 == pick) {
brick.setStatusLight(StatusLight.GreenFlash)
music.playSoundEffectUntilDone(sounds.expressionsCheering)
}
pick = 0
}
pause(300)
})
```
## See also
[play sound effect](/reference/music/play-sound-effect), [stop all sounds](/reference/music/stop-all-sounds)

View File

@ -0,0 +1,29 @@
# play Sound Effect
Play a sound from one of the built-in sound effects.
```sig
music.playSoundEffect(null)
```
There are several sound effects you can play. Use the sounds list in the block to pick the sound you want to play. When the sounds starts, your program continues on and doesn't wait for the sound to finish. This lets your program do other things while your sound plays in the _background_.
Many of the built-in sound effects make sounds match to the actions that your @boardname@ is doing. For example, you can add the ``mechanical motor start`` sound to your program to indicate that your motors are running.
## Parameters
* **sound**: a built-in sound effect from the list of available sounds.
## Example
Drive the brick backwards and play a backup alert sound.
```blocks
music.playSoundEffect(sounds.mechanicalBackingAlert);
motors.largeBC.tank(-50, -50, 15, MoveUnit.Rotations);
music.stopAllSounds();
```
## See also
[play sound effect until done](/reference/music/play-sound-effect-until-done), [stop all sounds](/reference/music/stop-all-sounds)

View File

@ -260,11 +260,12 @@ namespace music {
const soundsLimit = 1;
/**
* Plays a sound
* Play a sound and wait until it finishes
* @param sound the sound to play
*/
//% blockId=music_play_sound_effect_until_done block="play sound effect %sound|until done"
//% weight=98 blockGap=8
//% help=music/play-sound-effect-until-done
export function playSoundEffectUntilDone(sound: Sound) {
if (!sound || numSoundsPlaying >= soundsLimit) return;
numSoundsPlaying++;
@ -288,6 +289,7 @@ namespace music {
*/
//% blockId=music_play_sound_effect block="play sound effect %sound"
//% weight=99 blockGap=8
//% help=music/play-sound-effect
export function playSoundEffect(sound: Sound) {
if (!sound || numSoundsPlaying >= soundsLimit) return;
numSoundsPlaying++;

View File

@ -10,7 +10,7 @@ sensors.touch1.onEvent(ButtonEvent.Bumped, function () {
## Parameters
* **ev**: the touch sensor action to run some code for. The the touch actions (events) are:
* **ev**: the touch sensor action to run some code for. The touch actions (events) are:
> * ``pressed``: the sensor was pressed, or pressed and released
> * ``bumped``: the sensor was just bumped
> * ``released``: the sensor was just released
@ -18,7 +18,7 @@ sensors.touch1.onEvent(ButtonEvent.Bumped, function () {
## Example
Check for an event on touch sensor ``touch 1``. Put an expression on the screen when the senosr is released.
Check for an event on touch sensor ``touch 1``. Put an expression on the screen when the sensor is released.
```blocks
sensors.touch1.onEvent(ButtonEvent.Released, function () {

View File

@ -8,7 +8,7 @@ sensors.touch1.pauseUntil(ButtonEvent.Bumped);
## Parameters
* **ev**: the touch sensor action to wait for. The the touch actions (events) are:
* **ev**: the touch sensor action to wait for. The touch actions (events) are:
> * ``pressed``: the sensor was pressed, or pressed and released
> * ``bumped``: the sensor was just bumped
> * ``released``: the sensor was just released

View File

@ -10,7 +10,7 @@ If a touch sensor was pressed, then that event is remembered. Once you check if
## Returns
* a [boolean](/types/boolean) value that is `true` if the sensor is was pressed before. It's `false` if the sensor was not pressed.
* a [boolean](/types/boolean) value that is `true` if the sensor was pressed before. It's `false` if the sensor was not pressed.
## Example

View File

@ -30,10 +30,10 @@ namespace sensors {
* @param body code to run when the event is raised
*/
//% help=sensors/touch-sensor/on-event
//% blockId=touchEvent block="on %sensor|%event"
//% blockId=touchEvent block="on **touch** %this|%event"
//% parts="touch"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% weight=99 blockGap=12
//% group="Touch Sensor"
onEvent(ev: ButtonEvent, body: () => void) {
@ -46,10 +46,10 @@ namespace sensors {
* @param event the kind of button gesture that needs to be detected
*/
//% help=sensors/touch-sensor/pause-until
//% blockId=touchWaitUntil block="pause until %sensor|%event"
//% blockId=touchWaitUntil block="pause until **touch** %this|%event"
//% parts="touch"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% weight=98 blockGap=12
//% group="Touch Sensor"
pauseUntil(ev: ButtonEvent) {
@ -61,11 +61,11 @@ namespace sensors {
* @param sensor the port to query the request
*/
//% help=sensors/touch-sensor/is-pressed
//% block="%sensor|is pressed"
//% block="**touch** %this|is pressed"
//% blockId=touchIsPressed
//% parts="touch"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% weight=81 blockGap=8
//% group="Touch Sensor"
isPressed() {
@ -77,11 +77,11 @@ namespace sensors {
* @param sensor the port to query the request
*/
//% help=sensors/touch-sensor/was-pressed
//% block="%sensor|was pressed"
//% block="**touch** %this|was pressed"
//% blockId=touchWasPressed
//% parts="touch"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% weight=81
//% group="Touch Sensor"
wasPressed() {
@ -89,12 +89,12 @@ namespace sensors {
}
}
//% whenUsed block="touch 1" weight=95 fixedInstance jres=icons.port1
//% whenUsed block="1" weight=95 fixedInstance jres=icons.port1
export const touch1: TouchSensor = new TouchSensor(1)
//% whenUsed block="touch 2" weight=95 fixedInstance jres=icons.port2
//% whenUsed block="2" weight=95 fixedInstance jres=icons.port2
export const touch2: TouchSensor = new TouchSensor(2)
//% whenUsed block="touch 3" weight=95 fixedInstance jres=icons.port3
//% whenUsed block="3" weight=95 fixedInstance jres=icons.port3
export const touch3: TouchSensor = new TouchSensor(3)
//% whenUsed block="touch 4" weight=95 fixedInstance jres=icons.port4
//% whenUsed block="4" weight=95 fixedInstance jres=icons.port4
export const touch4: TouchSensor = new TouchSensor(4)
}

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,37 @@
# set Threshold
Set the distance threshold for when objects are near, far, or detected.
```sig
sensors.ultrasonic1.setThreshold(UltrasonicSensorEvent.ObjectDetected, 0)
```
Whether something is near or far away really depends on the situation. A object moving towards you is "near" at further distance than something that isn't moving due to the time necessary to move out of its way. So, in certain situations you may want change which distances mean near or far.
You can change the distances for near and far by setting their _thresholds_. A threshold is a boundary or a limit. If you wanted near to mean anything that's closer that 20 centimeters, then that is your threshold for ``near``. Also, if anything further than 35 centimeters is thought of as far, then the threshold for ``far`` is `35`.
Similarly, if you are just concerned about knowing that something has moved within a distance from you, then you set that distance as the threshold for ``detected``.
## Parameters
* **condition**: the threshold condition to set a distance for. These are: ``near``, ``far``, and ``detected``.
* **value**: a [number](/types/number) that the distance in centimeters to set the threshold for.
## Example
Set a threshold for detecting something moving within 30 centimeters. Wait for an object to show up. When it does, flash the status light and make noise as an alarm.
```blocks
sensors.ultrasonic1.setThreshold(UltrasonicSensorEvent.ObjectDetected, 30)
sensors.ultrasonic1.pauseUntil(UltrasonicSensorEvent.ObjectDetected)
brick.clearScreen()
brick.showString("Perimeter Breach!!!", 3)
brick.setStatusLight(StatusLight.RedFlash)
for (let i = 0; i < 10; i++) {
music.playSoundEffectUntilDone(sounds.mechanicalHorn2)
}
```
## See also
[threshold](/reference/sensors/ultrasonic/threshold)

View File

@ -0,0 +1,35 @@
# threshold
Get the distance threshold for when objects are near, far, or detected.
```sig
sensors.ultrasonic1.threshold(UltrasonicSensorEvent.ObjectDetected)
```
Whether something is near or far away really depends on the situation. A object moving towards you is "near" at further distance than something that isn't moving due to the time necessary to move out of its way.
Distances for near and far by have set _thresholds_. A threshold is a boundary or a limit. If near means anything that's closer that 20 centimeters, then the threshold for ``near``. Also, if anything further than 35 centimeters is thought of as far, then the threshold for ``far`` is `35`.
Also, the threshold for nowing that something has moved within a distance from you is set for ``detected``.
## Parameters
* **condition**: the condition to get the threshold distance for. These are: ``near``, ``far``, and ``detected``.
## Returns
* a [number](/types/number) that is the threshold distance in centimeters.
## Example
When a near object is detected, show what the threshold is.
```blocks
sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectNear, function () {
brick.showValue("NearObjectThreshold", sensors.ultrasonic4.threshold(UltrasonicSensorEvent.ObjectNear), 1)
})
```
## See also
[set threshold](/reference/sensors/ultrasonic/set-threshold)

View File

@ -43,10 +43,10 @@ namespace sensors {
*/
//% help=sensors/ultrasonic/on-event
//% blockId=ultrasonicOn
//% block="on %sensor|%event"
//% block="on **ultrasonic** %this|%event"
//% parts="ultrasonicsensor"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% weight=100 blockGap=8
//% group="Ultrasonic Sensor"
onEvent(event: UltrasonicSensorEvent, handler: () => void) {
@ -57,13 +57,13 @@ namespace sensors {
* Waits for the event to occur
*/
//% help=sensors/ultrasonic/pause-until
//% block="pause until %sensor| %event"
//% block="pause until **ultrasonic** %this| %event"
//% blockId=ultrasonicWait
//% parts="ultrasonicsensor"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% weight=99 blockGap=8
//% group="Ultrasonic Sensor"
//% group="Ultrasonic Sensor"
pauseUntil(event: UltrasonicSensorEvent) {
control.waitForEvent(this._id, event);
}
@ -73,13 +73,13 @@ namespace sensors {
* @param sensor the ultrasonic sensor port
*/
//% help=sensors/ultrasonic/distance
//% block="%sensor|distance"
//% block="**ultrasonic** %this|distance"
//% blockId=sonarGetDistance
//% parts="ultrasonicsensor"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
//% weight=65
//% group="Ultrasonic Sensor"
//% group="Ultrasonic Sensor"
distance(): number {
// it supposedly also has an inch mode, but we stick to cm
this._setMode(0)
@ -92,9 +92,10 @@ namespace sensors {
* @param condition the dark or bright light condition
* @param value the value threshold
*/
//% blockId=ultrasonicSetThreshold block="set %sensor|%condition|to %value"
//% blockId=ultrasonicSetThreshold block="set **ultrasonic** %this|%condition|to %value"
//% group="Threshold" blockGap=8 weight=80
//% value.min=0 value.max=255
//% this.fieldEditor="ports"
setThreshold(condition: UltrasonicSensorEvent, value: number) {
switch (condition) {
case UltrasonicSensorEvent.ObjectNear: this.promixityThreshold.setLowThreshold(value); break;
@ -107,9 +108,9 @@ namespace sensors {
* Gets the threshold value
* @param condition the proximity condition
*/
//% blockId=ultrasonicGetThreshold block="%sensor|%condition"
//% blockId=ultrasonicGetThreshold block="**ultrasonic** %this|%condition"
//% group="Threshold" blockGap=8 weight=79
//% sensor.fieldEditor="ports"
//% this.fieldEditor="ports"
threshold(condition: UltrasonicSensorEvent): number {
switch (condition) {
case UltrasonicSensorEvent.ObjectNear: this.promixityThreshold.threshold(ThresholdState.Low); break;
@ -120,15 +121,15 @@ namespace sensors {
}
}
//% fixedInstance whenUsed block="ultrasonic 4" jres=icons.port4
//% fixedInstance whenUsed block="4" jres=icons.port4
export const ultrasonic4: UltraSonicSensor = new UltraSonicSensor(4)
//% fixedInstance whenUsed block="ultrasonic 1" jres=icons.port1
//% fixedInstance whenUsed block="1" jres=icons.port1
export const ultrasonic1: UltraSonicSensor = new UltraSonicSensor(1)
//% fixedInstance whenUsed block="ultrasonic 2" jres=icons.port2
//% fixedInstance whenUsed block="2" jres=icons.port2
export const ultrasonic2: UltraSonicSensor = new UltraSonicSensor(2)
//% fixedInstance whenUsed block="ultrasonic 3" jres=icons.port3
//% fixedInstance whenUsed block="3" jres=icons.port3
export const ultrasonic3: UltraSonicSensor = new UltraSonicSensor(3)
}

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "pxt-ev3",
"version": "0.0.103",
"version": "0.0.108",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "pxt-ev3",
"version": "0.0.103",
"version": "0.0.108",
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
"private": true,
"keywords": [
@ -46,7 +46,7 @@
},
"dependencies": {
"pxt-common-packages": "0.19.5",
"pxt-core": "3.4.5"
"pxt-core": "3.4.8"
},
"scripts": {
"test": "node node_modules/pxt-core/built/pxt.js travis"

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 22.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="svg41" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 23 23" style="enable-background:new 0 0 23 23;" xml:space="preserve">
<style type="text/css">
.st0{fill:#FFFFFF;}
</style>
<title>color</title>
<path class="st0" d="M22.2,20.2L17,15c1.1-1.5,1.8-3.3,1.8-5.3c0-5-4-9-9-9c-5,0-9,4-9,9c0,5,4,9,9,9c1.9,0,3.6-0.6,5.1-1.6l5.2,5.2
L22.2,20.2z M9.8,15.7c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S13.1,15.7,9.8,15.7z"/>
</svg>

After

Width:  |  Height:  |  Size: 637 B

View File

@ -26,7 +26,8 @@ webfontsGenerator({
"./icons/check.svg",
"./icons/download.svg",
"./icons/save.svg",
"./icons/blocks.svg"
"./icons/blocks.svg",
"./categories/search.svg"
],
dest: '../docs/static/fonts/icons/',
round: 10

View File

@ -142,6 +142,10 @@ span.blocklyTreeIcon.blocklyTreeIconadvancedexpanded::before {
content: "\f114";
}
span.blocklyTreeIcon.blocklyTreeIconsearch::before {
content: "\f11a";
}
.save-editortools-btn .icon.save:before {
font-family: 'legoIcons';
content: "\f118";

View File

@ -37,3 +37,24 @@
stroke:#fc3;
stroke-width: 4px !important;
}
/* Color enum picker */
.blocklyDropDownDiv {
.goog-palette {
margin-bottom: 0px !important;
}
.legoColorPicker {
.goog-palette-colorswatch {
height: 30px;
width: 30px;
border-radius: 100%;
}
.goog-palette-cell-hover .goog-palette-colorswatch {
border: 2px solid #000;
}
.goog-palette-cell-selected .goog-palette-colorswatch {
border: 3px solid #000;
}
}
}