With my CAS hub leader and STEM Ambassador hats on I volunteer at these events in support of the great work that Pam Popay, Jill Southgate and all the BT volunteers put into delivering a great set of instructive and practical days.
As a code club leader at one of the school's attending, Woodbridge Primary School, we are beginning to do some work with microbits and have a few at the club so I thought it would be interesting to implement line tracking using a microbit based robot. I purchased the Kitronik bot which uses visible light instead of infrared to help "show" the principle of operation. Having built the bot and tested the sensitivity of the LDRs some minor tweaking was necessary to pull up the output of the comparator op amps to trigger the digital threshold on the microbit. Having completed the build it was on to a bit of coding..........
In Code Club we are using the Java blocks editor so I used this to code the line following script that Kitronik supply with their build instructions.
Their script uses the LEDs to show which direction the bot is travelling in for each of the detector states (very useful) which I coded using the basic show led block:
To overcome this but keep using block based coding it is necessary to convert the block code to javascript and add the ,0 into the led command:
basic.forever(() => {
if (true) {
basic.showLeds(`
. . # . .
. # # # .
# . # . #
. . # . .
. . # . .
`,0)
} else {
}
})
Then convert the code back to blocks which results in a script statement that cannot be converted to a block (a bit like a line of assembler in BASIC) but which has the 0 millisecond pause set ....
and results in a line tracking algorithm that works.