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
  • QTI Line Following ActivityBot with BlocklyProp

QTI Line Following ActivityBot with BlocklyProp

Line Following using Arrays

Now that you are sure your line follower is working well, try experimenting with arrays as another approach to building your BlocklyProp program.  Think of an array as a numbered list of data elements. Your code can refer to a particular data element by its list number.    Now, imagine your list numbering uses binary numbers instead of decimal numbers. 

Remember the table of wheel speeds from the previous page?  The binary numbers created by the QTI sensors can be used as array list numbers, and the left and right wheel speed values can be used as array elements.

binary left = right = behavior
1000 16 32 pivot left
1100 32 48 sharp left
1110 48 64 left
0100 56 64 slight left
0110 64 64 forward
0010 64 56 slight right
0111 64 48 right
0011 48 32 sharp right
0001 32 16 pivot right

The binary numbers in the column above represent the output of the four QTI sensors – but binary is also a way to represent an integer. The next table shows each of the binary numbers and their decimal equivalents:

binary decimal left = right = behavior
1000 8 16 32 pivot left
1100 12 32 48 sharp left
1110 14 48 64 left
0100 4 56 64 slight left
0110 6 64 64 forward
0010 2 64 56 slight right
0111 7 64 48 right
0011 3 48 32 sharp right
0001 1 32 16 pivot right

 

Next, we will sort the table by the decimal representation of the QTI sensors’ output, and leave blanks for the in-between numbers:

binary decimal left = right = behavior
  0 0 0  
0001 1 32 16 pivot right
0010 2 64 56 slight right
0011 3 48 32 sharp right
0100 4 56 64 slight left
  5 0 0  
0110 6 64 64 forward
0111 7 64 48 right
1000 8 16 32 pivot left
  9 0 0  
  10 0 0  
  11 0 0  
1100 12 32 48 sharp left
  13 0 0  
1110 14 48 64 left
  15 0 0  

Then, let’s turn these into lists, filling in the blanks with zeros:

  • Left = 0,32,64,48,56,0,64,64,16,0,0,0,32,0,48,0
  • Right = 0,16,56,32,64,0,64,48,32,0,0,0,48,0,64,0

These values can then be used to fill an array for each side, left and right:

Now, instead of the large switch…case block – you can use the array values. You will add an if…do block to handle the cases that have been filled with zeros by using the leftPrev and rightPrev variables:

Try this

With shorter code, it’s easier to customize the behavior of the robot. For example, you can add an else if that looks for all four of the QTI sensors to read 1 (binary 1111, or decimal 15), and when they do, have the robot stop or turncompletely around:

  • Create a shape like this at the end of your line:

  • Have your robot stop, beep, and then turn completely around when it encounters the “end of the line” by adding an else if to the if…do block in your code:

 


Printer-friendly version
Program for Line-Following
Prev

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress