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
  • Robotics with the Board of Education Shield for Arduino

Robotics with the Board of Education Shield for Arduino

Activity 7: Maneuver Sequences with Arrays

Some robotics applications require sequences of maneuvers.  You’ll actually see some simple sequence examples in the next chapter when the BOE Shield-Bot detects that it has bumped into an obstacle.  At that point, it has to back up, and then turn before trying to go forward again.  That is a simple sequence with two maneuvers. 

Another example is corridor navigation. The BOE Shield-Bot might have to find a corridor and then go through a sequence of maneuvers to enter it,  before searching for the corridor’s walls.

Other sequences can be more elaborate.  One example of a long and complex maneuver would be for a robotic dance contest.  (Robot dance contests have been gaining popularity in recent years.)  For dancing to an entire song, the robot might need a pretty long list of maneuvers and maneuver times.  If your sketch needs to store lists of maneuvers, the variable array is the best tool for storing these lists.

This activity introduces arrays with some simple musical applications using the piezospeaker.  Then, it examines two different approaches for using arrays to store sequences of maneuvers for playback while the sketch is running.

What’s an Array?

An array is a collection of variables with a common name. Each variable in the array is referred to as an element.  Here is an array declaration with eight elements:

  int note[] = {1047, 1174, 1319, 1397, 1568, 1760, 1976, 2093};

The array’s name is note, and each element in the array can be accessed by its index number. Arrays are zero indexed,  so the elements are numbered 0 to 7. The diagram below shows how note[0] stores 1047, note[1] stores 1174, note[2] stores 1319, and so on, up through note[7], which stores 2093.

Let’s say your code needs to copy note[3], which stores the value 1397, to a variable named myVar.  Your code could do it like this:

myVar = note[3];

Your sketch can change array element values too.  For example, you could change the value 1976 to 1975 with an expression like this:

note[3] = 1975;

An array does not have to be pre-initialized with values like it is in the diagram above.  For example, you could just declare an array with 8 elements like this:

int myArray[8];

Then, your sketch could fill in the values of each element later, perhaps with sensor measurements, values entered from the Serial Monitor, or whatever numbers you need to store.

The diagram below shows the musical notes on the right side of a piano keyboard.  Each key press on a piano key makes a string (or a speaker if it’s electric) vibrate at a certain frequency. 

  • Compare the frequencies of the leftmost eight white keys to the values in the note array. 

Next, let’s use the array to make your BOE Shield-Bot play some musical notes…

 


Printer-friendly version
Activity 6: Custom Maneuver Function
Prev
Using Array Elements
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress