diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 16f1d46d..182211e3 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -41,12 +41,8 @@ * [Reverse Beeper 1](/coding/reverse-beeper-1) * [Reverse Beeper 2](/coding/reverse-beeper-2) * [Reverse Beeper 3](/coding/reverse-beeper-3) - * [Ignition 1](/coding/ignition-1) - * [Ignition 2](/coding/ignition-2) - * [Ignition 3](/coding/ignition-3) - * [Cruise Control 1](/coding/cruise-control-1) - * [Cruise Control 2](/coding/cruise-control-2) - * [Cruise Control 3](/coding/cruise-control-3) + * [Ignition](/coding/ignition) + * [Cruise Control](/coding/cruise-control) * [Roaming 1](/coding/roaming-1) * [Roaming 2](/coding/roaming-2) diff --git a/docs/coding/cruise-control-1.md b/docs/coding/cruise-control-1.md deleted file mode 100644 index a0490ec2..00000000 --- a/docs/coding/cruise-control-1.md +++ /dev/null @@ -1,10 +0,0 @@ -# Cruise Control Activity 1 - -```blocks -let speed = 0; -sensors.touch1.onEvent(ButtonEvent.Pressed, function () { - if (speed < 100) - speed = speed + 10; - motors.largeBC.run(speed); -}) -``` \ No newline at end of file diff --git a/docs/coding/cruise-control-2.md b/docs/coding/cruise-control-2.md deleted file mode 100644 index e7f39ccc..00000000 --- a/docs/coding/cruise-control-2.md +++ /dev/null @@ -1,15 +0,0 @@ -# Cruise Control Activity 2 - -```blocks -let speed = 0; -sensors.touch1.onEvent(ButtonEvent.Pressed, function () { - if (speed < 100) - speed = speed + 10; - motors.largeBC.run(speed); -}) -sensors.touch2.onEvent(ButtonEvent.Pressed, function () { - if (speed > -100) - speed = speed - 10; - motors.largeBC.run(speed); -}) -``` \ No newline at end of file diff --git a/docs/coding/cruise-control-3.md b/docs/coding/cruise-control-3.md deleted file mode 100644 index 751a55b4..00000000 --- a/docs/coding/cruise-control-3.md +++ /dev/null @@ -1,28 +0,0 @@ -# Cruise Control Activity 3 - -```blocks -let speed = 0 -function decelerate() { - if (speed > -100) { - speed = speed - 10 - } -} -function accelerate() { - if (speed < 100) { - speed = speed + 10 - } -} -function update() { - brick.clearScreen() - brick.showString("speed: " + speed, 1) - motors.largeBC.run(speed) -} -sensors.touch2.onEvent(ButtonEvent.Pressed, function () { - accelerate() - update() -}) -sensors.touch1.onEvent(ButtonEvent.Pressed, function () { - decelerate() - update() -}) -``` \ No newline at end of file diff --git a/docs/coding/cruise-control.md b/docs/coding/cruise-control.md new file mode 100644 index 00000000..902c96d3 --- /dev/null +++ b/docs/coding/cruise-control.md @@ -0,0 +1,65 @@ +# Cruise Control + +Learn how to set and adjust motor speeds. + +## Activity 1 + +Increase motor speed when touch sensor `1` is pressed. + +```blocks +let speed = 0; +sensors.touch1.onEvent(ButtonEvent.Pressed, function () { + if (speed < 100) + speed = speed + 10; + motors.largeBC.run(speed); +}) +``` + +## Activity 2 + +Add a "reduce" motor speed action when touch sensor `2` is pressed. + +```blocks +let speed = 0; +sensors.touch1.onEvent(ButtonEvent.Pressed, function () { + if (speed < 100) + speed = speed + 10; + motors.largeBC.run(speed); +}) +sensors.touch2.onEvent(ButtonEvent.Pressed, function () { + if (speed > -100) + speed = speed - 10; + motors.largeBC.run(speed); +}) +``` + +## Activity 3 + +Refactor your code by moving the speed increase and speed decrease code into ``||functions:accelerate||`` and ``||functions:decelerate||`` functions. Run the motors at the new speed in an ``||functions:update||`` function. + +```blocks +let speed = 0 +function decelerate() { + if (speed > -100) { + speed = speed - 10 + } +} +function accelerate() { + if (speed < 100) { + speed = speed + 10 + } +} +function update() { + brick.clearScreen() + brick.showString("speed: " + speed, 1) + motors.largeBC.run(speed) +} +sensors.touch2.onEvent(ButtonEvent.Pressed, function () { + accelerate() + update() +}) +sensors.touch1.onEvent(ButtonEvent.Pressed, function () { + decelerate() + update() +}) +``` \ No newline at end of file diff --git a/docs/coding/ignition-1.md b/docs/coding/ignition-1.md deleted file mode 100644 index b9d5fe0f..00000000 --- a/docs/coding/ignition-1.md +++ /dev/null @@ -1,11 +0,0 @@ -# Ignition Activity 1 - -```blocks -sensors.touch1.onEvent(ButtonEvent.Pressed, function () { - brick.showImage(images.eyesDizzy) -}) -sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectDetected, function () { - brick.showImage(images.eyesTiredMiddle) -}) -brick.showImage(images.eyesSleeping) -``` diff --git a/docs/coding/ignition-2.md b/docs/coding/ignition-2.md deleted file mode 100644 index 61bafd21..00000000 --- a/docs/coding/ignition-2.md +++ /dev/null @@ -1,12 +0,0 @@ -# Ignition Activity 2 - -```blocks -while (true) { - if (sensors.touch1.wasPressed() && - sensors.ultrasonic4.distance() < 10) { - music.playSoundEffectUntilDone(sounds.mechanicalMotorStart) - music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle); - } - pause(1); -} -``` diff --git a/docs/coding/ignition-3.md b/docs/coding/ignition-3.md deleted file mode 100644 index 0b17c54c..00000000 --- a/docs/coding/ignition-3.md +++ /dev/null @@ -1,13 +0,0 @@ -# Ignition Activity 3 - -```blocks -while (true) { - if (sensors.ultrasonic4.distance() < 10 && - sensors.touch1.wasPressed() && - brick.buttonEnter.wasPressed()) { - music.playSoundEffectUntilDone(sounds.mechanicalMotorStart) - music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle); - } - pause(1); -} -``` diff --git a/docs/coding/ignition.md b/docs/coding/ignition.md new file mode 100644 index 00000000..8a4521d9 --- /dev/null +++ b/docs/coding/ignition.md @@ -0,0 +1,48 @@ +# Ignition + +Explore sensor events and sensor status. + +## Activity 1 + +Wait for a touch sensor press or ultrasonic object detection. Show an expression on the screen when they happen. + +```blocks +sensors.touch1.onEvent(ButtonEvent.Pressed, function () { + brick.showImage(images.eyesDizzy) +}) +sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectDetected, function () { + brick.showImage(images.eyesTiredMiddle) +}) +brick.showImage(images.eyesSleeping) +``` + +## Activity 2 + +Play some motor sounds if touch sensor `1` is pressed at the same moment when and object comes close. + +```blocks +while (true) { + if (sensors.touch1.wasPressed() && + sensors.ultrasonic4.distance() < 10) { + music.playSoundEffectUntilDone(sounds.mechanicalMotorStart) + music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle); + } + pause(1); +} +``` + +## Activity 3 + +Play some motor sounds if touch sensor `1` is pressed when both the `enter` button is pressed on the brick and an object comes close. + +```blocks +while (true) { + if (sensors.ultrasonic4.distance() < 10 && + sensors.touch1.wasPressed() && + brick.buttonEnter.wasPressed()) { + music.playSoundEffectUntilDone(sounds.mechanicalMotorStart) + music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle); + } + pause(1); +} +``` \ No newline at end of file