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
  • Visible Light Navigation for the cyber:bot

Visible Light Navigation for the cyber:bot

Light Measurements Graphic Display

The micro:bit module’s display can be used to show which side of the cyber:bot is detecting brighter light.  The following program shows a visual display of where the brigher light is hitting, reflecting the value of the norm_diff_shade variable.  If the light is on the right side, the display will light up a pixel on the right side, if the light is in the middle it will light up a pixel in the middle, and so on.

ERROR FALSE ALARM! On line 11 of the script norm_diff_shade_display, you may see a compiler error warning “Operator “+” not supported for this combination of types.”  This is just a false alarm.  The script actually works just fine, so go ahead and send it to the micro:bit.

Example script: norm_diff_shade_display

  • Use the micro:bit Python Editor to open a previous cyber:bot project, like norm_diff_shade_value or cyberbot-template-with-blink.
  • Set the project’s name to norm_diff_shade_display, update the script so that it matches the one below, and then click Save.
  • Click Send to micro:bit.  
# norm_diff_shade_display

from cyberbot import *
 
while True:                       
    bot(8).write_digital(1)        
    qt_left = bot(8).rc_time(1)   
    bot(6).write_digital(1)        
    qt_right = bot(6).rc_time(1)   
    
    norm_diff_shade = (qt_right / (qt_right + qt_left)) - 0.5
    display.clear()
    
    if norm_diff_shade > -0.5 and norm_diff_shade <= -0.35:
        display.set_pixel(0, 2, 9)
    elif norm_diff_shade > -0.35 and norm_diff_shade <= -0.1:
        display.set_pixel(1, 1, 9)
    elif norm_diff_shade > -0.1 and norm_diff_shade <= 0.1:
        display.set_pixel(2, 0, 9)
    elif norm_diff_shade > 0.1 and norm_diff_shade <= 0.35:
        display.set_pixel(3, 1, 9)
    elif norm_diff_shade > 0.35 and norm_diff_shade < 0.5:
        display.set_pixel(4, 2, 9)
    sleep(50)
  • Set the cyber:bot board’s PWR switch to 1.
  • Try casting different levels of shade over each light sensor, and watch how the pixel in the micro:bit module’s display responds. It should match the illustrations below.
  • Set the cyber:bot board’s PWR switch to 0.

       


Printer-friendly version
Light Measurements for Roaming
Prev
Navigate by Light
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress