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

(Legacy Version) Propeller C Programming with the ActivityBot

Curriculum

  • 1 Section
  • 48 Lessons
  • Lifetime
Expand all sectionsCollapse all sections
  • (Legacy Version) Propeller C Programming with the ActivityBot
    48
    • 1.1
      Mechanical Assembly
    • 1.2
      Check your Hardware
    • 1.3
      Step 1 – Prepare your Encoders
    • 1.4
      Step 2 – Prepare the Tires
    • 1.5
      Step 3 – Prepare the Chassis
    • 1.6
      Step 4 – Prepare the Servos
    • 1.7
      Step 5 – Mount the Right Servo
    • 1.8
      Step 6 – Mount the Left Servo
    • 1.9
      Step 7 – Mount the Right Encoder
    • 1.10
      Step 8 – Mount the Left Encoder
    • 1.11
      Step 9 – Mount the Battery Pack
    • 1.12
      Step 10 – Mount the Tail Wheel
    • 1.13
      Step 11 – Mount the Drive Wheels
    • 1.14
      Step 12 – Mount the Activity Board
    • 1.15
      Electrical Connections
    • 1.16
      Software and Programming
    • 1.17
      Circuit Practice
    • 1.18
      Powering & Connecting Circuits
    • 1.19
      Blinks
    • 1.20
      Beeps
    • 1.21
      Navigation Basics
    • 1.22
      Test Feedback 360° Servos
    • 1.23
      Calibrate Feedback 360° Encoders
    • 1.24
      Test the External Encoders
    • 1.25
      Calibrate External Encoders
    • 1.26
      Go Certain Distances
    • 1.27
      Set Certain Speeds
    • 1.28
      Navigate by Touch
    • 1.29
      Build the Whiskers
    • 1.30
      Test the Whiskers
    • 1.31
      Inside the Whisker Circuit (Optional)
    • 1.32
      Add Whisker Indicator Lights
    • 1.33
      Whisker-Wheel Response
    • 1.34
      Roaming with Whiskers
    • 1.35
      Navigate by Ultrasound
    • 1.36
      Build and Test the Ping))) Sensor Circuit
    • 1.37
      Roaming with Ultrasound
    • 1.38
      Follow Objects with Ultrasound
    • 1.39
      Navigate by Visible Light
    • 1.40
      Build the Light Sensor Circuits
    • 1.41
      Using the Measurements
    • 1.42
      Roaming with Light Sensors
    • 1.43
      Navigate by Infrared Flashlights
    • 1.44
      Build the IR Sensor Circuits
    • 1.45
      Test the IR Sensor Circuits
    • 1.46
      Roaming with Infrared Flashlights
    • 1.47
      Extras
    • 1.48
      Troubleshooting

Whisker-Wheel Response

Now let’s try a program that makes the robot back up while you push and hold a whisker up against its breadboard post. 

  • Click SimpleIDE’s Open Project button.
  • Navigate to …DocumentsSimpleIDELearnExamplesRobotsActivityBot.
  • Open Whiskers Push Bot.side
  • Set the PWR switch to 1.
  • Click the Load EEPROM & Run button. Wait for it to finish loading and then switch PWR to 0 (off).
  • Disconnect your Bot from the USB cable and place it on the floor (do not let it roam on a desk or other elevated surface).
  • Set the PWR switch to 2.
  • Press and hold one of the whiskers against its contact post.  The robot should back up as long as you keep the whisker pressed. 

 

How it Works

Before starting the while(1) loop, the program has its usual freqout call to make the speaker beep.

Inside the main function’s while(1) loop, the first two lines should look familiar: they test the whisker input states and assign the result to wL and wR. 

Next, we have if((wL == 0) || (wR == 0)) followed by a code block.  It means, “if wL stores 0 OR wR stores 0, do what is inside the code block.”  So, if either variable does store 0, then, drive_speed(-64, -64) runs the robot’s servos backwards for 20 ms. 

If neither whisker variable stores a 0, the program execution skips that if… code block and moves on to the else code block below.  There, it stops both servos with drive_speed(0, 0). 

/*
  Whiskers Push Bot.c
  Push the whiskers to make the Propeller ActivityBot back up.
*/

#include "simpletools.h"                      // Include simpletools header
#include "abdrive.h"                          // Include abdrive header

int main()                                    // main function
{
  freqout(4, 2000, 3000);                     // Speaker tone: 2 s, 3 kHz

  while(1)
  {
    // Check whisker states.
    int wL = input(7);                        // Left whisker -> wL variable
    int wR = input(8);                        // Right whisker -> wR variable

    // If whisker pressed, back up
    if((wL == 0) || (wR == 0))                // Either whisker detects
    {
      drive_speed(-64, -64);                  // Back up
    }
    else                                      // Neither whisker detects
    {
      drive_speed(0, 0);                      // Stay still
    }
  }
}

Try This

Here is a modified loop for your main function.  It replaces the if…else statements with code that allow you to push one whisker at a time to make it turn away to one side or the other, or both whiskers to make it move straight backwards.

  • Click the Save As Project button. 
  • Name the project Whiskers Push Bot Improved.
  • Add the new variables speedLeft and speedRight above main.
  • Modify the while (1) loop so that it uses the two new if… statements and variables, matching the one above.
  • Click the Load EEPROM & Run button.
  • Press and hold each whisker. Holding individual whiskers should make it turn, and holding both whiskers should make it back up.

 

Your Turn

  • Modify Whiskers Push Bot.side so that it makes the robot back up for one full second each time you press a whisker.

 


Printer-friendly version
Add Whisker Indicator Lights
Prev
Roaming with Whiskers
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2026 Parallax Learn • Built with GeneratePress