From 485f02ed27fc350ca9c8911deff1f39ee2efe818 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Fri, 5 Jan 2018 21:49:04 -0800 Subject: [PATCH] cruise control activities --- docs/coding.md | 21 +++++++++++++++++++++ docs/coding/cruise-control-1.md | 10 ++++++++++ docs/coding/cruise-control-2.md | 15 +++++++++++++++ docs/coding/cruise-control-3.md | 28 ++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 docs/coding/cruise-control-1.md create mode 100644 docs/coding/cruise-control-2.md create mode 100644 docs/coding/cruise-control-3.md diff --git a/docs/coding.md b/docs/coding.md index 2c7b39c2..43fb7b1b 100644 --- a/docs/coding.md +++ b/docs/coding.md @@ -131,4 +131,25 @@ "url":"/coding/ignition-3", "cardType": "example" }] +``` + +## Cruise Control + +```codecard +[{ + "name": "Cruise Control", + "description": "Activity 1", + "url":"/coding/cruise-control-1", + "cardType": "example" +}, { + "name": "Cruise Control", + "description": "Activity 2", + "url":"/coding/cruise-control-2", + "cardType": "example" +}, { + "name": "Cruise Control", + "description": "Activity 3", + "url":"/coding/cruise-control-3", + "cardType": "example" +}] ``` \ No newline at end of file diff --git a/docs/coding/cruise-control-1.md b/docs/coding/cruise-control-1.md new file mode 100644 index 00000000..f302e238 --- /dev/null +++ b/docs/coding/cruise-control-1.md @@ -0,0 +1,10 @@ +# Cruise Control Activity 1 + +```blocks +let speed = 0; +sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () { + if (speed < 100) + speed = speed + 10; + motors.largeBC.setSpeed(speed); +}) +``` \ No newline at end of file diff --git a/docs/coding/cruise-control-2.md b/docs/coding/cruise-control-2.md new file mode 100644 index 00000000..95e0b99b --- /dev/null +++ b/docs/coding/cruise-control-2.md @@ -0,0 +1,15 @@ +# Cruise Control Activity 2 + +```blocks +let speed = 0; +sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () { + if (speed < 100) + speed = speed + 10; + motors.largeBC.setSpeed(speed); +}) +sensors.touch2.onEvent(TouchSensorEvent.Pressed, function () { + if (speed > -100) + speed = speed - 10; + motors.largeBC.setSpeed(speed); +}) +``` \ No newline at end of file diff --git a/docs/coding/cruise-control-3.md b/docs/coding/cruise-control-3.md new file mode 100644 index 00000000..edc8776a --- /dev/null +++ b/docs/coding/cruise-control-3.md @@ -0,0 +1,28 @@ +# 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.printLine("speed: " + speed, 1) + motors.largeBC.setSpeed(speed) +} +sensors.touch2.onEvent(TouchSensorEvent.Pressed, function () { + accelerate() + update() +}) +sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () { + decelerate() + update() +}) +``` \ No newline at end of file