Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
0166785c1b | |||
ea0f6a4734 | |||
271721561d | |||
ed8f8bafa7 | |||
8cfb70c97b | |||
84c8e31ff5 | |||
ceb9b7fabf | |||
9e0670551f | |||
6613607503 | |||
3a67190914 |
@ -91,6 +91,23 @@
|
||||
* [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)
|
||||
|
@ -20,9 +20,9 @@
|
||||
},
|
||||
{
|
||||
"name": "Make a System that Communicates",
|
||||
"description": "TBD",
|
||||
"imageUrl": "/static/lessons/make-a-system.png",
|
||||
"url": "/design-engineering/make-it-move",
|
||||
"description": "A robot that tells you what it is doing.",
|
||||
"imageUrl": "/static/lessons/make-it-communicate.png",
|
||||
"url": "/design-engineering/make-it-communicate",
|
||||
"cardType": "side"
|
||||
}
|
||||
]
|
||||
|
164
docs/design-engineering/make-it-communicate.md
Normal file
164
docs/design-engineering/make-it-communicate.md
Normal file
@ -0,0 +1,164 @@
|
||||
# Make A System That Communicates
|
||||
|
||||
## Connect
|
||||
|
||||
### Design Brief
|
||||
|
||||
Design, build and program a robotic system that follows a path and communicates its position at least twice along the way.
|
||||
|
||||
https://www.youtube.com/watch?v=6piMI1JPDQc
|
||||
|
||||
* Robotic systems are built from smaller, related subsystems. Look at the automobile system shown in the video. What subsystems can you see?
|
||||
* What kinds of robots follow a path?
|
||||
* What kind of system do you want to make?
|
||||
|
||||
### Brainstorm
|
||||
|
||||
Discuss different solutions to the design brief.
|
||||
|
||||
Think about:
|
||||
* What kind of motorized mechanism can be used to control the movements of a robot?
|
||||
* How can the robot sense where it is along the path?
|
||||
* How can the robot communicate its position?
|
||||
|
||||

|
||||
|
||||
## Construct
|
||||
|
||||
### Build
|
||||
|
||||
You can start by tinkering with the LEGO elements in the picture and then build on.
|
||||
|
||||
More building ideas:
|
||||
* [EV3 Frames](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/ev3%20frames-5054ee378e624fb4cb31158d2fc8e5cf.pdf)
|
||||
|
||||
* [Tracks](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/tracks-32d7554813af3f25cf5012d54a4bad2b.pdf)
|
||||
|
||||
* [Color Sensor 2](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/color%20sensor_v2-e7fd54b6fa3cdfe36f414c1d2510f9cb.pdf)
|
||||
|
||||
|
||||
Build a path for your robot to follow. You can use electrical tape on a floor, or marker on paper. You can use objects as milestones to indicate a path that can be detected by either the Touch Sensor, Color Sensor, or Ultrasonic Sensor.
|
||||
|
||||
## Program
|
||||
|
||||
Before you program, think about:
|
||||
|
||||
* How will you program the robot to follow a path?
|
||||
* How will you program the robot to communicate its position?
|
||||
* Which programming blocks will you use?
|
||||
|
||||
### ~ hint
|
||||
|
||||
Explore the different Motor and Sensor blocks in the programming menu.
|
||||
|
||||
### ~
|
||||
|
||||
### Sample Solution
|
||||
|
||||
[Video: EV3 Track Rover](/static/lessons/make-it-communicate/trackrover.mp4)
|
||||
|
||||
The Track Rover follows a path using the color sensor. It identifies two locations by color.
|
||||
|
||||
[Building Instructions](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/ev3-dep/building%20instructions/track-rover-bi-6aadb1b053df0c58a0dea108b5ce0eea.pdf)
|
||||
|
||||
### Sample Program Solution
|
||||
|
||||
This program works with the Track Rover. If you create a different robot, adjust the program to fit your solution.
|
||||
|
||||
#### Program summary:
|
||||
|
||||
* If the Color Sensor sees black, Motor B runs at -50 power and Motor C turns off.
|
||||
* If the Color Sensor sees white, Motor B turns off and Motor C runs at -50 power.
|
||||
* If the Color Sensor sees green, all motors stop and the green sound plays.
|
||||
* The robot waits one second, then motors move forward.
|
||||
* If the Color Sensor sees red, all motors stop, and the red sound plays.
|
||||
* The robot waits one second, then motors move forward.
|
||||
* Loops unlimited.
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
if (sensors.color3.color() == ColorSensorColor.Black) {
|
||||
motors.largeB.run(-50)
|
||||
motors.largeC.run(0)
|
||||
} else if (sensors.color3.color() == ColorSensorColor.White) {
|
||||
motors.largeC.run(-50)
|
||||
motors.largeB.run(0)
|
||||
} else if (sensors.color3.color() == ColorSensorColor.Green) {
|
||||
motors.stopAll()
|
||||
music.playSoundEffectUntilDone(sounds.colorsGreen)
|
||||
motors.largeBC.run(-50)
|
||||
} else if (sensors.color3.color() == ColorSensorColor.Red) {
|
||||
motors.stopAll()
|
||||
music.playSoundEffectUntilDone(sounds.colorsRed)
|
||||
motors.largeBC.run(-50)
|
||||
} else {
|
||||
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
```blocks
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Black, function () {
|
||||
motors.largeB.run(-50)
|
||||
motors.largeC.run(0)
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.White, function () {
|
||||
motors.largeB.run(0)
|
||||
motors.largeC.run(-50)
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Green, function () {
|
||||
motors.stopAll()
|
||||
music.playSoundEffect(sounds.colorsGreen)
|
||||
pause(1000)
|
||||
motors.largeBC.run(-50)
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Red, function () {
|
||||
motors.stopAll()
|
||||
music.playSoundEffect(sounds.colorsRed)
|
||||
pause(1000)
|
||||
motors.largeBC.run(-50)
|
||||
})
|
||||
```
|
||||
|
||||
### Download and test
|
||||
|
||||
Click Download and follow the instructions to get your code onto your EV3 Brick. Press the center button on the EV3 Brick to run the program.
|
||||
|
||||
## Contemplate
|
||||
|
||||
### Test and Analyze
|
||||
|
||||
As you work on your solution:
|
||||
1. Describe one part of your design that worked especially well.
|
||||
2. Describe one design change that you had to make.
|
||||
3. What will you try next?
|
||||
|
||||
|
||||
### Review and Revise
|
||||
Take a moment to reflect on your robot solution.
|
||||
|
||||
### Think about:
|
||||
* Can the robot’s movement be more accurate?
|
||||
* What are some ways that others have solved the problem?
|
||||
|
||||
Describe two ways you could improve your robot.
|
||||
|
||||
## Continue
|
||||
|
||||
### Personalize your project
|
||||
* Add/remove LEGO elements to improve the way your robot moves.
|
||||
* Click on the JavaScript tab and experiment with changing the values in the code.
|
||||
* Add a custom image or sounds by adding blocks from the Brick or Music menus.
|
||||
|
||||
## Communicate
|
||||
|
||||
Here are some ideas:
|
||||
* Create a video of your project, especially your final presentation and your robot’s performance.
|
||||
* Explain some important features of your software program.
|
||||
* Produce a building guide for your model by taking a series of photographs as you deconstruct it.
|
||||
* Include an image of your program with comments.
|
||||
* Add a team photograph!
|
||||
|
||||
Congratulations! What will you design next?
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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.infraredSensor1.onEvent(null, function () {});
|
||||
sensors.infraredSensor1.pauseUntil(null);
|
||||
sensors.infraredSensor1.proximity();
|
||||
|
||||
```
|
||||
|
||||
## Infrared beacon button
|
||||
|
||||
```cards
|
||||
sensors.remoteButtonCenter.onEvent(ButtonEvent.Pressed, function () {})
|
||||
sensors.remoteButtonCenter.pauseUntil(ButtonEvent.Pressed);
|
||||
sensors.remoteButtonCenter.isPressed()
|
||||
sensors.remoteButtonCenter.wasPressed()
|
||||
sensors.infraredSensor1.setRemoteChannel(null)
|
||||
```
|
||||
|
BIN
docs/static/lessons/make-it-communicate.png
vendored
Normal file
BIN
docs/static/lessons/make-it-communicate.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 83 KiB |
BIN
docs/static/lessons/make-it-communicate/hero.png
vendored
Normal file
BIN
docs/static/lessons/make-it-communicate/hero.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 83 KiB |
BIN
docs/static/lessons/make-it-communicate/trackrover.mp4
vendored
Normal file
BIN
docs/static/lessons/make-it-communicate/trackrover.mp4
vendored
Normal file
Binary file not shown.
@ -19,28 +19,28 @@ enum LightIntensityMode {
|
||||
}
|
||||
|
||||
const enum ColorSensorColor {
|
||||
//% block="none" jres=colors.none
|
||||
//% block="none" jres=colors.none blockIdentity=sensors.color
|
||||
None,
|
||||
//% block="black" jres=colors.black
|
||||
//% block="black" jres=colors.black blockIdentity=sensors.color
|
||||
Black,
|
||||
//% block="blue" jres=colors.blue
|
||||
//% block="blue" jres=colors.blue blockIdentity=sensors.color
|
||||
Blue,
|
||||
//% block="green" jres=colors.green
|
||||
//% block="green" jres=colors.green blockIdentity=sensors.color
|
||||
Green,
|
||||
//% block="yellow" jres=colors.yellow
|
||||
//% block="yellow" jres=colors.yellow blockIdentity=sensors.color
|
||||
Yellow,
|
||||
//% block="red" jres=colors.red
|
||||
//% block="red" jres=colors.red blockIdentity=sensors.color
|
||||
Red,
|
||||
//% block="white" jres=colors.white
|
||||
//% block="white" jres=colors.white blockIdentity=sensors.color
|
||||
White,
|
||||
//% block="brown" jres=colors.brown
|
||||
//% block="brown" jres=colors.brown blockIdentity=sensors.color
|
||||
Brown
|
||||
}
|
||||
|
||||
enum LightCondition {
|
||||
//% block="dark"
|
||||
Dark = sensors.ThresholdState.Low,
|
||||
//$ block="bright"
|
||||
//% block="bright"
|
||||
Bright = sensors.ThresholdState.High
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ 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
|
||||
@ -210,7 +210,7 @@ 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
|
||||
@ -237,7 +237,7 @@ namespace sensors {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a threshold value
|
||||
* Set a threshold value
|
||||
* @param condition the dark or bright light condition
|
||||
* @param value the value threshold
|
||||
*/
|
||||
@ -245,6 +245,7 @@ namespace sensors {
|
||||
//% group="Threshold" blockGap=8 weight=90
|
||||
//% value.min=0 value.max=100
|
||||
//% sensor.fieldEditor="ports"
|
||||
//% help=sensors/color-sensor/set-threshold
|
||||
setThreshold(condition: LightCondition, value: number) {
|
||||
if (condition == LightCondition.Dark)
|
||||
this.thresholdDetector.setLowThreshold(value)
|
||||
@ -253,12 +254,13 @@ namespace sensors {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the threshold value
|
||||
* Get a threshold value
|
||||
* @param condition the light condition
|
||||
*/
|
||||
//% blockId=colorGetThreshold block="%sensor|%condition"
|
||||
//% group="Threshold" blockGap=8 weight=89
|
||||
//% sensor.fieldEditor="ports"
|
||||
//% help=sensors/color-sensor/threshold
|
||||
threshold(condition: LightCondition): number {
|
||||
return this.thresholdDetector.threshold(<ThresholdState><number>LightCondition.Dark);
|
||||
}
|
||||
@ -266,9 +268,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|%sensor|for %mode"
|
||||
//% group="Threshold" weight=91 blockGap=8
|
||||
//% sensor.fieldEditor="ports"
|
||||
//% help=sensors/color-sensor/calibrate-light
|
||||
calibrateLight(mode: LightIntensityMode, deviation: number = 8) {
|
||||
this.calibrating = true; // prevent events
|
||||
|
||||
@ -318,6 +321,12 @@ namespace sensors {
|
||||
//% blockId=colorSensorColor block="color %color"
|
||||
//% group="Color Sensor"
|
||||
//% weight=97
|
||||
//% help=sensors/color
|
||||
//% color.fieldEditor="gridpicker"
|
||||
//% color.fieldOptions.columns=4
|
||||
//% color.fieldOptions.tooltips=true
|
||||
//% color.fieldOptions.hideRect=true
|
||||
//% color.fieldOptions.width=268
|
||||
export function color(color: ColorSensorColor): ColorSensorColor {
|
||||
return color;
|
||||
}
|
||||
|
@ -1,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)
|
||||
|
@ -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)
|
@ -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)
|
@ -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)
|
@ -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)
|
@ -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)
|
@ -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)
|
@ -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)
|
@ -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)
|
@ -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)
|
@ -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)
|
@ -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)
|
55
libs/color-sensor/docs/reference/sensors/color.md
Normal file
55
libs/color-sensor/docs/reference/sensors/color.md
Normal 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/infrared-sensor/docs/reference/sensors/beacon.md
Normal file
17
libs/infrared-sensor/docs/reference/sensors/beacon.md
Normal 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.infraredSensor1.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)
|
@ -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.infraredSensor1.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
|
@ -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.infraredSensor1.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
|
@ -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.infraredSensor1.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
|
@ -0,0 +1,35 @@
|
||||
# set Remote Channel
|
||||
|
||||
Set the remote infrared signal channel for an infrared sensor.
|
||||
|
||||
```sig
|
||||
sensors.infraredSensor1.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.infraredSensor3.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
|
@ -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.infraredSensor1.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
|
13
libs/infrared-sensor/docs/reference/sensors/infrared.md
Normal file
13
libs/infrared-sensor/docs/reference/sensors/infrared.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Infrared sensor
|
||||
|
||||
```cards
|
||||
sensors.infraredSensor1.onEvent(null, function () {});
|
||||
sensors.infraredSensor1.pauseUntil(null);
|
||||
sensors.infraredSensor1.proximity();
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[on event](/reference/sensors/infrared/on-event),
|
||||
[pause until](/reference/sensors/infrared/pause-until),
|
||||
[proximity](/reference/sensors/infrared/proximity)
|
@ -0,0 +1,35 @@
|
||||
# on Event
|
||||
|
||||
Run some code when an object is detected by the infrared sensor.
|
||||
|
||||
```sig
|
||||
sensors.infraredSensor4.onEvent(InfraredSensorEvent.ObjectNear, function () {});
|
||||
```
|
||||
|
||||
How an object is detected depends on the light _thresholds_ set for the sensor. A threshold is a number for relative distance of the a return of reflected infrared light. The brighter the light, the nearer the object is. The value for what _near_ means is determined by this threshold. A certain minimum amount of light returned is also set to determine that an object is detected. The two thresholds you can set are:
|
||||
|
||||
* **near**: a distance to set to detect objects coming close
|
||||
* **detected**: the brightness of infrared light to needed to detect presence of another infrared transmitter.
|
||||
|
||||
## Parameters
|
||||
|
||||
* **event**: the object detection action to wait for. The detection types (events) are:
|
||||
> * ``detected``: some other object is sending out infrared light
|
||||
> * ``near``: the sensor detected something within the distance of the near threshold
|
||||
* **body**: the code you want to run when something is detected by infrared sensor.
|
||||
|
||||
## Example
|
||||
|
||||
When the ultrasonic sensor on port 4 detects a near object, display its distance on the screen.
|
||||
|
||||
```blocks
|
||||
sensors.infraredSensor4.onEvent(InfraredSensorEvent.ObjectNear, function () {
|
||||
brick.showString("Object detected at:", 1)
|
||||
brick.showNumber(sensors.infraredSensor4.proximity(), 2)
|
||||
brick.showString("percent of range", 3)
|
||||
})
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[pause until](/reference/sensors/infrared/pause-until)
|
@ -0,0 +1,34 @@
|
||||
# pause Until
|
||||
|
||||
Make your program wait until an some object is detected in proximity of the infrared sensor.
|
||||
|
||||
```sig
|
||||
sensors.infraredSensor1.pauseUntil(InfraredSensorEvent.ObjectDetected);
|
||||
```
|
||||
|
||||
How an object is detected depends on the light _thresholds_ set for the sensor. A threshold is a number for relative distance of the a return of reflected infrared light. The brighter the light, the nearer the object is. The value for what _near_ means is determined by this threshold. A certain minimum amount of light returned is also set to determine that an object is detected. The two thresholds you can set are:
|
||||
|
||||
* **near**: a distance to set to detect objects coming close
|
||||
* **detected**: the brightness of infrared light to needed to detect presence of another infrared transmitter.
|
||||
|
||||
## Parameters
|
||||
|
||||
* **event**: the object detection action to wait for. The detection types (events) are:
|
||||
> * ``detected``: some other object is sending out infrared light
|
||||
> * ``near``: the sensor detected something within the distance of the near threshold
|
||||
|
||||
## Example
|
||||
|
||||
Wait for another object sending out infrared light. Show a message on the screen when it's dectected.
|
||||
|
||||
```blocks
|
||||
brick.showString("Waiting for another", 1);
|
||||
brick.showString("robot to appear...", 2);
|
||||
sensors.infraredSensor1.pauseUntil(InfraredSensorEvent.ObjectDetected);
|
||||
brick.showString("Hey, I just saw", 1)
|
||||
brick.showString("Something!", 2);
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[on event](/reference/sensors/ultrasonic/on-event)
|
@ -0,0 +1,32 @@
|
||||
# proximity Threshold
|
||||
|
||||
Get the proximity threshold for when objects are near and detected.
|
||||
|
||||
```sig
|
||||
sensors.infraredSensor1.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.infraredSensor1.onEvent(InfraredSensorEvent.ObjectNear, function () {
|
||||
brick.showValue("NearObjectThreshold", sensors.infraredSensor1.proximityThreshold(InfraredSensorEvent.ObjectNear)
|
||||
, 1)
|
||||
})
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[set proximity threshold](/reference/sensors/infrared/set-proximity-threshold)
|
@ -0,0 +1,30 @@
|
||||
# proximity
|
||||
|
||||
Get the promixity of an object measured by the infrared sensor.
|
||||
|
||||
```sig
|
||||
sensors.infraredSensor1.proximity();
|
||||
```
|
||||
|
||||
The proximity value returned is a number between `0` and `100` which is a _relative_ measurment of distance to an object. A value of `0` means something is very close and `100` means something is far away. The proximity is determined by the amount of infrared light reflected back by an object. The proximity value for an object that has a lighter color and smooth surface will be less than an object at the same distance with a darker color and a rough surface.
|
||||
|
||||
Proximity isn't an actual measurement units of distance, like in centimeters or meters, but it gives you an idea whether something is close or not so close.
|
||||
|
||||
## Returns
|
||||
|
||||
* a [number](/types/number) that is `0` for (very near) to `100` (far). The value is relative to the range of the infrared sensor.
|
||||
|
||||
## Example
|
||||
|
||||
When the infrared sensor on port 4 detects a near object, display its proximity value on the screen.
|
||||
|
||||
```blocks
|
||||
sensors.infraredSensor4.onEvent(InfraredSensorEvent.ObjectNear, function () {
|
||||
brick.clearScreen()
|
||||
brick.showValue("proximity", sensors.infraredSensor4.proximity(), 1)
|
||||
})
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[on event](/reference/sensors/infrared/on-event), [pause until](/reference/sensors/infrared/pause-until)
|
@ -0,0 +1,35 @@
|
||||
# set Proximity Threshold
|
||||
|
||||
Set the proximity threshold for when objects are near or detected.
|
||||
|
||||
```sig
|
||||
sensors.infraredSensor1.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.infraredSensor1.setPromixityThreshold(InfraredSensorEvent.ObjectDetected, 30)
|
||||
sensors.infraredSensor1.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)
|
@ -83,7 +83,7 @@ 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
|
||||
//% help=sensors/beacon/is-pressed
|
||||
//% block="%button|is pressed"
|
||||
//% blockId=remoteButtonIsPressed
|
||||
//% parts="remote"
|
||||
@ -98,7 +98,7 @@ 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
|
||||
//% help=sensors/beacon/was-pressed
|
||||
//% block="%button|was pressed"
|
||||
//% blockId=remotebuttonWasPressed
|
||||
//% parts="remote"
|
||||
@ -110,12 +110,12 @@ 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
|
||||
//% help=sensors/beacon/on-event
|
||||
//% blockId=remotebuttonEvent block="on %button|%event"
|
||||
//% parts="remote"
|
||||
//% blockNamespace=sensors
|
||||
@ -126,10 +126,10 @@ 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
|
||||
//% help=sensors/beacon/pause-until
|
||||
//% blockId=remoteButtonPauseUntil block="pause until %button|%event"
|
||||
//% parts="remote"
|
||||
//% blockNamespace=sensors
|
||||
@ -181,10 +181,10 @@ 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
|
||||
//% help=sensors/infrared/on-event
|
||||
//% block="on %sensor|%event"
|
||||
//% blockId=infraredOn
|
||||
//% parts="infraredsensor"
|
||||
@ -197,9 +197,9 @@ namespace sensors {
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for the event to occur
|
||||
* Wait until the infrared sensor detects something
|
||||
*/
|
||||
//% help=input/ultrasonic/wait
|
||||
//% help=sensors/infrared/pause-until
|
||||
//% block="pause until %sensor| %event"
|
||||
//% blockId=infraredwait
|
||||
//% parts="infraredsensor"
|
||||
@ -215,7 +215,7 @@ namespace sensors {
|
||||
* Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)
|
||||
* @param sensor the infrared sensor
|
||||
*/
|
||||
//% help=input/infrared/proximity
|
||||
//% help=sensors/infrared/proximity
|
||||
//% block="%sensor|proximity"
|
||||
//% blockId=infraredGetProximity
|
||||
//% parts="infrared"
|
||||
@ -228,13 +228,14 @@ namespace sensors {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
//% group="Remote Infrared Beacon"
|
||||
//% help=sensors/beacon/set-remote-channel
|
||||
setRemoteChannel(channel: InfraredRemoteChannel) {
|
||||
this.setMode(InfraredSensorMode.RemoteControl)
|
||||
channel = Math.clamp(0, 3, channel | 0)
|
||||
@ -257,7 +258,7 @@ namespace sensors {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the threshold value
|
||||
* Get a threshold value
|
||||
* @param condition the proximity condition
|
||||
*/
|
||||
//% blockId=irGetThreshold block="%sensor|%condition"
|
||||
|
@ -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 () {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -20,7 +20,7 @@ Both **near** and **far** have distance thresholds set in centimeters. The **det
|
||||
> * ``object detected``: some other object is sending out an ultrasonic sound
|
||||
> * ``object near``: the sensor detected something within the distance of the near threshold
|
||||
> * ``object far``: the sensor detected somethin within the distance of the far threshold
|
||||
* **body**: the code you want to run when something happens to the touch sensor.
|
||||
* **body**: the code you want to run when something is dectected by the ultrasonic sensor.
|
||||
|
||||
## Example
|
||||
|
||||
|
@ -17,9 +17,9 @@ Both **near** and **far** have distance thresholds set in centimeters. The **det
|
||||
## Parameters
|
||||
|
||||
* **event**: the object detection action to wait for. The detection types (events) are:
|
||||
> * ``object detected``: some other object is sending out an ultrasonic sound
|
||||
> * ``object near``: the sensor detected something within the distance of the near threshold
|
||||
> * ``object far``: the sensor detected somethin within the distance of the far threshold
|
||||
> * ``detected``: some other object is sending out an ultrasonic sound
|
||||
> * ``near``: the sensor detected something within the distance of the near threshold
|
||||
> * ``far``: the sensor detected somethin within the distance of the far threshold
|
||||
|
||||
## Example
|
||||
|
||||
|
@ -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)
|
@ -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)
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-ev3",
|
||||
"version": "0.0.103",
|
||||
"version": "0.0.105",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-ev3",
|
||||
"version": "0.0.103",
|
||||
"version": "0.0.105",
|
||||
"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.7"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
||||
|
Reference in New Issue
Block a user