Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
2129601e6a | |||
e1727dc917 | |||
ecc9319334 | |||
81758f2555 | |||
7825bd1579 | |||
ac81067f82 | |||
b1958d77e7 | |||
232744520b | |||
ac9ebf6776 | |||
c97098b99e | |||
b39a7f3484 | |||
806f60a419 | |||
0bb7295d86 | |||
60bf3df1d8 | |||
b8a3fa345f | |||
ec1ceea138 | |||
b618bfec59 | |||
2467b3c4c9 | |||
69194b0b76 | |||
3339a7660a | |||
9c3be9fe37 | |||
c0413aa192 | |||
6c626f9c98 | |||
f95b39cd62 | |||
bba0af6193 | |||
a8a92ca806 |
@ -6,6 +6,15 @@
|
||||
* [Try](/getting-started/try)
|
||||
* [Use](/getting-started/use)
|
||||
|
||||
* [Tutorials](/tutorials)
|
||||
* [Wake Up!](/tutorials/wake-up)
|
||||
* [Make An Animation](/tutorials/make-an-animation)
|
||||
* [What Animal Am I?](/tutorials/what-animal-am-i)
|
||||
* [Music Brick](/tutorials/mindstorms-music)
|
||||
* [Run Motors](/tutorials/run-motors)
|
||||
* [Touch to Run](/tutorials/touch-to-run)
|
||||
* [Touch Sensor Values](/tutorials/touch-sensor-values)
|
||||
|
||||
* [Coding](/coding)
|
||||
* [Autonomous Parking](/coding/autonomous-parking)
|
||||
* [Object Detection](/coding/object-detection)
|
||||
@ -20,33 +29,6 @@
|
||||
* [Make a Sound Machine](/maker/sound-machine)
|
||||
* [Make a Security Gadget](/maker/security-gadget)
|
||||
|
||||
* [Examples](/examples)
|
||||
* [Make it move](/lessons/make-it-move)
|
||||
* [Line detection](/lessons/line-detection)
|
||||
* [Sound of Color](/maker/sound-of-color)
|
||||
* [Security Gadget](/maker/security-gadget)
|
||||
* [Intruder detector](/maker/intruder-detector)
|
||||
* [Puppet](/maker/puppet)
|
||||
* [Three Point Turn 1](/coding/three-point-turn-1)
|
||||
* [Three Point Turn 2](/coding/three-point-turn-2)
|
||||
* [Three Point Turn 3](/coding/three-point-turn-3)
|
||||
* [Reversing the robot 1](/coding/reversing-the-robot-1)
|
||||
* [Reversing the robot 2](/coding/reversing-the-robot-2)
|
||||
* [Reversing the robot 3](/coding/reversing-the-robot-3)
|
||||
* [Light the way 1](/coding/light-the-way-1)
|
||||
* [Light the way 2](/coding/light-the-way-2)
|
||||
* [Light the way 3](/coding/light-the-way-3)
|
||||
* [Traffic Lights 1](/coding/traffic-lights-1)
|
||||
* [Traffic Lights 2](/coding/traffic-lights-2)
|
||||
* [Traffic Lights 3](/coding/traffic-lights-3)
|
||||
* [Reverse Beeper 1](/coding/reverse-beeper-1)
|
||||
* [Reverse Beeper 2](/coding/reverse-beeper-2)
|
||||
* [Reverse Beeper 3](/coding/reverse-beeper-3)
|
||||
* [Ignition](/coding/ignition)
|
||||
* [Cruise Control](/coding/cruise-control)
|
||||
* [Roaming 1](/coding/roaming-1)
|
||||
* [Roaming 2](/coding/roaming-2)
|
||||
|
||||
## Reference #reference
|
||||
|
||||
* [Reference](/reference)
|
||||
@ -103,9 +85,9 @@
|
||||
* [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)
|
||||
* [pause until color detected](/reference/sensors/color-sensor/pause-until-color-detected)
|
||||
* [on light detected](/reference/sensors/color-sensor/on-light-detected)
|
||||
* [pause until light condition detected](/reference/sensors/color-sensor/pause-until-light-detected)
|
||||
* [color](/reference/sensors/color-sensor/color)
|
||||
* [light](/reference/sensors/color-sensor/ambient-light)
|
||||
* [Music](/reference/music)
|
||||
|
@ -22,7 +22,7 @@ Play some motor sounds if touch sensor `1` is pressed at the same moment when an
|
||||
|
||||
```blocks
|
||||
while (true) {
|
||||
if (sensors.touch1.wasPressed() &&
|
||||
if (sensors.touch1.isPressed() &&
|
||||
sensors.ultrasonic4.distance() < 10) {
|
||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
||||
@ -38,8 +38,8 @@ Play some motor sounds if touch sensor `1` is pressed when both the `enter` butt
|
||||
```blocks
|
||||
while (true) {
|
||||
if (sensors.ultrasonic4.distance() < 10 &&
|
||||
sensors.touch1.wasPressed() &&
|
||||
brick.buttonEnter.wasPressed()) {
|
||||
sensors.touch1.isPressed() &&
|
||||
brick.buttonEnter.isPressed()) {
|
||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Light the way Activity 1
|
||||
|
||||
```blocks
|
||||
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Dark, function () {
|
||||
sensors.color3.onLightDetected(LightIntensityMode.Ambient, Light.Dark, function () {
|
||||
brick.showImage(images.objectsLightOn)
|
||||
pause(5000)
|
||||
brick.clearScreen()
|
||||
|
@ -1,10 +1,10 @@
|
||||
# Light the way Activity 2
|
||||
|
||||
```blocks
|
||||
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Bright, function () {
|
||||
sensors.color3.onLightDetected(LightIntensityMode.Ambient, Light.Bright, function () {
|
||||
brick.clearScreen()
|
||||
})
|
||||
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Dark, function () {
|
||||
sensors.color3.onLightDetected(LightIntensityMode.Ambient, Light.Dark, function () {
|
||||
brick.showImage(images.objectsLightOn)
|
||||
})
|
||||
```
|
@ -1,10 +1,10 @@
|
||||
# Light the way Activity 3
|
||||
|
||||
```blocks
|
||||
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Bright, function () {
|
||||
sensors.color3.onLightDetected(LightIntensityMode.Ambient, Light.Bright, function () {
|
||||
brick.clearScreen()
|
||||
})
|
||||
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Dark, function () {
|
||||
sensors.color3.onLightDetected(LightIntensityMode.Ambient, Light.Dark, function () {
|
||||
brick.showImage(images.objectsLightOn)
|
||||
})
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
@ -54,7 +54,7 @@ loops.forever(function () {
|
||||
|
||||
})
|
||||
motors.largeBC.steer(0, 50)
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Red)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Red)
|
||||
motors.stopAll()
|
||||
```
|
||||
|
||||
@ -70,7 +70,7 @@ motors.stopAll()
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
motors.largeBC.steer(0, 50)
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Red)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Red)
|
||||
motors.stopAll()
|
||||
})
|
||||
```
|
||||
@ -94,9 +94,9 @@ Now add to your program and have your robot to drive forward again when the ligh
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
motors.largeBC.steer(0, 50)
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Red)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Red)
|
||||
motors.stopAll()
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Green)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Green)
|
||||
})
|
||||
```
|
||||
|
||||
@ -134,10 +134,10 @@ music.playSoundEffect(sounds.systemGeneralAlert)
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
motors.largeBC.steer(-30, 20)
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Black)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Black)
|
||||
music.playSoundEffect(sounds.systemGeneralAlert)
|
||||
motors.largeBC.steer(30, 20)
|
||||
sensors.color3.pauseForColor(ColorSensorColor.White)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.White)
|
||||
})
|
||||
```
|
||||
|
||||
@ -185,11 +185,11 @@ if (true) {
|
||||
```blocks
|
||||
forever(function () {
|
||||
while (true) {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Black)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Black)
|
||||
motors.largeBC.steer(-30, 50)
|
||||
}
|
||||
while (true) {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.White)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.White)
|
||||
motors.largeBC.steer(30, 50)
|
||||
}
|
||||
})
|
||||
@ -204,10 +204,10 @@ Else the Color Sensor detects the color white, start motors ``B`` and ``C`` (dri
|
||||
```blocks
|
||||
forever(function () {
|
||||
if (true) {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Black)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Black)
|
||||
motors.largeBC.steer(-30, 50)
|
||||
} else {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.White)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.White)
|
||||
motors.largeBC.steer(30, 50)
|
||||
}
|
||||
})
|
||||
|
@ -3,7 +3,7 @@
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
motors.largeBC.tank(20, 20)
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Red)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Red)
|
||||
motors.largeBC.tank(0, 0)
|
||||
})
|
||||
```
|
@ -6,7 +6,7 @@
|
||||
|
||||
Design, build and program a robot that can move itself using no wheels for locomotion.
|
||||
|
||||

|
||||

|
||||
|
||||
Your robot will:
|
||||
|
||||
|
@ -14,7 +14,7 @@ v = sensors.color3.light(LightIntensityMode.Reflected)
|
||||
min = v
|
||||
max = v
|
||||
setpoint = v
|
||||
while (!(brick.buttonEnter.wasPressed())) {
|
||||
while (!(brick.buttonEnter.isPressed())) {
|
||||
brick.clearScreen()
|
||||
brick.showString("Move robot on terrain", 1)
|
||||
brick.showString("Press ENTER when done", 2)
|
||||
|
@ -1,40 +0,0 @@
|
||||
|
||||
# Print Ports
|
||||
|
||||
```typescript
|
||||
/**
|
||||
* Print the port states on the screen
|
||||
*/
|
||||
//% blockId=brickPrintPorts block="print ports"
|
||||
//% help=brick/print-ports
|
||||
//% weight=1 group="Screen"
|
||||
function printPorts() {
|
||||
const col = 44;
|
||||
clearScreen();
|
||||
|
||||
function scale(x: number) {
|
||||
if (Math.abs(x) > 1000) return Math.round(x / 100) / 10 + "k";
|
||||
return ("" + (x >> 0));
|
||||
}
|
||||
|
||||
// motors
|
||||
const datas = motors.getAllMotorData();
|
||||
for(let i = 0; i < datas.length; ++i) {
|
||||
const data = datas[i];
|
||||
if (!data.actualSpeed && !data.count) continue;
|
||||
const x = i * col;
|
||||
print(`${scale(data.actualSpeed)}%`, x, brick.LINE_HEIGHT)
|
||||
print(`${scale(data.count)}>`, x, 2 * brick.LINE_HEIGHT)
|
||||
print(`${scale(data.tachoCount)}|`, x, 3 * brick.LINE_HEIGHT)
|
||||
}
|
||||
|
||||
// sensors
|
||||
const sis = sensors.internal.getActiveSensors();
|
||||
for(let i =0; i < sis.length; ++i) {
|
||||
const si = sis[i];
|
||||
const x = (si.port() - 1) * col;
|
||||
const v = si._query();
|
||||
print(`${scale(v)}`, x, 9 * brick.LINE_HEIGHT)
|
||||
}
|
||||
}
|
||||
```
|
@ -135,7 +135,7 @@ Keeping the Large Motor connected to **Port D**, connect the Color Sensor to **P
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Green)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Green)
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations)
|
||||
})
|
||||
```
|
||||
@ -143,7 +143,7 @@ brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
* Using the same program, replace the ``||sensors:pause until touch 1||`` block with a ``||sensors:pause color sensor 3||`` for color block.
|
||||
|
||||
```block
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Green)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Green)
|
||||
```
|
||||
|
||||
* Select the color you want to detect (e.g., green).
|
||||
|
@ -1,3 +1,3 @@
|
||||
{
|
||||
"appref": "v0"
|
||||
"appref": "v0.1.11"
|
||||
}
|
||||
|
@ -60,18 +60,18 @@ while (true) {
|
||||
|
||||
### Step 3
|
||||
|
||||
Place a ``||sensors:pause for color||`` from ``||sensors:Sensors||`` inside the ``||loops:while||`` loop block. Change the color to red.
|
||||
Place a ``||sensors:pause until color detected||`` from ``||sensors:Sensors||`` inside the ``||loops:while||`` loop block. Change the color to red.
|
||||
|
||||
```blocks
|
||||
motors.largeBC.steer(0, 20)
|
||||
while (true) {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Red)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Red)
|
||||
}
|
||||
```
|
||||
|
||||
### Step 4
|
||||
|
||||
Place a ``||motors:stop all motors||`` block under the ``||sensors:pause for color||`` block.
|
||||
Place a ``||motors:stop all motors||`` block under the ``||sensors:pause until color detected||`` block.
|
||||
|
||||
Study the program...what do you think the program will do?
|
||||
|
||||
@ -80,7 +80,7 @@ Study the program...what do you think the program will do?
|
||||
```blocks
|
||||
motors.largeBC.steer(0, 20)
|
||||
while (true) {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Red)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Red)
|
||||
motors.stopAll()
|
||||
}
|
||||
```
|
||||
@ -128,26 +128,26 @@ while (true) {
|
||||
|
||||
### Step 5
|
||||
|
||||
Place a ``||sensors:pause for color||`` block from ``||sensors:Sensors||`` inside the ``||loops:while||`` loop block. Change the color to red.
|
||||
Place a ``||sensors:pause until color detected||`` block from ``||sensors:Sensors||`` inside the ``||loops:while||`` loop block. Change the color to red.
|
||||
|
||||
```blocks
|
||||
while (true) {
|
||||
motors.largeBC.steer(0, 20)
|
||||
while (true) {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Red)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Red)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Step 6
|
||||
|
||||
Place a ``||motors:stop all motors||`` block under the ``||sensors:pause for color||`` block.
|
||||
Place a ``||motors:stop all motors||`` block under the ``||sensors:pause until color detected||`` block.
|
||||
|
||||
```blocks
|
||||
while (true) {
|
||||
motors.largeBC.steer(0, 20)
|
||||
while (true) {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Red)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Red)
|
||||
motors.stopAll()
|
||||
}
|
||||
}
|
||||
@ -161,7 +161,7 @@ Place a ``||loops:while||`` loop block under the second ``||loops:while||`` loop
|
||||
while (true) {
|
||||
motors.largeBC.steer(0, 20)
|
||||
while (true) {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Red)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Red)
|
||||
motors.stopAll()
|
||||
}
|
||||
while (true) {
|
||||
@ -172,7 +172,7 @@ while (true) {
|
||||
|
||||
### Step 8
|
||||
|
||||
Place a ``||sensors:pause for color||`` block inside the new ``||loops:while||`` loop block. Change the color to red.
|
||||
Place a ``||sensors:pause unril color detected||`` block inside the new ``||loops:while||`` loop block. Change the color to red.
|
||||
|
||||
What do you think the program will do?
|
||||
|
||||
@ -182,11 +182,11 @@ What do you think the program will do?
|
||||
while (true) {
|
||||
motors.largeBC.steer(0, 20)
|
||||
while (true) {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Red)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Red)
|
||||
motors.stopAll()
|
||||
}
|
||||
while (true) {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Red)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Red)
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -208,16 +208,17 @@ Think about what you have learned, then document it. Describe your pseudocode fo
|
||||
```blocks
|
||||
motors.largeBC.steer(0, 20)
|
||||
while (true) {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Yellow)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Yellow)
|
||||
music.playSoundEffect(sounds.systemGeneralAlert)
|
||||
}
|
||||
while (true) {
|
||||
while (true) { sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
while (true) {
|
||||
sensors.color3.pauseUntilLightDetected(LightIntensityMode.Reflected, Light.Bright)
|
||||
motors.largeB.run(10)
|
||||
motors.largeC.run(-10)
|
||||
}
|
||||
while (true) {
|
||||
sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
sensors.color3.pauseUntilLightDetected(LightIntensityMode.Reflected, Light.Bright)
|
||||
motors.largeA.run(-10)
|
||||
motors.largeA.run(10)
|
||||
}
|
||||
@ -234,12 +235,13 @@ You will need to constantly debug your program in order to make your robot trave
|
||||
|
||||
```blocks
|
||||
while (true) {
|
||||
while (true) { sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
while (true) {
|
||||
sensors.color3.pauseUntilLightDetected(LightIntensityMode.Reflected, Light.Bright)
|
||||
motors.largeB.run(10)
|
||||
motors.largeC.run(-10)
|
||||
}
|
||||
while (true) {
|
||||
sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
sensors.color3.pauseUntilLightDetected(LightIntensityMode.Reflected, Light.Bright)
|
||||
motors.largeB.run(-10)
|
||||
motors.largeC.run(10)
|
||||
}
|
||||
|
@ -1,139 +0,0 @@
|
||||
|
||||
# Make a Security Gadget
|
||||
|
||||
Invent a Security Gadget that will protect your belongings by warning you!
|
||||
|
||||

|
||||
|
||||
## Connect
|
||||
|
||||
Over time, people have come up with many different ways to help protect their personal belongings from theft. These inventions include simple alarm systems and even traps!
|
||||
|
||||

|
||||
|
||||
Look at the photos and think about:
|
||||
|
||||
* What do you see?
|
||||
* Can you see any new design opportunities?
|
||||
* What problems can you see?
|
||||
* How could you make use of the LEGO bricks, the EV3 Programmable Brick, motors, and sensors?
|
||||
|
||||
### Things You’ll Need
|
||||
|
||||
* [LEGO MINDSTORMS Education EV3 Core Set](https://education.lego.com/enus/products/legomindstormseducationev3coreset/5003400)
|
||||
|
||||
Additional materials to add to your Security Gadget:
|
||||
|
||||
* String
|
||||
* Arts and crafts materials such as:
|
||||
>* Cardboard
|
||||
>* Construction paper
|
||||
>* Pipe cleaners
|
||||
>* Plastic or paper cups
|
||||
>* Recycled materials
|
||||
>* Rubber bands
|
||||
>* Wire
|
||||
|
||||
### Prior Knowledge
|
||||
|
||||
This activity uses sensor inputs. You may want to try the [Use](/getting-started/use) or [Object Detection](/coding/object-detection) activity before this one. Or, you can start out with this activity and tinker with coding sensor inputs on your own.
|
||||
|
||||
## Contemplate
|
||||
|
||||
Follow the steps of the [Maker Design Process](/lessons/classroom-management#design-process) for this lesson:
|
||||
|
||||

|
||||
|
||||
### Defining the Problem
|
||||
|
||||
1. What problems did you imagine?
|
||||
2. Pick one problem and explain it to a partner.
|
||||
|
||||
### Brainstorm
|
||||
|
||||
Now that you have defined a problem, start to generate ideas for solving it.
|
||||
|
||||
### ~hint
|
||||
|
||||
Some things to do while brainstorming:
|
||||
|
||||
* Use the bricks from the LEGO set to help you brainstorm or sketch your ideas on paper.
|
||||
* The goal of brainstorming is to explore as many solutions as possible. You can use the tinkering examples in the Sample Solutions section below as inspiration for getting started.
|
||||
* Share your ideas and get some feedback. It may lead to more ideas!
|
||||
|
||||
### ~
|
||||
|
||||
### Define the Design Criteria
|
||||
|
||||
1. You should have generated a number of ideas. Now select the best one to make.
|
||||
2. Write out two or three specific design criteria your design must meet.
|
||||
|
||||
### Go Make
|
||||
|
||||
It is time to start making!
|
||||
|
||||
* Use the components from the LEGO® MINDSTORMS EV3 Core Set and additional materials to make your chosen solution.
|
||||
* Test and analyze your design as you go and record any improvements that you make.
|
||||
|
||||
### Review and Revise Your Solution
|
||||
|
||||
* Have you managed to solve the problem that you defined?
|
||||
* Look back at your design criteria. How well does your solution work?
|
||||
* How can you improve your design?
|
||||
|
||||
### Communicate Your Solution
|
||||
|
||||
Now that you have finished you can:
|
||||
|
||||
* Make a sketch or take a photo or video of your model.
|
||||
* Label the three most important parts and explain how they work.
|
||||
* Share your work with others.
|
||||
|
||||
## Continue
|
||||
|
||||
### Phone Protector - Sample Solution
|
||||
|
||||
This example program combined with the small model will sound an alarm if someone picks it up. The program activates an alarm when an object is lifted from the Touch Sensor.
|
||||
|
||||

|
||||
|
||||
#### Programming
|
||||
|
||||
1. Drag a ``||sensors:pause until touch||`` block and place it inside the ``||loops:forever||`` loop.
|
||||
2. Drag a ``||music:play sound effect||`` block and place it below the ``||sensors:pause until||`` block.
|
||||
3. Change the sound effect to ``mechanical horn1``.
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
music.playSoundEffect(sounds.mechanicalHorn1)
|
||||
})
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
### Object Detection - Sample Solution
|
||||
|
||||
This example program combined with the small model will sound an alarm if someone (or something) crosses its path! The program activates an alarm when an object moves in front of the Ultrasonic Sensor.
|
||||
|
||||

|
||||
|
||||
#### Programming
|
||||
|
||||
1. Drag a ``||sensors:pause until ultrasonic||`` block and place it inside the ``||loops:forever||`` loop.
|
||||
2. Drag a ``||music:play sound effect||`` block and place it below the ``||sensors:pause until||`` block.
|
||||
3. Change the sound effect to ``mechanical horn1``.
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectDetected)
|
||||
music.playSoundEffect(sounds.mechanicalHorn1)
|
||||
})
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
### Well done!
|
||||
|
||||
Click [here](/examples) to try out some more projects!
|
||||
|
@ -1,164 +0,0 @@
|
||||
# Make a Sound Machine
|
||||
|
||||
Make a Sound Machine that can play a rhythm, music or just noise!
|
||||
|
||||

|
||||
|
||||
## Connect
|
||||
|
||||
Music is made up of a combination of sounds, notes and rhythm. A rhythm is a regular movement or repeated pattern of movements that can be used in many different ways. In mechanical machines, a rhythm can help keep a machine running smoothly. It can also be used to generate different sounds in music.
|
||||
|
||||

|
||||
|
||||
Look at the photos and think about:
|
||||
|
||||
* What do you see?
|
||||
* Can you see any new design opportunities?
|
||||
* What problems can you see?
|
||||
* How could you make use of the LEGO bricks, the EV3 Programmable Brick, motors, and sensors?
|
||||
|
||||
### Things You’ll Need
|
||||
|
||||
* [LEGO MINDSTORMS Education EV3 Core Set](https://education.lego.com/enus/products/legomindstormseducationev3coreset/5003400)
|
||||
|
||||
Additional materials to add to your Sound Machine:
|
||||
|
||||
* Small musical instruments, such as chimes, bells, and small drums
|
||||
* Arts and crafts materials such as:
|
||||
>* Cardboard
|
||||
>* Construction paper
|
||||
>* Pipe cleaners
|
||||
>* Plastic or paper cups
|
||||
>* Recycled materials
|
||||
>* Rubber bands
|
||||
>* Wire
|
||||
|
||||
### Prior Knowledge
|
||||
|
||||
This activity uses motor rotations and sensor inputs. You may want to try the [Use](/getting-started/use) or [Object Detection](/coding/object-detection) activity before this one. Or, you can start out with this activity and tinker with coding motor and sensor inputs on your own.
|
||||
|
||||
## Contemplate
|
||||
|
||||
Follow the steps of the [Maker Design Process](/lessons/classroom-management#design-process) for this lesson:
|
||||
|
||||

|
||||
|
||||
### Defining the Problem
|
||||
|
||||
1. What problems did you imagine?
|
||||
2. Pick one problem and explain it to a partner.
|
||||
|
||||
### Brainstorm
|
||||
|
||||
Now that you have defined a problem, start to generate ideas for solving it.
|
||||
|
||||
### ~hint
|
||||
|
||||
Some things to do while brainstorming:
|
||||
|
||||
* Use the bricks from the LEGO set to help you brainstorm or sketch your ideas on paper.
|
||||
* The goal of brainstorming is to explore as many solutions as possible. You can use the tinkering examples in the Sample Solutions section below as inspiration for getting started.
|
||||
* Share your ideas and get some feedback. It may lead to more ideas!
|
||||
|
||||
### ~
|
||||
|
||||
### Define the Design Criteria
|
||||
|
||||
* You should have generated a number of ideas. Now select the best one to make.
|
||||
* Write out two or three specific design criteria your design must meet.
|
||||
|
||||
### Go Make
|
||||
|
||||
It is time to start making!
|
||||
|
||||
* Use the components from the LEGO® MINDSTORMS EV3 Core Set and additional materials to make your chosen solution.
|
||||
* Test and analyze your design as you go and record any improvements that you make.
|
||||
|
||||
### Review and Revise Your Solution
|
||||
|
||||
* Have you managed to solve the problem that you defined?
|
||||
* Look back at your design criteria. How well does your solution work?
|
||||
* How can you improve your design?
|
||||
|
||||
### Communicate Your Solution
|
||||
|
||||
Now that you have finished you can:
|
||||
* Make a sketch or take a photo or video of your model.
|
||||
* Label the three most important parts and explain how they work.
|
||||
* Share your work with others.
|
||||
|
||||
## Continue
|
||||
|
||||
### Rhythm Maker - Sample Solution
|
||||
|
||||
This example program combined with the small model will make a beat and rhythm on any surface when the program is run.
|
||||
|
||||

|
||||
|
||||
#### Programming
|
||||
|
||||
1. Drag a run ``||motors:large motor A||`` block inside the ``||loops:forever||`` loop.
|
||||
2. Press the **(+)**.
|
||||
3. Change the rotations to `2`.
|
||||
4. Drag a ``||loops:pause||`` block and place it under the motor block.
|
||||
5. Change the duration to ``200`` ms.
|
||||
6. Drag a ``||run large motor A||`` block inside the ``||loops:forever||`` loop.
|
||||
7. Press the **(+)**.
|
||||
8. Change the power to `100`.
|
||||
9. Change the rotations to `1`.
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
motors.largeA.run(50, 2, MoveUnit.Rotations)
|
||||
pause(200)
|
||||
motors.largeA.run(100, 1, MoveUnit.Rotations)
|
||||
})
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
### Color Sensor Sounds - Sample Solution
|
||||
|
||||
You can also tinker with the use of sensors.
|
||||
|
||||

|
||||
|
||||
#### Programming
|
||||
|
||||
1. Drag an ``||logic:if else||`` Logic block and place it inside the ``||loops:forever||`` loop.
|
||||
2. Drag a ``||sensors:pause color sensor||`` block and place it inside the ``||logic:if true then||`` block.
|
||||
3. Change the color to ``blue``.
|
||||
4. Drag a ``||music:play tone||`` block and place under the sensor block.
|
||||
5. Change the tone to ``Middle G`` (392 Hz).
|
||||
6. Drag a ``||sensors:pause color sensor||`` block and place it inside the ``||logic:else||`` block.
|
||||
7. Change the color to ``red``.
|
||||
8. Drag a ``||music:play tone||`` block and place under the new sensor block.
|
||||
9. Change the tone to ``High C`` (523 Hz).
|
||||
10. Press the **(+)**.
|
||||
11. Drag a ``||sensors:pause color sensor||`` block and place it inside the ``||logic:else if||`` block.
|
||||
12. Change the color to ``green``.
|
||||
13. Drag a ``||music:play tone||`` block and place under the new sensor block.
|
||||
14. Change the tone to ``High D`` (587 Hz).
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
if (true) {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Blue)
|
||||
music.playTone(392, music.beat(BeatFraction.Whole))
|
||||
} else if (false) {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Red)
|
||||
music.playTone(523, music.beat(BeatFraction.Half))
|
||||
} else {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Green)
|
||||
music.playTone(587, music.beat(BeatFraction.Half))
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
### Well done!
|
||||
|
||||
Click [here](/examples) to try out some more projects!
|
||||
|
||||
|
@ -143,13 +143,13 @@ You can also tinker with the use of sensors.
|
||||
```blocks
|
||||
forever(function () {
|
||||
if (true) {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Blue)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Blue)
|
||||
music.playTone(392, music.beat(BeatFraction.Whole))
|
||||
} else if (false) {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Red)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Red)
|
||||
music.playTone(523, music.beat(BeatFraction.Half))
|
||||
} else {
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Green)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Green)
|
||||
music.playTone(587, music.beat(BeatFraction.Half))
|
||||
}
|
||||
})
|
||||
|
@ -20,8 +20,8 @@ brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
});
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Bumped);
|
||||
brick.buttonEnter.isPressed()
|
||||
brick.buttonEnter.wasPressed()
|
||||
brick.setStatusLight(StatusLight.Red);
|
||||
brick.buttonEnter.wasPressed()
|
||||
```
|
||||
|
||||
## Other
|
||||
|
@ -14,7 +14,7 @@ The fact that a button was pressed earlier is remembered. Once **was pressed** i
|
||||
|
||||
Your @boardname@ has touch sensors that work like buttons. Instead of saying `enter` or `left` as the source button, use a touch sensor block with a sensor name like `touch 1`.
|
||||
|
||||
```block
|
||||
```typescript
|
||||
if (sensors.touch1.wasPressed()) {
|
||||
console.log("Hey, I was pressed.");
|
||||
}
|
||||
@ -32,7 +32,7 @@ Read about [touch sensors](/reference/sensors/touch-sensor) and using them as to
|
||||
|
||||
Set the brick light to green if the `right` button was pressed before the `left` button. If not, the brick light is turned off when the `left` button is pressed.
|
||||
|
||||
```blocks
|
||||
```typescript
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Bumped, function() {
|
||||
if (brick.buttonRight.wasPressed()) {
|
||||
brick.setStatusLight(StatusLight.Green)
|
||||
@ -45,6 +45,5 @@ brick.buttonLeft.onEvent(ButtonEvent.Bumped, function() {
|
||||
## See also
|
||||
|
||||
[is pressed](/reference/brick/button/is-pressed),
|
||||
[on event](/reference/brick/button/on-event)
|
||||
|
||||
[on event](/reference/brick/button/on-event),
|
||||
[Touch sensors](/reference/sensors/touch-sensor)
|
@ -4,9 +4,9 @@
|
||||
|
||||
```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.onLightDetected(LightIntensityMode.Reflected, Light.Dark, function () {})
|
||||
sensors.color1.pauseUntilLightDetected(LightIntensityMode.Reflected, Light.Dark)
|
||||
sensors.color1.pauseUntilColorDetected(ColorSensorColor.Blue)
|
||||
sensors.color1.color();
|
||||
sensors.color1.light(LightIntensityMode.Ambient)
|
||||
sensors.color(ColorSensorColor.Blue)
|
||||
@ -17,8 +17,8 @@ sensors.color(ColorSensorColor.Blue)
|
||||
```cards
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {})
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
sensors.touch1.wasPressed()
|
||||
sensors.touch1.isPressed()
|
||||
sensors.touch1.wasPressed()
|
||||
```
|
||||
|
||||
## Gyro
|
||||
|
Before Width: | Height: | Size: 49 KiB |
BIN
docs/static/lessons/make-it-move/make-it-move-without-wheels.png
vendored
Normal file
After Width: | Height: | Size: 115 KiB |
BIN
docs/static/tutorials/make-an-animation.png
vendored
Normal file
After Width: | Height: | Size: 68 KiB |
BIN
docs/static/tutorials/make-an-animation/button-pressed.gif
vendored
Normal file
After Width: | Height: | Size: 82 KiB |
BIN
docs/static/tutorials/mindstorms-music.png
vendored
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
docs/static/tutorials/mindstorms-music/play-tone-dropdown.png
vendored
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
docs/static/tutorials/mindstorms-music/press-my-buttons.png
vendored
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
docs/static/tutorials/run-motors.png
vendored
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
docs/static/tutorials/run-motors/on-button-dropdown.png
vendored
Normal file
After Width: | Height: | Size: 8.8 KiB |
BIN
docs/static/tutorials/run-motors/run-motor-dropdown.png
vendored
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
docs/static/tutorials/run-motors/run-motors.gif
vendored
Normal file
After Width: | Height: | Size: 509 KiB |
BIN
docs/static/tutorials/run-motors/run-speed-field.png
vendored
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
docs/static/tutorials/touch-sensor-values.png
vendored
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
docs/static/tutorials/touch-sensor-values/touch-to-stop.gif
vendored
Normal file
After Width: | Height: | Size: 240 KiB |
BIN
docs/static/tutorials/touch-to-run.png
vendored
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
docs/static/tutorials/touch-to-run/on-touch-dropdown.png
vendored
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
docs/static/tutorials/touch-to-run/touch-to-run.gif
vendored
Normal file
After Width: | Height: | Size: 169 KiB |
BIN
docs/static/tutorials/wake-up.png
vendored
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
docs/static/tutorials/wake-up/show-mood-dropdown-1.png
vendored
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
docs/static/tutorials/wake-up/show-mood-dropdown-2.png
vendored
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
docs/static/tutorials/wake-up/show-mood.gif
vendored
Normal file
After Width: | Height: | Size: 234 KiB |
BIN
docs/static/tutorials/what-animal-am-i.png
vendored
Normal file
After Width: | Height: | Size: 85 KiB |
BIN
docs/static/tutorials/what-animal-am-i/guess-animal.gif
vendored
Normal file
After Width: | Height: | Size: 207 KiB |
BIN
docs/static/tutorials/what-animal-am-i/on-button-dropdown.png
vendored
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
docs/static/tutorials/what-animal-am-i/play-sound-effect-dropdown.png
vendored
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
docs/static/tutorials/what-animal-am-i/show-image-dropdown.PNG
vendored
Normal file
After Width: | Height: | Size: 59 KiB |
BIN
docs/static/tutorials/what-color.png
vendored
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
docs/static/tutorials/what-color/color-detector.gif
vendored
Normal file
After Width: | Height: | Size: 74 KiB |
58
docs/tutorials.md
Normal file
@ -0,0 +1,58 @@
|
||||
# Tutorials
|
||||
|
||||
## Tutorials
|
||||
|
||||
Step by step guides to coding your @boardname@.
|
||||
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "Wake Up!",
|
||||
"description": "Show different moods on your @boardname@. Is it tired, sleepy, or awake?",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/wake-up",
|
||||
"imageUrl":"/static/tutorials/wake-up.png"
|
||||
}, {
|
||||
"name": "Make An Animation",
|
||||
"description": "Create a custom animation for your @boardname@.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/make-an-animation",
|
||||
"imageUrl":"/static/tutorials/make-an-animation.png"
|
||||
}, {
|
||||
"name": "What Animal Am I?",
|
||||
"description": "Create different animal sounds and have someone guess the what the animal is.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/what-animal-am-i",
|
||||
"imageUrl":"/static/tutorials/what-animal-am-i.png"
|
||||
}, {
|
||||
"name": "Music Brick",
|
||||
"description": "Transform your @boardname@ into a musical instrument!",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/mindstorms-music",
|
||||
"imageUrl":"/static/tutorials/mindstorms-music.png"
|
||||
}, {
|
||||
"name": "Run Motors",
|
||||
"description": "Use the buttons to start and stop the large and medium motors.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/run-motors",
|
||||
"imageUrl":"/static/tutorials/run-motors.png"
|
||||
}, {
|
||||
"name": "Touch to Run",
|
||||
"description": "Press the Touch sensor and run a motor.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/touch-to-run",
|
||||
"imageUrl":"/static/tutorials/touch-to-run.png"
|
||||
}, {
|
||||
"name": "Using Touch Sensor Values",
|
||||
"description": "Check the value of a Touch sensor and stop a motor if pressed.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/touch-sensor-values",
|
||||
"imageUrl":"/static/tutorials/touch-sensor-values.png"
|
||||
}, {
|
||||
"name": "What Color?",
|
||||
"description": "Use the Color sensor to detect different colors.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/what-color",
|
||||
"imageUrl":"/static/tutorials/what-color.png"
|
||||
}]
|
||||
```
|
61
docs/tutorials/make-an-animation.md
Normal file
@ -0,0 +1,61 @@
|
||||
# Make a custom animation
|
||||
|
||||
## Introduction @fullscreen
|
||||
|
||||
Create a custom animation for your @boardname@.
|
||||
|
||||

|
||||
|
||||
## Step 1
|
||||
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. Drag out a ``||brick:show string||`` block onto the Workspace, and drop it into the ``||loops:on Start||`` block. You should hear and see the block click into place.
|
||||
|
||||
```block
|
||||
brick.showString("Hello world", 1)
|
||||
```
|
||||
|
||||
## Step 2
|
||||
|
||||
In the ``||brick:show string||`` block, type the text ``"Press my button"`` to replace ``"Hello world"``.
|
||||
|
||||
```blocks
|
||||
brick.showString("Press my button!", 1)
|
||||
```
|
||||
|
||||
## Step 3
|
||||
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. Drag out an ``||brick:on button||`` block onto anyplace in the Workspace.
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
brick.showString("Press my button!", 1)
|
||||
```
|
||||
|
||||
## Step 4
|
||||
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. Drag out a ``||brick:show image||`` block onto the Workspace, and drop it into the ``||brick:on button||`` block.
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.expressionsBigSmile)
|
||||
})
|
||||
brick.showString("Press my button!", 1)
|
||||
```
|
||||
|
||||
## Step 5
|
||||
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. Drag out a ``||brick:set status light||`` block onto the Workspace, and drop it into the ``||brick:on button||`` block after the ``||brick:show image||`` block.
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.expressionsBigSmile)
|
||||
brick.setStatusLight(StatusLight.Orange)
|
||||
})
|
||||
brick.showString("Press my button!", 1)
|
||||
```
|
||||
|
||||
## Step 6
|
||||
|
||||
Now, let’s download our program to the brick. Plug your @boardname@ into the computer with the USB cable, and click the blue **Download** button in the bottom left of your screen. Follow the directions to save your program to the brick.
|
72
docs/tutorials/mindstorms-music.md
Normal file
@ -0,0 +1,72 @@
|
||||
# Music Brick
|
||||
|
||||
## Introduction @fullscreen
|
||||
|
||||
Transform your @boardname@ into a musical instrument!
|
||||
|
||||

|
||||
|
||||
|
||||
## Step 1
|
||||
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. From the **Screen** section, drag out a ``||brick:show string||`` block onto the Workspace, and drop it into the ``||loops:on start||`` block. You should hear and see the block click into place.
|
||||
|
||||
```blocks
|
||||
brick.showString("Hello world", 1)
|
||||
```
|
||||
|
||||
## Step 2
|
||||
|
||||
In the ``||brick:show string||`` block, type the text ``"Press my buttons to make music!"`` to replace ``"Hello world"``.
|
||||
|
||||
```blocks
|
||||
brick.showString("Press my buttons to make music!", 1)
|
||||
```
|
||||
|
||||
# Step 3
|
||||
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. From the **Buttons** section, drag out an ``||brick:on button||`` block onto the Workspace (you can put it anywhere).
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
brick.showString("Press my buttons to make music!", 1)
|
||||
```
|
||||
|
||||
## Step 4
|
||||
|
||||
Open the ``||music:Music||`` Toolbox drawer. Drag out **5** ``||music:play tone||`` blocks onto the Workspace, and drop them into the ``||brick:on button||`` block. **Note:** you can also right-click on a block and select "Duplicate" to copy blocks.
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
music.playTone(0, music.beat(BeatFraction.Half))
|
||||
music.playTone(0, music.beat(BeatFraction.Half))
|
||||
music.playTone(0, music.beat(BeatFraction.Half))
|
||||
music.playTone(0, music.beat(BeatFraction.Half))
|
||||
music.playTone(0, music.beat(BeatFraction.Half))
|
||||
})
|
||||
brick.showString("Press my buttons to make music!", 1)
|
||||
```
|
||||
|
||||
## Step 5
|
||||
|
||||
In the ``||music:play tone||`` blocks, use the drop-down menu to select a note to play for each block. You can also set the duration to play each note for.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
music.playTone(440, music.beat(BeatFraction.Half))
|
||||
music.playTone(494, music.beat(BeatFraction.Half))
|
||||
music.playTone(392, music.beat(BeatFraction.Half))
|
||||
music.playTone(196, music.beat(BeatFraction.Half))
|
||||
music.playTone(294, music.beat(BeatFraction.Whole))
|
||||
})
|
||||
brick.showString("Press my buttons to make music!", 1)
|
||||
```
|
||||
|
||||
## Step 6
|
||||
|
||||
Now, let’s download our program to the brick. Plug your @boardname@ into the computer with the USB cable, and click the blue **Download** button in the bottom left of your screen. Follow the directions to save your program to the brick. You can add more ``||brick:on button||`` blocks to the Workspace and create other ``||music:play tone||`` melodies when different buttons are pressed to transform your brick into a musical instrument!
|
||||
|
230
docs/tutorials/run-motors.md
Normal file
@ -0,0 +1,230 @@
|
||||
# Run motors
|
||||
|
||||
## Introduction @fullscreen
|
||||
|
||||
Use the buttons to start and stop the large and medium motors.
|
||||
|
||||

|
||||
|
||||
## Step 1
|
||||
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. Drag out **2** ``||brick:on button||`` blocks onto the Workspace (you can place these anywhere on the Workspace).
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
## Step 2
|
||||
|
||||
In the ``||brick:on button||`` blocks, use the drop-down menu to select the ``up`` and ``down`` buttons.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
## Step 3
|
||||
|
||||
Open the ``||motors:Motors||`` Toolbox drawer. Drag out **2** ``||motors:run||`` blocks onto the Workspace, and drop one of them each into the ``||brick:on button||`` blocks.
|
||||
|
||||
```blocks
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 4
|
||||
|
||||
The ``||motors:run||`` blocks specify which type of motor to run (Large or Medium), and which port the motor is attached to (Ports A, B, C, or D). The default setting is to run the large motor attached to port A at 50% speed. When we press the Down button, we want our motor to run in the reverse direction.
|
||||
|
||||
In the Run block that is in the On Button Down pressed block, change the speed value from ``50%`` to ``-50%``.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(-50)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 5
|
||||
|
||||
Now, let’s add a Medium motor, and specify how many rotations we want the motor to run for.
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. Drag out **2** ``|brick:on button||`` blocks onto the Workspace. In the ``||brick:on button||`` blocks, use the drop-down menu to select the ``left`` and ``right`` buttons.
|
||||
|
||||
```blocks
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(-50)
|
||||
})
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
## Step 6
|
||||
|
||||
Open the ``||motors:Motors||`` Toolbox drawer. Drag out **2** ``||motors:run||`` blocks onto the Workspace, and drop one of them each into the ``||brick:on button left||`` and ``||brick:on button right||`` blocks.
|
||||
|
||||
```blocks
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(-50)
|
||||
})
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 7
|
||||
|
||||
For the ``||motors:run||`` blocks that are in the ``||brick:on button left||`` and ``||brick:on button right||`` blocks, use the drop-down menu to select ``medium motor D``.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(-50)
|
||||
})
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.mediumD.run(50)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.mediumD.run(50)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 8
|
||||
|
||||
In the ``||motors:run medium motor||`` blocks, click on the plus icon **(+)** to expand the blocks. Change the number of rotations from `0` to `5`.
|
||||
|
||||
```blocks
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(-50)
|
||||
})
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.mediumD.run(50, 5, MoveUnit.Rotations)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.mediumD.run(50, 5, MoveUnit.Rotations)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 9
|
||||
|
||||
Let’s also change the speed that our Medium motors are running at. In the ``||motors:run medium motor||`` block that is in the ``||brick:on button left||`` block, change the speed from ``50%`` to ``10%``.
|
||||
|
||||
```blocks
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(-50)
|
||||
})
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.mediumD.run(10, 5, MoveUnit.Rotations)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.mediumD.run(50, 5, MoveUnit.Rotations)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 10
|
||||
|
||||
In the ``||motors:run medium motor||`` block that is in the ``||brick:on button right||`` block, change the speed from ``50%`` to ``100%``.
|
||||
|
||||
```blocks
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(-50)
|
||||
})
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.mediumD.run(10, 5, MoveUnit.Rotations)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.mediumD.run(100, 5, MoveUnit.Rotations)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 11
|
||||
|
||||
Finally, let’s add a way to stop all our motors from running. Open the ``||brick:Brick||`` Toolbox drawer. Drag out an ``||brick:on button||`` block onto the Workspace.
|
||||
|
||||
```blocks
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(-50)
|
||||
})
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.mediumD.run(10, 5, MoveUnit.Rotations)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.mediumD.run(100, 5, MoveUnit.Rotations)
|
||||
})
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
# Step 12
|
||||
|
||||
Open the ``||motors:Motors||`` Toolbox drawer. Drag out a ``||motors:stop all motors||`` block onto the Workspace, and drop into the ``||brick:on button||`` enter block.
|
||||
|
||||
```blocks
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(-50)
|
||||
})
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.mediumD.run(10, 5, MoveUnit.Rotations)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.mediumD.run(100, 5, MoveUnit.Rotations)
|
||||
})
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.stopAll()
|
||||
})
|
||||
```
|
||||
|
||||
## Step 13
|
||||
|
||||
Now, let’s download our program to the brick. Plug your @boardname@ into the computer with the USB cable, and click the blue **Download** button in the bottom left of your screen. Follow the directions to save your program to the brick. Attach a Large motor to Port A, and a Medium motor to Port D. Test your program by pressing the different buttons to see whether the correct motors are running as expected.
|
92
docs/tutorials/touch-sensor-values.md
Normal file
@ -0,0 +1,92 @@
|
||||
# Using Touch Sensor Values
|
||||
|
||||
## Introduction @fullscreen
|
||||
|
||||
Use the Touch sensor value to stop a running motor.
|
||||
|
||||

|
||||
|
||||
## Step 1
|
||||
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. Drag an ``||brick:on button||`` block onto the Workspace, and place it anywhere on the Workspace.
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
## Step 2
|
||||
|
||||
Open the ``||motors:Motors||`` Toolbox drawer. Drag out a ``||motors:run||`` block onto the Workspace, and drop it into the ``||brick:on button||`` block.
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 3
|
||||
|
||||
Open the ``||logic:Logic||`` Toolbox drawer. Drag out an ``||logic:if then||`` block onto the Workspace, and drop it into the ``||loops:forever||`` block.
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
if (true) {
|
||||
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## Step 4
|
||||
|
||||
Open the ``||sensors:Sensors||`` Toolbox drawer. Drag out a ``||sensors:touch is pressed||`` block onto the Workspace, and drop it in the ``||logic:if then||`` block replacing ``true``.
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
if (sensors.touch1.isPressed()) {
|
||||
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## Step 5
|
||||
|
||||
Open the ``||music:Music||`` Toolbox drawer. Drag out a ``||music:play sound effect||`` block onto the Workspace, and drop it under the ``||logic:if then||`` block.
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
if (sensors.touch1.isPressed()) {
|
||||
music.playSoundEffect(sounds.animalsCatPurr)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## Step 6
|
||||
|
||||
In the ``||music:play sound effect||`` block, use the drop-down menu to select the ``information touch`` sound effect.
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
if (sensors.touch1.isPressed()) {
|
||||
music.playSoundEffect(sounds.informationTouch)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## Step 7
|
||||
|
||||
Open the ``||motors:Motors||`` Toolbox drawer. Drag out a ``||motors:stop||`` block onto the Workspace, and drop it in after the ``||music:play sound effect||`` block.
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
if (sensors.touch1.isPressed()) {
|
||||
music.playSoundEffect(sounds.informationTouch)
|
||||
motors.largeA.stop()
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## Step 8
|
||||
|
||||
Now, let’s download our program to the brick. Plug your @boardname@ into the computer with the USB cable, and click the blue **Download** button in the bottom left of your screen. Follow the directions to save your program to the brick. Attach a Large motor to Port A, and a Touch sensor to Port 1 on your brick. Test your program by pressing the ENTER button. When the motor starts, press the touch sensor. Does the motor stop as expected?
|
65
docs/tutorials/touch-to-run.md
Normal file
@ -0,0 +1,65 @@
|
||||
# Touch to Run
|
||||
|
||||
## Introduction @fullscreen
|
||||
|
||||
Use the Touch sensor to run a motor.
|
||||
|
||||

|
||||
|
||||
## Step 1
|
||||
|
||||
Open the ``||sensors:Sensors||`` Toolbox drawer. Drag out **2** ``||sensors:on touch||`` blocks onto the Workspace (you can place these anywhere).
|
||||
|
||||
```blocks
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
## Step 2
|
||||
|
||||
In one of the ``||sensors:on touch||`` blocks, use the second drop-down menu to change from ``pressed`` to ``released``.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
sensors.touch1.onEvent(ButtonEvent.Released, function () {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
## Step 3
|
||||
|
||||
Open the ``||motors:Motors||`` Toolbox drawer. Drag out a ``||motors:run||`` block onto the Workspace, and drop it into the ``||brick:on touch pressed||`` block.
|
||||
|
||||
```blocks
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
sensors.touch1.onEvent(ButtonEvent.Released, function () {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
## Step 4
|
||||
|
||||
Open the ``||motors:Motors||`` Toolbox drawer. Drag out a ``||motors:stop||`` block onto the Workspace, and drop it into the ``||sensors:on touch released||`` block.
|
||||
|
||||
```blocks
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
sensors.touch1.onEvent(ButtonEvent.Released, function () {
|
||||
motors.largeA.stop()
|
||||
})
|
||||
```
|
||||
|
||||
## Step 5
|
||||
|
||||
Now, let’s download our program to the brick. Plug your @boardname@ into the computer with the USB cable, and click the blue **Download** button in the bottom left of your screen. Follow the directions to save your program to the brick. Attach a Large motor to Port A, and a Touch sensor to Port 1 on your brick. Test your program by pressing and releasing the touch sensor – does the motor start and stop as expected?
|
54
docs/tutorials/wake-up.md
Normal file
@ -0,0 +1,54 @@
|
||||
# Wake Up!
|
||||
|
||||
## Introduction @fullscreen
|
||||
|
||||
Show different moods on your @boardname@.
|
||||
|
||||

|
||||
|
||||
## Step 1
|
||||
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. Drag out a ``||brick:show mood||`` block onto the Workspace, and place it into the ``||loops:on start||`` block. You should hear and see the block click into place.
|
||||
|
||||
```blocks
|
||||
brick.showMood(moods.sleeping)
|
||||
```
|
||||
|
||||
## Step 2
|
||||
|
||||
Notice your brick is snoring with eyes closed in the simulator! Let’s wake her up. Open the ``||brick:Brick||`` Toolbox drawer again. Drag out 2 more ``||brick:show mood||`` blocks onto the Workspace, and drop them into the ``||brick:on start||`` block also.
|
||||
|
||||
```blocks
|
||||
brick.showMood(moods.sleeping)
|
||||
brick.showMood(moods.sleeping)
|
||||
brick.showMood(moods.sleeping)
|
||||
```
|
||||
|
||||
## Step 3
|
||||
|
||||
In the second ``||brick:show mood||`` block, click on the drop-down menu to select the tired mood.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
brick.showMood(moods.sleeping)
|
||||
brick.showMood(moods.tired)
|
||||
brick.showMood(moods.sleeping)
|
||||
```
|
||||
|
||||
## Step 4
|
||||
|
||||
In the third ``||brick:show mood||`` block, click on the drop-down menu to select the love mood.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
brick.showMood(moods.sleeping)
|
||||
brick.showMood(moods.tired)
|
||||
brick.showMood(moods.love)
|
||||
```
|
||||
|
||||
## Step 5
|
||||
|
||||
Now, let’s download our program to the brick. Plug your @boardname@ into the computer with the USB cable, and click the blue **Download** button in the bottom left of your screen. Follow the directions to save your program to the brick.
|
||||
|
163
docs/tutorials/what-animal-am-i.md
Normal file
@ -0,0 +1,163 @@
|
||||
# What Animal Am I?
|
||||
|
||||
## Introduction @fullscreen
|
||||
|
||||
Create different animal effects with your @boardname@.
|
||||
|
||||

|
||||
|
||||
## Step 1
|
||||
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. Drag out a ``||brick:show string||`` block from the **Screen** section onto the Workspace, and drop it into the ``||loops:on start||`` block. You should hear and see the block click into place.
|
||||
|
||||
```block
|
||||
brick.showString("Hello world", 1)
|
||||
```
|
||||
|
||||
## Step 2
|
||||
|
||||
In the ``||brick:show string||`` block, type the text ``"Guess what animal?"`` to replace ``"Hello world"``.
|
||||
|
||||
```blocks
|
||||
brick.showString("Guess what animal?", 1)
|
||||
```
|
||||
|
||||
## Step 3
|
||||
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. From the **Buttons** section, drag out an ``||brick:on button||`` block and put it anywhere in the Workspace.
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
brick.showString("Guess what animal?", 1)
|
||||
```
|
||||
|
||||
## Step 4
|
||||
|
||||
In the ``||brick:on button||`` block, use the drop-down menu to select the ``left`` button.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
brick.showString("Guess what animal?", 1)
|
||||
```
|
||||
|
||||
## Step 5
|
||||
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. In the **Buttons** section, drag out **3** more ``||brick:on button||`` blocks onto the Workspace. Using the drop-down menu, select the ``right``, ``up``, and ``down`` buttons for these 3 blocks.
|
||||
|
||||
```blocks
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
brick.showString("Guess what animal?", 1)
|
||||
```
|
||||
|
||||
## Step 6
|
||||
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. Drag out **4** ``||brick:show image||`` blocks onto the Workspace, and drop one of them into each of the ``||brick:on button||`` blocks.
|
||||
|
||||
```blocks
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.expressionsBigSmile)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.expressionsBigSmile)
|
||||
})
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.expressionsBigSmile)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.expressionsBigSmile)
|
||||
})
|
||||
brick.showString("Guess what animal?", 0)
|
||||
```
|
||||
|
||||
## Step 7
|
||||
|
||||
In the ``||brick:show image||`` blocks, use the drop-down menu to select a different image to show for each block.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.expressionsMouth2shut)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.expressionsMouth1open)
|
||||
})
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.objectsBoom)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.objectsPirate)
|
||||
})
|
||||
brick.showString("Guess what animal?", 0)
|
||||
```
|
||||
|
||||
## Step 8
|
||||
|
||||
Open the ``||music:Music||`` Toolbox drawer. Drag out **4** ``||music:play sound effect||`` blocks onto the Workspace, and drop one of them into each of the ``||brick:on button||`` blocks, just after the ``||brick:show image||`` block.
|
||||
|
||||
```blocks
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.expressionsMouth2shut)
|
||||
music.playSoundEffect(sounds.animalsCatPurr)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.expressionsMouth1open)
|
||||
music.playSoundEffect(sounds.animalsCatPurr)
|
||||
})
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.objectsBoom)
|
||||
music.playSoundEffect(sounds.animalsCatPurr)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.objectsPirate)
|
||||
music.playSoundEffect(sounds.animalsCatPurr)
|
||||
})
|
||||
brick.showString("Guess what animal?", 0)
|
||||
```
|
||||
|
||||
## Step 9
|
||||
|
||||
In each ``||music:play sound effect||`` block, use the drop-down menu to select a different animal sound to play.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.expressionsMouth2shut)
|
||||
music.playSoundEffect(sounds.animalsCatPurr)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.expressionsMouth1open)
|
||||
music.playSoundEffect(sounds.animalsDogBark1)
|
||||
})
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.objectsBoom)
|
||||
music.playSoundEffect(sounds.animalsElephantCall)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.objectsPirate)
|
||||
music.playSoundEffect(sounds.animalsSnakeHiss)
|
||||
})
|
||||
brick.showString("Guess what animal?", 0)
|
||||
```
|
||||
|
||||
## Step 10
|
||||
|
||||
Now, let’s download our program to the brick. Plug your @boardname@ into the computer with the USB cable, and click the blue **Download** button in the bottom left of your screen. Follow the directions to save your program to the brick. Test your program with a friend by pressing the right, left, up, and down buttons on your brick. Have your friend guess what animal it is!
|
134
docs/tutorials/what-color.md
Normal file
@ -0,0 +1,134 @@
|
||||
# What Color is it?
|
||||
|
||||
## Introduction @fullscreen
|
||||
|
||||
Use the Color sensor to detect different colors.
|
||||
|
||||

|
||||
|
||||
## Step 1
|
||||
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. From the **Screen** section, drag out a ``||brick:show string||`` block onto the Workspace, and drop it into the ``||loops:on start||`` block.
|
||||
|
||||
```blocks
|
||||
brick.showString("Hello world", 1)
|
||||
```
|
||||
|
||||
## Step 2
|
||||
|
||||
In the ``||brick:show string||`` block, type the text ``"What color?"`` replacing ``"Hello World"``.
|
||||
|
||||
```blocks
|
||||
brick.showString("What color?", 1)
|
||||
```
|
||||
|
||||
## Step 3
|
||||
|
||||
Open the ``||sensors:Sensors||`` Toolbox drawer. Drag out **3** ``||sensors:on color sensor detected||`` blocks onto the Workspace (you can place these anywhere).
|
||||
|
||||
```blocks
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Blue, function () {
|
||||
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Blue, function () {
|
||||
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Blue, function () {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
## Step 4
|
||||
|
||||
In the ``||sensors:on color sensor detected||`` blocks, use the second drop-down menu to select Red, Green, and Yellow colors.
|
||||
|
||||
```blocks
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Red, function () {
|
||||
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Green, function () {
|
||||
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Yellow, function () {
|
||||
|
||||
})
|
||||
brick.showString("What color?", 1)
|
||||
```
|
||||
|
||||
## Step 5
|
||||
|
||||
Open the ``||brick:Brick||`` Toolbox drawer. From the **Buttons** section, drag out a **3** ``||brick:set status light||`` blocks onto the Workspace, and drop one of them each into the ``||sensors:on color detected||`` blocks.
|
||||
|
||||
```blocks
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Red, function () {
|
||||
brick.setStatusLight(StatusLight.Orange)
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Green, function () {
|
||||
brick.setStatusLight(StatusLight.Orange)
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Yellow, function () {
|
||||
brick.setStatusLight(StatusLight.Orange)
|
||||
})
|
||||
brick.showString("What color?", 1)
|
||||
```
|
||||
|
||||
## Step 6
|
||||
|
||||
In the ``||brick:set status light||`` blocks, use the drop-down menu to change the lights to Red, Green, and Orange corresponding to the different colors detected. There is no Yellow status light, so we’ll use Orange instead.
|
||||
|
||||
```blocks
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Red, function () {
|
||||
brick.setStatusLight(StatusLight.Red)
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Green, function () {
|
||||
brick.setStatusLight(StatusLight.Green)
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Yellow, function () {
|
||||
brick.setStatusLight(StatusLight.Orange)
|
||||
})
|
||||
brick.showString("What color?", 1)
|
||||
```
|
||||
|
||||
## Step 7
|
||||
|
||||
Open the ``||music:Music||`` Toolbox drawer. Drag out **3** ``||music:play sound effect||`` blocks onto the Workspace, and drop one of them each into the ``||sensors:on color detected||`` blocks after the ``||brick:set status light||`` block.
|
||||
|
||||
```blocks
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Red, function () {
|
||||
brick.setStatusLight(StatusLight.Red)
|
||||
music.playSoundEffect(sounds.animalsCatPurr)
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Green, function () {
|
||||
brick.setStatusLight(StatusLight.Green)
|
||||
music.playSoundEffect(sounds.animalsCatPurr)
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Yellow, function () {
|
||||
brick.setStatusLight(StatusLight.Orange)
|
||||
music.playSoundEffect(sounds.animalsCatPurr)
|
||||
})
|
||||
brick.showString("What color?", 1)
|
||||
```
|
||||
|
||||
## Step 8
|
||||
|
||||
In the ``||music::play sound effect||`` blocks, use the drop-down menu to select the ``colors red``, ``colors green``, and ``colors yellow`` sound effects corresponding to the different colors detected.
|
||||
|
||||
```blocks
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Red, function () {
|
||||
brick.setStatusLight(StatusLight.Red)
|
||||
music.playSoundEffect(sounds.colorsRed)
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Green, function () {
|
||||
brick.setStatusLight(StatusLight.Green)
|
||||
music.playSoundEffect(sounds.colorsGreen)
|
||||
})
|
||||
sensors.color3.onColorDetected(ColorSensorColor.Yellow, function () {
|
||||
brick.setStatusLight(StatusLight.Orange)
|
||||
music.playSoundEffect(sounds.colorsYellow)
|
||||
})
|
||||
brick.showString("What color?", 1)
|
||||
```
|
||||
|
||||
## Step 9
|
||||
|
||||
Now, let’s download our program to the brick. Plug your @boardname@ into the computer with the USB cable, and click the blue **Download** button in the bottom left of your screen. Follow the directions to save your program to the brick. Attach a Color Sensor to Port 3 of your brick. Test your program by flashing Red, Green and Yellow colored paper or use LEGO bricks in front of the Color Sensor.
|
@ -37,7 +37,7 @@ const enum ColorSensorColor {
|
||||
Brown
|
||||
}
|
||||
|
||||
enum LightCondition {
|
||||
enum Light {
|
||||
//% block="dark"
|
||||
Dark = sensors.ThresholdState.Low,
|
||||
//% block="bright"
|
||||
@ -145,15 +145,15 @@ namespace sensors {
|
||||
* Waits for the given color to be detected
|
||||
* @param color the color to detect
|
||||
*/
|
||||
//% help=sensors/color-sensor/pause-for-color
|
||||
//% block="pause **color sensor** %this|for %color=colorEnumPicker"
|
||||
//% blockId=colorPauseForColorDetected
|
||||
//% help=sensors/color-sensor/pause-until-color-detected
|
||||
//% block="pause until **color sensor** %this|detected %color=colorEnumPicker"
|
||||
//% blockId=colorpauseUntilColorDetectedDetected
|
||||
//% parts="colorsensor"
|
||||
//% blockNamespace=sensors
|
||||
//% this.fieldEditor="ports"
|
||||
//% weight=99 blockGap=8
|
||||
//% group="Color Sensor"
|
||||
pauseForColor(color: number) {
|
||||
pauseUntilColorDetected(color: number) {
|
||||
this.setMode(ColorSensorMode.Color);
|
||||
if (this.color() != color) {
|
||||
const v = this._colorEventValue(<number>color);
|
||||
@ -184,15 +184,15 @@ namespace sensors {
|
||||
* @param condition the light condition
|
||||
* @param handler the code to run when detected
|
||||
*/
|
||||
//% help=sensors/color-sensor/on-light-changed
|
||||
//% block="on **color sensor** %this|%mode|%condition"
|
||||
//% blockId=colorOnLightChanged
|
||||
//% help=sensors/color-sensor/on-light-detected
|
||||
//% block="on **color sensor** %this|detected %mode|%condition"
|
||||
//% blockId=colorOnLightDetected
|
||||
//% parts="colorsensor"
|
||||
//% blockNamespace=sensors
|
||||
//% this.fieldEditor="ports"
|
||||
//% weight=89 blockGap=12
|
||||
//% group="Color Sensor"
|
||||
onLightChanged(mode: LightIntensityMode, condition: LightCondition, handler: () => void) {
|
||||
onLightDetected(mode: LightIntensityMode, condition: Light, handler: () => void) {
|
||||
this.setMode(<ColorSensorMode><number>mode)
|
||||
control.onEvent(this._id, <number>condition, handler);
|
||||
}
|
||||
@ -201,15 +201,15 @@ namespace sensors {
|
||||
* Wait for the given color to be detected
|
||||
* @param color the color to detect
|
||||
*/
|
||||
//% help=sensors/color-sensor/pause-for-light
|
||||
//% block="pause **color sensor** %this|for %mode|%condition"
|
||||
//% blockId=colorPauseForLight
|
||||
//% help=sensors/color-sensor/pause-until-light-detected
|
||||
//% block="pause until **color sensor** %this|detected %mode|%condition"
|
||||
//% blockId=colorPauseUntilLightDetected
|
||||
//% parts="colorsensor"
|
||||
//% blockNamespace=sensors
|
||||
//% this.fieldEditor="ports"
|
||||
//% weight=88 blockGap=8
|
||||
//% group="Color Sensor"
|
||||
pauseForLight(mode: LightIntensityMode, condition: LightCondition) {
|
||||
pauseUntilLightDetected(mode: LightIntensityMode, condition: Light) {
|
||||
this.setMode(<ColorSensorMode><number>mode)
|
||||
if (this.thresholdDetector.state != <number>condition)
|
||||
control.waitForEvent(this._id, <number>condition)
|
||||
@ -252,8 +252,8 @@ namespace sensors {
|
||||
//% value.min=0 value.max=100
|
||||
//% this.fieldEditor="ports"
|
||||
//% help=sensors/color-sensor/set-threshold
|
||||
setThreshold(condition: LightCondition, value: number) {
|
||||
if (condition == LightCondition.Dark)
|
||||
setThreshold(condition: Light, value: number) {
|
||||
if (condition == Light.Dark)
|
||||
this.thresholdDetector.setLowThreshold(value)
|
||||
else
|
||||
this.thresholdDetector.setHighThreshold(value);
|
||||
@ -267,8 +267,8 @@ namespace sensors {
|
||||
//% group="Threshold" blockGap=8 weight=89
|
||||
//% this.fieldEditor="ports"
|
||||
//% help=sensors/color-sensor/threshold
|
||||
threshold(condition: LightCondition): number {
|
||||
return this.thresholdDetector.threshold(<ThresholdState><number>LightCondition.Dark);
|
||||
threshold(condition: Light): number {
|
||||
return this.thresholdDetector.threshold(<ThresholdState><number>Light.Dark);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
```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.onLightDetected(LightIntensityMode.Reflected, Light.Dark, function () {})
|
||||
sensors.color1.pauseUntilLightDetected(LightIntensityMode.Reflected, Light.Dark)
|
||||
sensors.color1.pauseUntilColorDetected(ColorSensorColor.Blue)
|
||||
sensors.color1.color();
|
||||
sensors.color1.light(LightIntensityMode.Ambient)
|
||||
```
|
||||
@ -12,8 +12,8 @@ sensors.color1.light(LightIntensityMode.Ambient)
|
||||
## 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),
|
||||
[pause until color detected](/reference/sensors/color-sensor/pause-until-color-detected),
|
||||
[on light detected](/reference/sensors/color-sensor/on-light-detected),
|
||||
[pause until light detected](/reference/sensors/color-sensor/pause-until-light-detected),
|
||||
[color](/reference/sensors/color-sensor/color),
|
||||
[light](/reference/sensors/color-sensor/ambient-light)
|
||||
|
@ -24,4 +24,4 @@ sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {
|
||||
```
|
||||
## See also
|
||||
|
||||
[pause for color](/reference/sensors/color-sensor/pause-for-color), [color](/reference/sensors/color)
|
||||
[pause until color detected](/reference/sensors/color-sensor/pause-until-color-detected), [color](/reference/sensors/color)
|
@ -3,7 +3,7 @@
|
||||
Run some code when the amount of light dectected changes.
|
||||
|
||||
```sig
|
||||
sensors.color1.onLightChanged(LightIntensityMode.Reflected, LightCondition.Dark, function () {
|
||||
sensors.color1.onLightDetected(LightIntensityMode.Reflected, Light.Dark, function () {
|
||||
|
||||
})
|
||||
```
|
||||
@ -21,7 +21,7 @@ You can check for a change in either _ambient_ or _reflected_ light and run some
|
||||
Show a message on the screen when the ambient light goes dark.
|
||||
|
||||
```blocks
|
||||
sensors.color1.onLightChanged(LightIntensityMode.Ambient, LightCondition.Dark, function() {
|
||||
sensors.color1.onLightDetected(LightIntensityMode.Ambient, Light.Dark, function() {
|
||||
brick.clearScreen();
|
||||
brick.showString("It just got dark", 1)
|
||||
brick.showString("Can you see me?", 2)
|
@ -1,9 +1,9 @@
|
||||
# pause For Color
|
||||
# pause Until Color Detected
|
||||
|
||||
Wait for the sensor to see a certain color.
|
||||
|
||||
```sig
|
||||
sensors.color1.pauseForColor(ColorSensorColor.Blue)
|
||||
sensors.color1.pauseUntilColorDetected(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.
|
||||
@ -18,7 +18,7 @@ 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)
|
||||
sensors.color1.pauseUntilColorDetected(ColorSensorColor.Blue)
|
||||
brick.clearScreen()
|
||||
brick.showImage(images.expressionsSick)
|
||||
```
|
@ -1,9 +1,9 @@
|
||||
# pause For Light
|
||||
# pause Until Light Condition Detected
|
||||
|
||||
Wait for the light condition to change.
|
||||
Wait until a particular light condition is detected.
|
||||
|
||||
```sig
|
||||
sensors.color1.pauseForLight(LightIntensityMode.Reflected, LightCondition.Dark)
|
||||
sensors.color1.pauseUntilLightDetected(LightIntensityMode.Reflected, Light.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.
|
||||
@ -19,11 +19,11 @@ 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)
|
||||
sensors.color1.pauseUntilLightDetected(LightIntensityMode.Reflected, Light.Dark)
|
||||
brick.clearScreen()
|
||||
brick.showImage(images.expressionsSick)
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[on light changed](/reference/sensors/color-sensor/on-light-changed)
|
||||
[on light detected](/reference/sensors/color-sensor/on-light-detected)
|
@ -3,7 +3,7 @@
|
||||
Set the threshold value for dark or bright light.
|
||||
|
||||
```sig
|
||||
sensors.color1.setThreshold(LightCondition.Dark, 0)
|
||||
sensors.color1.setThreshold(Light.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.
|
||||
@ -11,8 +11,8 @@ Light intensity is measured from `0` (very dark) to `100` (very bright). You can
|
||||
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 () {
|
||||
sensors.color1.setThreshold(Light.Dark, 20)
|
||||
sensors.color1.onLightDetected(LightIntensityMode.Reflected, Light.Dark, function () {
|
||||
brick.showMood(moods.sleeping)
|
||||
})
|
||||
```
|
||||
@ -27,8 +27,8 @@ sensors.color1.onLightChanged(LightIntensityMode.Reflected, LightCondition.Dark,
|
||||
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 () {
|
||||
sensors.color3.setThreshold(Light.Bright, 70)
|
||||
sensors.color3.onLightDetected(LightIntensityMode.Ambient, Light.Bright, function () {
|
||||
brick.setStatusLight(StatusLight.GreenFlash)
|
||||
for (let i = 0; i < 5; i++) {
|
||||
music.playSoundEffectUntilDone(sounds.mechanicalBackingAlert)
|
||||
|
@ -3,7 +3,7 @@
|
||||
Get the threshold value for dark or bright light.
|
||||
|
||||
```sig
|
||||
sensors.color1.threshold(LightCondition.Dark)
|
||||
sensors.color1.threshold(Light.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`.
|
||||
@ -17,8 +17,8 @@ Light intensity is measured from `0` (very dark) to `100` (very bright). A _thre
|
||||
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)
|
||||
sensors.color3.onLightDetected(LightIntensityMode.Reflected, Light.Dark, function () {
|
||||
brick.showValue("DarknessThresholdValue", sensors.color3.threshold(Light.Dark), 1)
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -95,6 +95,7 @@ namespace brick {
|
||||
//% help=brick/button/was-pressed
|
||||
//% block="%button|was pressed"
|
||||
//% blockId=buttonWasPressed
|
||||
//% blockHidden=true
|
||||
//% parts="brick"
|
||||
//% blockNamespace=brick
|
||||
//% weight=80
|
||||
|
@ -59,7 +59,6 @@ namespace console {
|
||||
|
||||
namespace console._screen {
|
||||
const maxLines = 100;
|
||||
const screenLines = 10;
|
||||
let lines: string[];
|
||||
let scrollPosition = 0;
|
||||
|
||||
@ -75,10 +74,11 @@ namespace console._screen {
|
||||
function printLog() {
|
||||
brick.clearScreen()
|
||||
if (!lines) return;
|
||||
const screenLines = brick.lineCount();
|
||||
for (let i = 0; i < screenLines; ++i) {
|
||||
const line = lines[i + scrollPosition];
|
||||
if (line)
|
||||
screen.print(line, 0, 4 + i * brick.LINE_HEIGHT)
|
||||
screen.print(line, 0, 4 + i * brick.lineHeight(), 1, brick.font)
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,6 +98,7 @@ namespace console._screen {
|
||||
scrollPosition = Math.min(scrollPosition, lines.length - 1)
|
||||
}
|
||||
// move down scroll once it gets large than the screen
|
||||
const screenLines = brick.lineCount();
|
||||
if (lines.length > screenLines
|
||||
&& lines.length >= scrollPosition + screenLines) {
|
||||
scrollPosition++;
|
||||
|
@ -164,7 +164,7 @@ namespace motors {
|
||||
*/
|
||||
//% blockId=outputMotorSetBrakeMode block="set %motor|brake %brake=toggleOnOff"
|
||||
//% weight=60 blockGap=8
|
||||
//% group="Move"
|
||||
//% group="Properties"
|
||||
//% help=motors/motor/set-brake
|
||||
setBrake(brake: boolean) {
|
||||
this.init();
|
||||
@ -176,7 +176,7 @@ namespace motors {
|
||||
*/
|
||||
//% blockId=motorSetInverted block="set %motor|inverted %reversed=toggleOnOff"
|
||||
//% weight=59 blockGap=8
|
||||
//% group="Move"
|
||||
//% group="Properties"
|
||||
//% help=motors/motor/set-inverted
|
||||
setInverted(inverted: boolean) {
|
||||
this.init();
|
||||
@ -344,7 +344,7 @@ namespace motors {
|
||||
*/
|
||||
//% blockId=outputMotorSetRegulated block="set %motor|regulated %value=toggleOnOff"
|
||||
//% weight=58
|
||||
//% group="Move"
|
||||
//% group="Properties"
|
||||
//% help=motors/motor/set-regulated
|
||||
setRegulated(value: boolean) {
|
||||
this._regulated = value;
|
||||
|
@ -13,7 +13,7 @@ namespace sensors {
|
||||
}
|
||||
|
||||
//% color="#00852B" weight=90 icon="\uf10d"
|
||||
//% groups='["Move", "Counters"]'
|
||||
//% groups='["Move", "Counters", "Properties"]'
|
||||
//% labelLineWidth=50
|
||||
namespace motors {
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ In order to recognize a button event signalled from a remote beacon, an infrared
|
||||
|
||||
If the beacon button ``top left`` was pressed, show a `green` status light. Otherwise, set the status light to `orange`.
|
||||
|
||||
```blocks
|
||||
```typescript
|
||||
sensors.infrared1.setRemoteChannel(InfraredRemoteChannel.Ch0)
|
||||
forever(function () {
|
||||
if (sensors.remoteButtonTopLeft.wasPressed()) {
|
||||
|
@ -101,6 +101,7 @@ namespace sensors {
|
||||
//% help=sensors/beacon/was-pressed
|
||||
//% block="**remote button** %button|was pressed"
|
||||
//% blockId=remotebuttonWasPressed
|
||||
//% blockHidden=true
|
||||
//% parts="remote"
|
||||
//% blockNamespace=sensors
|
||||
//% weight=80
|
||||
@ -278,7 +279,7 @@ namespace sensors {
|
||||
//% group="Threshold" blockGap=8 weight=49
|
||||
//% this.fieldEditor="ports"
|
||||
proximityThreshold(condition: InfraredSensorEvent): number {
|
||||
return this._proximityThreshold.threshold(<ThresholdState><number>LightCondition.Dark);
|
||||
return this._proximityThreshold.threshold(<ThresholdState><number>Light.Dark);
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
3
libs/music/docs/reference/music/play-sound-until-done.md
Normal file
@ -0,0 +1,3 @@
|
||||
# play Sound Until Done
|
||||
|
||||
This function is not enabled for @boardname@.
|
3
libs/music/docs/reference/music/play-sound.md
Normal file
@ -0,0 +1,3 @@
|
||||
# play Sound
|
||||
|
||||
This function is not enabled for @boardname@.
|
3
libs/music/docs/reference/music/sounds.md
Normal file
@ -0,0 +1,3 @@
|
||||
# sounds
|
||||
|
||||
This function is not enabled for @boardname@.
|
@ -136,8 +136,8 @@ void playSample(Buffer buf) {
|
||||
|
||||
/**
|
||||
* Play a tone through the speaker for some amount of time.
|
||||
* @param frequency pitch of the tone to play in Hertz (Hz)
|
||||
* @param ms tone duration in milliseconds (ms)
|
||||
* @param frequency pitch of the tone to play in Hertz (Hz), eg: Note.C
|
||||
* @param ms tone duration in milliseconds (ms), eg: BeatFraction.Half
|
||||
*/
|
||||
//% help=music/play-tone
|
||||
//% blockId=music_play_note block="play tone|at %note=device_note|for %duration=device_beat"
|
||||
|
4
libs/music/shims.d.ts
vendored
@ -15,8 +15,8 @@ declare namespace music {
|
||||
|
||||
/**
|
||||
* Play a tone through the speaker for some amount of time.
|
||||
* @param frequency pitch of the tone to play in Hertz (Hz)
|
||||
* @param ms tone duration in milliseconds (ms)
|
||||
* @param frequency pitch of the tone to play in Hertz (Hz), eg: Note.C
|
||||
* @param ms tone duration in milliseconds (ms), eg: BeatFraction.Half
|
||||
*/
|
||||
//% help=music/play-tone
|
||||
//% blockId=music_play_note block="play tone|at %note=device_note|for %duration=device_beat"
|
||||
|
7
libs/screen/fieldeditors.ts
Normal file
@ -0,0 +1,7 @@
|
||||
declare namespace images {
|
||||
//% blockHidden=1
|
||||
function _spriteImage(img: Image) : Image;
|
||||
|
||||
//% blockHidden=1
|
||||
function _image(image: Image): Image;
|
||||
}
|
@ -14,28 +14,51 @@ namespace _screen_internal {
|
||||
function updateStats(msg: string): void { }
|
||||
|
||||
control.__screen.setupUpdate(() => updateScreen(screen))
|
||||
control.EventContext.onStats = function(msg: string) {
|
||||
control.EventContext.onStats = function (msg: string) {
|
||||
updateStats(msg);
|
||||
}
|
||||
}
|
||||
|
||||
namespace brick {
|
||||
export const LINE_HEIGHT = 12;
|
||||
const textOffset = 4;
|
||||
const lineOffset = 2;
|
||||
export let font = image.font8;
|
||||
|
||||
/**
|
||||
* Gets the text line height
|
||||
*/
|
||||
//%
|
||||
export function lineHeight(): number {
|
||||
return font.charHeight + lineOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of lines
|
||||
*/
|
||||
//%
|
||||
export function lineCount(): number {
|
||||
return ((screen.height - textOffset) / lineHeight()) >> 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Show text on the screen at a specific line.
|
||||
* @param text the text to print on the screen, eg: "Hello world"
|
||||
* @param line the line number to print the text at, eg: 1
|
||||
* @param line the line number to print the text at (starting at 1), eg: 1
|
||||
*/
|
||||
//% blockId=screen_print block="show string %text|at line %line"
|
||||
//% weight=98 group="Screen" inlineInputMode="inline" blockGap=8
|
||||
//% help=brick/show-string
|
||||
//% line.min=1 line.max=10
|
||||
export function showString(text: string, line: number) {
|
||||
const NUM_LINES = 9;
|
||||
const offset = 5;
|
||||
const y = offset + (Math.clamp(0, NUM_LINES, line - 1) / (NUM_LINES + 2)) * DAL.LCD_HEIGHT;
|
||||
screen.print(text, offset, y);
|
||||
// line indexing starts at 1.
|
||||
line = (line - 1) >> 0;
|
||||
const nlines = lineCount();
|
||||
if (line < 0 || line > nlines) return; // out of screen
|
||||
|
||||
const h = lineHeight();
|
||||
const y = textOffset + h * line;
|
||||
screen.fillRect(0, y, screen.width, h, 0); // clear background
|
||||
screen.print(text, textOffset, y, 1, font);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,6 +108,7 @@ namespace brick {
|
||||
//% weight=10 group="Screen"
|
||||
export function showPorts() {
|
||||
const col = 44;
|
||||
const lineHeight8 = image.font8.charHeight + 2;
|
||||
clearScreen();
|
||||
|
||||
function scale(x: number) {
|
||||
@ -98,19 +122,22 @@ namespace brick {
|
||||
const data = datas[i];
|
||||
if (!data.actualSpeed && !data.count) continue;
|
||||
const x = i * col;
|
||||
screen.print("ABCD"[i], x, brick.LINE_HEIGHT)
|
||||
screen.print(`${scale(data.actualSpeed)}%`, x, 2* brick.LINE_HEIGHT)
|
||||
screen.print(`${scale(data.count)}>`, x, 3 * brick.LINE_HEIGHT)
|
||||
screen.print("ABCD"[i], x + 2, 1 * lineHeight8, 1, image.font8)
|
||||
screen.print(`${scale(data.actualSpeed)}%`, x + 2, 3 * lineHeight8, 1, image.font8)
|
||||
screen.print(`${scale(data.count)}>`, x + 2, 4 * lineHeight8, 1, image.font5)
|
||||
}
|
||||
screen.drawLine(0, 5 * lineHeight8, screen.width, 5 * lineHeight8, 1);
|
||||
|
||||
// sensors
|
||||
const sis = sensors.internal.getActiveSensors();
|
||||
const h = screen.height;
|
||||
screen.drawLine(0, h - 5 * lineHeight8, screen.width, h - 5 * lineHeight8, 1)
|
||||
for (let i = 0; i < sis.length; ++i) {
|
||||
const si = sis[i];
|
||||
const x = (si.port() - 1) * col;
|
||||
const inf = si._info();
|
||||
screen.print(si.port() + "", x, 8 * brick.LINE_HEIGHT)
|
||||
screen.print(inf, x, 9 * brick.LINE_HEIGHT)
|
||||
screen.print(si.port() + "", x, h - 4 * lineHeight8, 1, image.font8)
|
||||
screen.print(inf, x, h - 2 * lineHeight8, 1, inf.length > 4 ? image.font5 : image.font8);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ If a touch sensor was pressed, then that event is remembered. Once you check if
|
||||
|
||||
If the touch sensor ``touch 1`` was pressed, show a `green` status light. Otherwise, set the status light to `orange`.
|
||||
|
||||
```blocks
|
||||
```typescript
|
||||
forever(function () {
|
||||
if (sensors.touch1.wasPressed()) {
|
||||
brick.setStatusLight(StatusLight.Green)
|
||||
|
@ -83,6 +83,7 @@ namespace sensors {
|
||||
//% help=sensors/touch-sensor/was-pressed
|
||||
//% block="**touch** %this|was pressed"
|
||||
//% blockId=touchWasPressed
|
||||
//% blockHidden=true
|
||||
//% parts="touch"
|
||||
//% blockNamespace=sensors
|
||||
//% this.fieldEditor="ports"
|
||||
|
@ -3,7 +3,9 @@
|
||||
Run some code when an object is detected by the ultrasonic sensor.
|
||||
|
||||
```sig
|
||||
sensors.ultrasonic1.pauseUntil(UltrasonicSensorEvent.ObjectDetected);
|
||||
sensors.ultrasonic1.onEvent(UltrasonicSensorEvent.ObjectDetected, function () {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
How an object is detected depends on the distance and movement _thresholds_ set for the sensor. A threshold is a number that is some distance in centimeters or the strength of ultrasonic sound. You can set a distance to detect something that is far, near, or is sending out ultrasound (like the sensor of another robot in the area). The three thresholds you can set are:
|
||||
@ -20,7 +22,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 is dectected by the ultrasonic sensor.
|
||||
* **handler**: the code you want to run when something is dectected by the ultrasonic sensor.
|
||||
|
||||
## Example
|
||||
|
||||
|
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-ev3",
|
||||
"version": "0.1.11",
|
||||
"version": "0.1.14",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-ev3",
|
||||
"version": "0.1.11",
|
||||
"version": "0.1.14",
|
||||
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
|
||||
"private": true,
|
||||
"keywords": [
|
||||
@ -45,8 +45,8 @@
|
||||
"webfonts-generator": "^0.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-common-packages": "0.20.30",
|
||||
"pxt-core": "3.7.1"
|
||||
"pxt-common-packages": "0.20.38",
|
||||
"pxt-core": "3.8.3"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
||||
|
@ -9,6 +9,7 @@
|
||||
},
|
||||
"galleries": {
|
||||
"Getting Started": "getting-started",
|
||||
"Tutorials": "tutorials",
|
||||
"Design Engineering": "design-engineering",
|
||||
"Coding": "coding",
|
||||
"Maker": "maker"
|
||||
|
@ -159,6 +159,7 @@
|
||||
@blocklyToolboxColor: #FFF; /*#FAC80A;*/
|
||||
@trashIconColor: #FAC80A; /*white*/
|
||||
|
||||
@editorToggleColor: @primaryColor;
|
||||
|
||||
/*-------------------
|
||||
Blockly
|
||||
|
@ -58,7 +58,7 @@
|
||||
}
|
||||
|
||||
/* Menu bar colors */
|
||||
.menubar .ui.item {
|
||||
.ui.menu .ui.item {
|
||||
color: #4A4A4A;
|
||||
}
|
||||
.fullscreensim .menubar .ui.menu {
|
||||
@ -73,18 +73,15 @@
|
||||
|
||||
/* Editor menu toggle */
|
||||
.menubar .ui.menu.fixed .item.editor-menuitem .ui.grid {
|
||||
background: @blue !important;
|
||||
background: fade(@blue, 10%) !important;
|
||||
border: 1px solid #888888;
|
||||
border-radius: 0px !important;
|
||||
border: 2px solid @blue;
|
||||
}
|
||||
.menubar .ui.menu.fixed .ui.item.editor-menuitem .item:not(.active) {
|
||||
color: white;
|
||||
}
|
||||
.menubar .ui.menu.fixed .ui.item.editor-menuitem .item {
|
||||
border-radius: 0px !important;
|
||||
}
|
||||
.menubar .ui.menu.fixed .ui.item.editor-menuitem .item.active {
|
||||
color: @blue;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.menubar .ui.item.editor-menuitem .item.toggle {
|
||||
|