Welcome to Solar Disinfection Coding Tutorial
Plug your USB cable into the micro:bit.
Click ||logic: Logic||
drag and drop ||logic:If then Else||
block inside ||basic:forever||
loop.
basic.forever(function () {
if (true) {
}
else {
}
)}
Click ||Logic:Logic||
drag and drop ||Logic:Comparison <||
block
to replace ||Logic:true||
condition of ||Logic:If true then||
block. Change
||Logic:less than <||
to ||Logic:greater than >||
.
basic.forever(function () {
if (0>0) {
}
else {
}
)}
Click ||Input:Input||
drag and drop ||Input:light level||
block
to replace ||Logic:0||
on the left side of ||Logic:Comparison||
block.
Change ||Logic:0||
on the right side to ||Logic:128||
.
basic.forever(function () {
if (input.lightLevel()>128) {
}
else {
}
)}
Click ||Variables:Variables||
create two ||Variables:Variables||
:
||Variables:totalLightExposure||
||Variables:exposure_start_time||
Click ||Variables:Variables||
drag and drop
||Variables:change totalLightExposure by 1||
block inside ||Logic:If||
||Input:light level||
||Logic:> 128 then||
block.
basic.forever(function () {
if (input.lightLevel()>128) {
totalLightExposure += 1
}
else {
}
)}
Click ||Math:Math||
drag and drop
||Math:Substraction||
block to replace ||Variables:1||
in
||Variables:change totalLightExposure by||
block.
basic.forever(function () {
if (input.lightLevel()>128) {
totalLightExposure += (0-0)
}
else {
}
)}
Click ||Input:Input||
then ||Input:more||
drag and drop
||Input:running time (ms)||
block to replace left ||Math:0||
in
||Math:Substraction||
block.
basic.forever(function () {
if (input.lightLevel()>128) {
totalLightExposure += (input.runningTime()-0)
}
else {
}
)}
Click ||Variables:Variables||
drag and drop
||Variables:exposure start time||
block to replace right ||Math:0||
in
||Math:Substraction||
block.
basic.forever(function () {
if (input.lightLevel()>128) {
totalLightExposure += (input.runningTime()- exposure_start_time)
}
else {
}
)}
Click ||Variables:Variables||
drag and drop
||Variables:set exposure_start_time||
block under
||Variables:change totalLightExposure by||
block.
basic.forever(function () {
if (input.lightLevel()>128) {
totalLightExposure += (input.runningTime()- exposure_start_time)
exposure_start_time = 0
}
else {
}
)}
Click ||Input:Input||
then ||Input:more||
drag and drop
||Input:running time (ms)||
block to replace ||0||
in
||Variables:set exposure_start_time to||
block.
basic.forever(function () {
if (input.lightLevel()>128) {
totalLightExposure += (input.runningTime()- exposure_start_time)
exposure_start_time = input.runningTime()
}
else {
}
)}
Click ||logic:Logic||
drag and drop ||logic:If true then||
block under ||Variables:set exposure_start_time to||
block.
basic.forever(function () {
if (input.lightLevel()>128) {
totalLightExposure += (input.runningTime()- exposure_start_time)
exposure_start_time = input.runningTime()
if(true){
}
}
else {
}
)}
Click ||Logic:Logic||
drag and drop ||Logic:Comparison||
block
to replace ||Logic:true||
condition of ||Logic:If true then||
block.
basic.forever(function () {
if (input.lightLevel()>128) {
totalLightExposure += (input.runningTime()- exposure_start_time)
exposure_start_time = input.runningTime()
if(0>0){
}
}
else {
}
)}
Click ||Variables:Variables||
drag and drop ||Variables:totalLightExposure||
block to replace left ||Logic:0||
of ||Logic:Comparison||
block.
basic.forever(function () {
if (input.lightLevel()>128) {
totalLightExposure += (input.runningTime()- exposure_start_time)
exposure_start_time = input.runningTime()
if(totalLightExposure>0){
}
}
else {
}
)}
Click ||Math:Math||
drag and drop ||Math:Mutliplication||
block to replace right ||Logic:0||
of ||Logic:Comparison||
block.
basic.forever(function () {
if (input.lightLevel()>128) {
totalLightExposure += (input.runningTime()- exposure_start_time)
exposure_start_time = input.runningTime()
if(totalLightExposure > (0 * 0)){
}
}
else {
}
)}
Click ||Math:Math||
drag and drop ||Math:Mutliplication||
block to replace left ||Math:0||
of ||Math:Mutliplication||
block.
basic.forever(function () {
if (input.lightLevel()>128) {
totalLightExposure += (input.runningTime()- exposure_start_time)
exposure_start_time = input.runningTime()
if(totalLightExposure > ((0 * 0) * 0)){
}
}
else {
}
)}
Change the values in ||Math:Math||
block to ||Math:6 x 3600 x 1000||
.
basic.forever(function () {
if (input.lightLevel()>128) {
totalLightExposure += (input.runningTime()- exposure_start_time)
exposure_start_time = input.runningTime()
if(totalLightExposure > ((6 * 3600) * 1000)){
}
}
else {
}
)}
Click ||Basic:Basic||
drag and drop ||Basic:show icon||
block inside
||Logic:if||
||Variables:totalLightExposure||
||Logic:then||
block.
Change ||basic:Heart||
to ||basic::)||
icon.
basic.forever(function () {
if (input.lightLevel()>128) {
totalLightExposure += (input.runningTime()- exposure_start_time)
exposure_start_time = input.runningTime()
if(totalLightExposure > ((6 * 3600) * 1000)){
basic.showIcon(IconNames.Happy)
}
}
else {
}
)}
Click ||Basic:Basic||
drag and drop ||Basic:show string||
block under
||Basic:show icon||
block. Change string to ||basic:Safe||
.
basic.forever(function () {
if (input.lightLevel()>128) {
totalLightExposure += (input.runningTime()- exposure_start_time)
exposure_start_time = input.runningTime()
if(totalLightExposure > ((6 * 3600) * 1000)){
basic.showIcon(IconNames.Happy)
basic.showString("Safe")
}
}
else {
}
)}
Click ||Basic:Basic||
drag and drop ||Basic:show string||
block inside
||Logic:else||
condition. Change string to ||basic:Not Safe||
.
basic.forever(function () {
if (input.lightLevel()>128) {
totalLightExposure += (input.runningTime()- exposure_start_time)
exposure_start_time = input.runningTime()
if(totalLightExposure > ((6 * 3600) * 1000)){
basic.showIcon(IconNames.Happy)
basic.showString("Safe")
}
}
else {
basic.showString("Not Safe")
}
)}
|Download|
and test your code.
Congratulations on completing your SODIS project!