Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses

Respond to Object Coordinates

Curriculum

  • 1 Section
  • 2 Lessons
  • Lifetime
Expand all sectionsCollapse all sections
  • Respond to Object Coordinates
    2
    • 1.0
      Get and Display Coordinates with a Program
    • 1.1
      Navigate to Center on Object Coordinates

Get and Display Coordinates with a Program

In the last lessons you trained the HUSKYLENS and saved your training to a microSD card. Now you’ll read where the camera sees your trained target and plot its position on the micro:bit’s 5×5 LED display (X,Y). This is the first step toward making the robot respond to what it sees.

  • Open the MakeCode editor.

  • Start with your previous project (e.g., Learn Colors or Save Colors).

    • If you need to reopen it, click Import on the MakeCode home page and choose your saved file.

  • Use the Name field next to Download to name this project: Show Object XY.

  • Update your program so it matches the script below.

  • Click the Save (floppy disk) icon to keep a copy.

  • Press Download to load it onto your micro:bit.

Test the Script

This test builds directly on your earlier Learn Colors work.

Power-up the cyber:bot

  • 5 fresh AA batteries (alkaline or recharged NiMH).

  • Battery barrel jack connected.

  • 3-position switch set to 1 (center).

Use your trained color

  1. If needed, load training from microSD (Logo + B) using your previous save/load script.

  2. Press A/B to select the currentId you trained earlier.

Watch the coordinates dot

  1. Point the HUSKYLENS at the trained color.

  2. You should see a single LED dot plotted on the micro:bit display.

  3. Move the target left/right/up/down — the dot should move in the opposite-mapped directions (because we inverted the map to match a “screen-like” view).

  4. If nothing is detected, the screen will clear. Re-center the color and check you selected the correct ID.

Try this (optional)

  • Switch to non-inverted mapping (commented lines in the script) and observe the difference in dot motion.

  • Train a second color as ID 2, press A to switch to ID 2, and verify the dot only appears for that color.

How it Works

This script works like a simple feedback loop, but instead of moving the robot, it gives you a visual display of the object’s position. Each cycle, the HUSKYLENS reports the coordinates of the object’s center (x, y) on its 320×240 camera screen. The program scales those values down to fit the micro:bit’s 5×5 LED display.

The result is that one LED lights up at the location that corresponds to the object’s position in the HUSKYLENS view. If the object moves left, the dot shifts left. If it moves up, the dot shifts up. When nothing is detected, the display clears.

This gives you a direct way to “see what the camera sees” in a simplified form, turning continuous camera data into a quick visual guide that updates in real time.

On start setup

  • cyber:bot → I2C Repeat on (clock signal on pin P5 data on P4) — shares the I²C bus with the HUSKYLENS.

  • Basic → pause (ms) (100) — gives the hardware time to settle.

  • HUSKYLENS → HuskyLens initialize I2C until success — starts communication.

  • HUSKYLENS → HuskyLens switch algorithm to (color recognition) — sets the mode for this lesson.

  • Variables → set (currentId) to (1) — starts with ID 1.

Inside the forever loop

  • if <button A is pressed>
    → Variables → change (currentId) by (1) to move to the next ID.
    → Basic → show number (currentId) to display it.

  • else if <button B is pressed>
    → Variables → change (currentId) by (–1) to move to the previous ID.
    → Basic → show number (currentId) to display it.

  • (after button checks) HUSKYLENS → HuskyLens request data once — updates detections from the camera.

  • if <HUSKYLENS ID (currentId) appears as (block)>
    → HUSKYLENS → read (xCenter) of ID (currentId) into x.
    → HUSKYLENS → read (yCenter) of ID (currentId) into y.
    → Math → map and Math → clamp to convert camera coordinates (320×240) to LED grid (5×5).
    → Basic → clear screen then LED → plot (xLED, yLED) to show the dot.

  • else
    → Basic → clear screen if nothing is detected for this ID.

  • Basic → pause (ms) (80) — small delay so the dot doesn’t flicker.


Printer-friendly version
Navigate to Center on Object Coordinates
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2026 Parallax Learn • Built with GeneratePress