Update the Training Programs
You may have noticed that turning off your robot erased all the HUSKYLENS training data. That can be frustrating! This time, we’ll use the MicroSD card slot on the HUSKYLENS so your training data can be saved and loaded whenever you need it. With this program, you’ll be able to change IDs with the micro:bit buttons, train the camera on colors, save that training to the MicroSD card, and reload it later. You’ll also be able to erase everything when you’re ready for a fresh start.
The Program
- Start with the Learn Colors script you saved in the Create the Color Training Script lesson. If you need to reopen it, simply click the Import button on the makecode.microbit.org homepage.
- Use the Name field next to the Download button to name the project: Learn Colors and Remember with microSD.
- Update your program so that it matches the one below.
- Click the Save icon (floppy disk) to keep a copy in your editor.
- Press Download to load the program onto your micro:bit.

How It Works
On start setup
I2C Repeat on with clock signal on pin P5 data on P4 → shares the I²C bus with the cyber:bot board.
pause (ms) (100) → gives the system time to get ready.
HuskyLens initialize I2C until success → starts communication with the HUSKYLENS.
HuskyLens switch algorithm to (color recognition) → sets it to look for colors.
set (currentId) to (1) → starts the ID counter at 1.
show number (currentId) → displays “1” on the LED matrix.
Inside the forever loop
Each time through the loop, the script checks conditions in order. Only the first true condition runs:
if <button A pressed> and <button B pressed>
→ HuskyLens learn ID (currentId) once automatically trains on the current ID.
→ show icon (Yes) confirms success.
else if <logo pressed> and <button A pressed>
→ HuskyLens save model to TF card (Save, currentId) saves this ID’s training data.
→ show arrow (North) shows the save action.
else if <logo pressed> and <button B pressed>
→ HuskyLens save model to TF card (Load, currentId) loads training data from the card.
→ show arrow (South) shows the load action.
else if <button A pressed>
→ change (currentId) by (1) increases the ID.
→ show number (currentId) updates the display.
else if <button B pressed>
→ change (currentId) by (–1) decreases the ID.
→ show number (currentId) updates the display.
else if <logo pressed>
→ HuskyLens forget all learning data of the current algorithm erases training data.
→ show icon (Skull) confirms deletion.
Before the loop repeats:
pause (ms) (500) → debounces button presses.
show number (currentId) → keeps the current ID visible.