fwd-edu-breakout=github:climate-action-kits/pxt-fwd-edu/fwd-breakout
ledRing=github:climate-action-kits/pxt-fwd-edu
Welcome to Bees Coding Tutorial.
In this coding tutorial we will count the number of pollinators visiting your garden monitor, whenever a pollinator lands on the touch sensor all pixels of the LED Ring are turned on. Also a bar graph is plotted on the Microbit LED matrix. Button A clears the screen and shows the number of total pollinators.
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.
Look below the @boardname@ simulator to see the Climate Action Board’s simulator of the connected components. Try touching the Touch Sensor on your project. The virtual simulators will react to it.
Click ||Variables:Variables||
. Click on |Make a Variable| to create a new ||Variables:Variable||
.
Name it ||Variables:bugVisits||
.
Inside ||Variables:Variables||
there is ||Variables:bugVisits||
and more blocks.
Click ||Variables:Variables||
drag and drop ||Variables:set bugVisits to 0||
block
inside ||basic:on start||
block.
let bugVisits = 0
basic.forever(function (){
})
Click ||logic:Logic||
drag and drop ||logic:if true then||
conditional block inside ||basic:forever||
loop.
let bugVisits = 0
basic.forever(function (){
if (true){
}
})
Click ||fwdSensors:Sensors||
drag and drop ||fwdSensors:touch pressed||
block to replace ||logic:true||
condition of ||logic:if true then||
block.
let bugVisits = 0
basic.forever(function () {
if (fwdSensors.touch.fwdIsPressed()) {
}
})
Click ||Variables:Variables||
drag and drop
||Variables:change bugVisits by 1||
block inside
||logic:if||
||fwdSensors:touch pressed||
||logic: then||
block.
let bugVisits = 0
basic.forever(function () {
if (fwdSensors.touch.fwdIsPressed()) {
bugVisits += 1
}
})
Click ||fwdSensors:Sensors||
drag and drop ||fwdSensors:set all ledRing LEDs to||
block under ||Variables:change bugVisits by 1||
block.
let bugVisits = 0
basic.forever(function () {
if (fwdSensors.touch.fwdIsPressed()) {
bugVisits += 1
fwdSensors.ledRing.fwdSetAllPixelsColour(0xff0000)
}
})
Click ||basic:Basic||
drag and drop ||basic:show number||
block under ||fwdSensors:set all ledRing LEDs to||
block.
let bugVisits = 0
basic.forever(function () {
if (fwdSensors.touch.fwdIsPressed()) {
bugVisits += 1
fwdSensors.ledRing.fwdSetAllPixelsColour(0xff0000)
}
})
Click ||fwdSensors:Sensors||
drag and drop ||fwdSensors:set all ledRing LEDs to||
block under ||basic:show number||
block.
let bugVisits = 0
basic.forever(function () {
if (fwdSensors.touch.fwdIsPressed()) {
bugVisits += 1
fwdSensors.ledRing.fwdSetAllPixelsColour(0xff0000)
fwdSensors.ledRing.fwdSetAllPixelsColour(0x000000)
}
})
Click ||Variables:Variables||
drag and drop ||Variables:bugVisits||
to replace the ||0||
in both ||basic:show number||
.
Change the color of second ||fwdSensors:LED Ring||
block to ||control:Black||
.
let bugVisits = 1
basic.forever(function () {
if (fwdSensors.touch.fwdIsPressed()) {
bugVisits += 1
fwdSensors.ledRing.fwdSetAllPixelsColour(0xff0000)
fwdSensors.ledRing.fwdSetAllPixelsColour(0x000000)
}
})
Click ||LED:LED||
drag and drop ||LED: plot bar graph of 0 upto 0||
block
under ||fwdSensors:set all pixels colour||
block
let bugVisits = 0
bugVisits = 0
basic.forever(function () {
if (fwdSensors.touch.fwdIsPressed()) {
bugVisits += 1
fwdSensors.ledRing.fwdSetAllPixelsColour(0xff0000)
fwdSensors.ledRing.fwdSetAllPixelsColour(0x000000)
led.plotBarGraph(0,0)
}
})
Click ||Variables:Variables||
drag and drop ||Variables:bugVisits||
block
to replace ||0||
in ||LED:plot bar grap of 0||
block. Change ||LED:upto 0||
to ||25||
let bugVisits = 0
bugVisits = 0
basic.forever(function () {
if (fwdSensors.touch.fwdIsPressed()) {
bugVisits += 1
fwdSensors.ledRing.fwdSetAllPixelsColour(0xff0000)
fwdSensors.ledRing.fwdSetAllPixelsColour(0x000000)
led.plotBarGraph(
bugVisits,
25
)
}
})
Click ||Input:Input||
drag and drop ||Input:on button A pressed||
block
on the workspace.
input.onButtonPressed(Button.A, function () {
})
let bugVisits = 0
bugVisits = 0
basic.forever(function () {
if (fwdSensors.touch.fwdIsPressed()) {
bugVisits += 1
fwdSensors.ledRing.fwdSetAllPixelsColour(0xff0000)
fwdSensors.ledRing.fwdSetAllPixelsColour(0x000000)
led.plotBarGraph(
bugVisits,
25
)
}
})
Click ||Basic:Basic||
drag and drop ||Basic:clear screen||
block inside
||Input:on button A pressed||
block.
input.onButtonPressed(Button.A, function () {
basic.clearScreen()
})
let bugVisits = 0
bugVisits = 0
basic.forever(function () {
if (fwdSensors.touch.fwdIsPressed()) {
bugVisits += 1
fwdSensors.ledRing.fwdSetAllPixelsColour(0xff0000)
fwdSensors.ledRing.fwdSetAllPixelsColour(0x000000)
led.plotBarGraph(
bugVisits,
25
)
}
})
Click ||Basic:Basic||
drag and drop ||Basic:show number||
block under
||Basic:clear screen||
block. Click ||Variables:Variables||
drag and drop
||Variables:bugVisits||
block to replace ||0||
in ||Basic:show number||
block.
input.onButtonPressed(Button.A, function () {
basic.clearScreen()
basic.showNumber(bugVisits)
})
let bugVisits = 0
bugVisits = 0
basic.forever(function () {
if (fwdSensors.touch.fwdIsPressed()) {
bugVisits += 1
fwdSensors.ledRing.fwdSetAllPixelsColour(0xff0000)
fwdSensors.ledRing.fwdSetAllPixelsColour(0x000000)
led.plotBarGraph(
bugVisits,
25
)
}
})
Click ||Basic:Basic||
drag and drop ||Basic:pause (ms) 100||
block under
||Basic:show number||
||Variables:bugVisits||
block. Click ||Basic:Basic||
drag and drop ||Basic:pause (ms) 100||
block under
||Basic:clear screen||
block under ||Basic:pause (ms) 100||
block. Change ||100||
of ||Basic:pause (ms) 100||
block to ||Basic:5000||
.
input.onButtonPressed(Button.A, function () {
basic.clearScreen()
basic.showNumber(bugVisits)
basic.pause(5000)
basic.clearScreen()
})
let bugVisits = 0
bugVisits = 0
basic.forever(function () {
if (fwdSensors.touch.fwdIsPressed()) {
bugVisits += 1
fwdSensors.ledRing.fwdSetAllPixelsColour(0xff0000)
fwdSensors.ledRing.fwdSetAllPixelsColour(0x000000)
led.plotBarGraph(
bugVisits,
25
)
}
})
|Download|
and test your code. Click the bulb icon to see how the simulator shows the components working.
Congratulations on completing your Bees Project!
After your project is complete, go back to the lesson for more challenges and extensions.