fwd-edu-breakout=github:climate-action-kits/pxt-fwd-edu/fwd-breakout
sonar=github:climate-action-kits/pxt-fwd-edu
Welcome to Wildfire Tracking with Autonomous Vehicles
In this coding tutorial the vehicle will be moving around a perimeter and keeping a check on Light and Temperature. Press the button A and B to start and stop moving the vehicle.
Turn on the Climate Action Kit board.
Click three dots besides |Download|
button, and click on Connect Device. Next, follow the steps to pair your micro:bit.
Next, click the |Download|
button to download the blank project to start-up the simulators.
This is how the simulators should look after a successful download. You can see
the Servo Motors along side the Pump.
Look below the @boardname@ simulator to see the Climate Action Board and the connected devices. Try to turn the motors on and off using
the simulator and observe the changes.
Click ||fwdMotors:Motors||
drag and drop ||fwdMotors:setup driving||
block
inside ||Basic:on start||
block.
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.leftServo,
)
Change the ||fwdMotors:right motor to rightServo||
.
Keep the ||fwdMotors: left motor to leftServo||
.
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo,
0
)
Click ||Variables:Variables||
and then click |Make a Variable| to create
these ||Variables:Variables||
||Variables:IsDrivingEnabled||
||Variables:lightThreshold||
||Variables:temperatureThreshold||
Click ||Input:Input||
drag and drop ||Input:on button A pressed||
block.
Right click and duplicate it to get another ||Input:on button A pressed||
block.
Change ||Input:A||
to ||Input:B||
for the greyed ||Input:on button A pressed||
block.
input.onButtonPressed(Button.A, function () {
})
input.onButtonPressed(Button.B, function () {
})
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo,
0
)
basic.forever(function () {
})
Click ||Variables:Variables||
drag and drop ||Variables:set IsDrivingEnabled to 0||
block
inside ||Input:on button A pressed||
block and also inside
||Input:on button B pressed||
block.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = 0
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = 0
})
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo,
0
)
basic.forever(function () {
})
Click ||Logic:Logic||
drag and drop ||Logic:true||
block to replace
||Variables:0||
of ||Variables:set IsDrivingEnabled to 0||
block
inside ||Input:on button A pressed||
block.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = 0
})
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo,
0
)
basic.forever(function () {
})
Click ||Logic:Logic||
drag and drop ||Logic:false||
block to replace
||Variables:0||
of ||Variables:set IsDrivingEnabled to 0||
block
inside ||Input:on button B pressed||
block.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo,
0
)
IsDrivingEnabled = false
basic.forever(function () {
})
Click ||Logic:Logic||
drag and drop ||Logic:if true then else||
block
inside ||basic:forever||
block.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo,
0
)
basic.forever(function () {
if (true) {
}
else {
}
})
Click ||Loops:Loops||
drag and drop ||Loops:repeat 4 times||
block to nest inside ||Logic:if true then||
block.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
basic.forever(function () {
if (true) {
for (let index = 0; index < 4; index++) {
}
} else {
}
})
Click ||logic:Logic||
drag and drop ||logic:if true then else||
block
to nest inside ||Loops:repeat 4 times||
block.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo,
0
)
basic.forever(function () {
if (true) {
for (let index = 0; index < 4; index++){
if (true) {
}
else {
}
} }
else {
}
})
Click ||Variables:Variables||
drag and drop ||Variables:IsDrivingEnabled||
block
to replace ||Logic:true||
condition of ||Logic:if true then||
block.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo,
0
)
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++){
if (true) {
}
else {
}
}
}else {
}
})
Click ||fwdMotors:Motors||
drag and drop ||fwdMotors:stop motors||
block inside ||Logic:else condition||
.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo,
0
)
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++){
if (true) {
}
else {
}
}
}else {
fwdMotors.stop()
}
})
Click ||fwdMotors:Motors||
drag and drop ||fwdMotors:drive forward at 50||
block.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
if (true) {
} else {
}
}
} else {
fwdMotors.stop()
}
})
Click ||basic:Basic||
drag and drop ||basic:pause (ms) 100||
block under ||fwdMotors:drive forward at 50||
.
Change ||basic:100||
to ||basic:5000||
.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
if (true) {
} else {
}
}
} else {
fwdMotors.stop()
}
})
Click ||fwdMotors:Motors||
drag and drop ||fwdMotors:turn 0' in place||
block
under ||basic:pause (ms) 5000||
block. Change ||fwdMotors:0||
to ||fwdMotors:25||
.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
fwdMotors.turn(25)
if (true) {
} else {
}
}
} else {
fwdMotors.stop()
}
})
Click ||Logic:Logic||
drag and drop ||Logic: or ||
block to replace ||Logic:true||
condition under
of ||Logic:if true then||
block under ||fwdMotors:turn 25' in place||
block.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
fwdMotors.turn(25)
if (0 || 0) {
} else {
}
}
} else {
fwdMotors.stop()
}
})
Click ||Logic:Logic||
drag and drop ||Logic: or ||
block to replace left side of ||Logic: or ||
block condition.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
fwdMotors.turn(25)
if (0 || 0 || 0) {
} else {
}
}
} else {
fwdMotors.stop()
}
})
Click ||Logic:Logic||
drag and drop ||Logic: 0 < 0||
block to replace left side of ||Logic: or ||
block condition.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
fwdMotors.turn(25)
if (0 < 0 || 0 || 0) {
} else {
}
}
} else {
fwdMotors.stop()
}
})
Click ||Logic:Logic||
drag and drop ||Logic: 0 < 0||
block to replace middle ||Logic: or ||
block condition.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
fwdMotors.turn(25)
if (0 < 0 || 0 < 0 || 0) {
} else {
}
}
} else {
fwdMotors.stop()
}
})
Click ||Logic:Logic||
drag and drop ||Logic: 0 < 0||
block to replace right ||Logic: or ||
block condition.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
fwdMotors.turn(25)
if (0 < 0 || 0 < 0 || 0 < 0) {
} else {
}
}
} else {
fwdMotors.stop()
}
})
Click ||Variables:Variables||
drag and drop ||Variables:lightThreshold||
block to replace left ||Logic:0||
of ||Logic:Comparison||
condition.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
fwdMotors.turn(25)
if (lightThreshold < 0 || 0 < 0 || 0 < 0) {
} else {
}
}
} else {
fwdMotors.stop()
}
})
Click ||Variables:Variables||
drag and drop ||Variables:temperatureThreshold||
block to replace left ||Logic:0||
of middle ||Logic:Comparison||
condition.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
fwdMotors.turn(25)
if (lightThreshold < 0 || temperatureThreshold < 0 || 0 < 0) {
} else {
}
}
} else {
fwdMotors.stop()
}
})
Click ||Input:Input||
drag and drop ||Input:light level||
block to replace right ||Logic:0||
of ||Logic:Comparison||
condition with
||Variables:lightThreshold||
block on the left.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
fwdMotors.turn(25)
if (lightThreshold < input.lightLevel() || temperatureThreshold < 0) {
} else {
}
}
} else {
fwdMotors.stop()
}
})
Click ||Input:Input||
drag and drop ||Input:temperature ('C)||
block to replace right ||Logic:0||
of ||Logic:Comparison||
condition with
||Variables:temperatureThreshold||
block in the middle.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
fwdMotors.turn(25)
if (lightThreshold < input.lightLevel() || temperatureThreshold < input.temperature()) {
} else {
}
}
} else {
fwdMotors.stop()
}
})
Click ||Variables:Variables||
drag and drop ||Variables:set temperatureThreshold to 0||
and
||Variables:set lightThreshold to 0||
blocks inside
||Basic:on start||
block under ||fwdMotors:setup driving||
block.
Recommended threshold values:
- Temperature = 25
- Light = 100
- Note: Adjust the threshold values according to your surroundings.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
let lightThreshold = 100
let temperatureThreshold = 25
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
fwdMotors.turn(25)
if (lightThreshold < input.lightLevel() || temperatureThreshold < input.temperature()) {
} else {
}
}
} else {
fwdMotors.stop()
}
})
Click ||Loops:Loops||
drag and drop ||Loops:repeat 4 times||
block to nest inside ||Logic:if true then||
block.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
let lightThreshold = 100
let temperatureThreshold = 25
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
fwdMotors.turn(25)
if (input.lightLevel() > lightThreshold || input.temperature() > temperatureThreshold) {
for (let index = 0; index < 4; index++) {
}
} else {
}
}
} else {
fwdMotors.stop()
}
})
Click ||Music:Music||
drag and drop two ||Music:play tone Middle C for 1 beat||
blocks to nest inside ||Loops:repeat 4 times||
block.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
let lightThreshold = 100
let temperatureThreshold = 25
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
fwdMotors.turn(25)
if (input.lightLevel() > lightThreshold || input.temperature() > temperatureThreshold) {
for (let index = 0; index < 4; index++) {
music.playTone(262, music.beat(BeatFraction.Whole))
music.playTone(262, music.beat(BeatFraction.Whole))
}
} else {
}
}
} else {
fwdMotors.stop()
}
})
Click ||Music:Music||
drag and drop ||Music:stop all sounds||
blocks to nest inside ||Logic:else||
condition.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
let lightThreshold = 100
let temperatureThreshold = 25
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
fwdMotors.turn(25)
if (input.lightLevel() > lightThreshold || input.temperature() > temperatureThreshold) {
for (let index = 0; index < 4; index++) {
music.playTone(262, music.beat(BeatFraction.Whole))
music.playTone(262, music.beat(BeatFraction.Whole))
}
} else {
music.stopAllSounds()
}
}
} else {
fwdMotors.stop()
}
})
Click ||Basic:Basic||
drag and drop ||Basic:pause (ms) 100||
block under
||Logic:else||
condition. Change ||Basic:100||
to ||Basic:1000||
.
input.onButtonPressed(Button.A, function () {
IsDrivingEnabled = true
})
input.onButtonPressed(Button.B, function () {
IsDrivingEnabled = false
})
let IsDrivingEnabled = false
fwdMotors.setupDriving(
fwdMotors.leftServo,
fwdMotors.rightServo
)
let lightThreshold = 100
let temperatureThreshold = 25
basic.forever(function () {
if (IsDrivingEnabled) {
for (let index = 0; index < 4; index++) {
fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 50)
basic.pause(5000)
fwdMotors.turn(25)
if (input.lightLevel() > lightThreshold || input.temperature() > temperatureThreshold) {
for (let index = 0; index < 4; index++) {
music.playTone(262, music.beat(BeatFraction.Whole))
music.playTone(262, music.beat(BeatFraction.Whole))
}
} else {
music.stopAllSounds()
}
basic.pause(1000)
}
} else {
fwdMotors.stop()
}
})
|Download|
and test your code. Click the bulb icon to see how
the simulator shows the components working.
|Download|
and test your code. Click the bulb icon to see how
the simulator shows the components working.
If after |Downloading|
your project does not work please refer to the
image and make sure your components are assigned correctly.
Need help in assigning the right components to their simulators. Watch the video.
Congratulations on completing your Wildfire Tracking with Autonomous Vehicles Project!
After your project is complete go back to the lesson for more challenges and extensions.