A Robotics Project Page
Google
 
Web    www.PhilBot.com
My other sites
  • OurCoolHouse
  • Phil's Resume
  • Web Portfolio

  • [Home] [Projects] [Hardware] [Software] [Books] [Links] [Downloads]


    BOB: Software: Lesson A - LED Test.          [Back to BOB Software]        [Back to BOB index]

    The first lesson is very simple, and it just sets the ground-work for subsequent tests.

    In this program (PBot_BOB-A_VC6.osc) I start using the I/O definitions described on the main BOB [Software page]. 
    I'm going to use the LED definitions.  These are:

    //-------------------------------------------------------
    // BOB I/O Port definitions
    //-------------------------------------------------------
    Const   IO_LED1                 = 12;   // General Purpose LED 1
    Const   IO_LED2                 = 13;   // General Purpose LED 2
    Const   IO_LED3                 = 14;   // General Purpose LED 3
    Const   IO_LED4                 = 15;   // General Purpose LED 4
    Const   IO_LED_GROUP            = 1;    // LED I/O Group 1    (Lines 8-15)
    Const   IO_LED_NIBBLE           = 1;    // LED I/O High Nible (Lines 12-15)

    There are actually two sets of LED definitions here.  Which ones you use, depends on whether you want to use them as 4 separate LEDs, or a combined group of 4 LEDs. Choosing to use them as a group of 4 is more efficient with respect to Object memory, and in this case we want to treat them as a 4 bit number anyway, so it makes more sense to group them that way.  See Lesson 2 for an example of using the LEDs as individual Bits.

    Here is the code I use to declare the two Objects that I need for this Lesson:

    //-----------------------------------------------------------------
    // User Objects.  Use these to access BOB hardware.
    //-----------------------------------------------------------------
    oCountDownO ActionTimer = New oCountDownO;  // User Timer   

    // LED Object (accessed as group of 4 bits)
    oDIO4       LEDs        = New oDIO4;        // Driver for LEDs

    In my programs, I always use the SetupIO( ) function configure the OOPic "Objects" required to interface to the hardware. 
    Here is the object Setup code for this lesson:.

    //-----------------------------------------------------------------
    //  SetupIO()
    //  Configure all the IO Objects here
    //-----------------------------------------------------------------
    Void    SetupIO( Void )
    {
        // --------------------------------
        // setup the ActionTimer Timer for 1/10th Second ticks 
        // Preload counter with 5 second delay
        // --------------------------------
        ActionTimer.PreScale    = CLOCK_PRESCALE;
        ActionTimer.ClockIn.Link(ooPIC.Hz60);
        ActionTimer             = FIVE_SECONDS;
        ActionTimer.Operate     = cvTrue;
        
        // --------------------------------
        // setup the LED Drivers
        // --------------------------------
        LEDs.IOGroup            = IO_LED_GROUP ;
        LEDs.Nibble             = IO_LED_NIBBLE ;
        LEDs.Direction          = cvOutput ;

        // Turn All LEDs on.
        LEDs.Value              = 15 ;
    }

    Notice that the first thing I always do is configure the ActionTimer object.  It's setup to count down to zero in 1/10th of a second.  I use this capability a lot to pace my programs, or just to insert standard delays.

    Then I configure the LEDs object.  This is an "oDIO4" objects which means a "4 bit Digital Input/Output" object.  This object works for groups of 4 digital I/O lines that start on IOLines 8,12,16,20,24,or 28.  In our case, the LEDs start on line 12, which is Group 1, Nibble 1.  After setting the Group and Nibble, all that remains is to assign a direction, which is Output.  With oDIO4, all the lines must have the same direction, which is perhaps another reason why you might need to use individual oDIO1 objects instead.

    Before exiting the SetupIO( ) function, I set the LEDs.Value to 15, which turns ON all four output bits (15 = 1 + 2 + 4 + 8).  This is just my way of signaling that the program is ready to run.

    Now for the actual program.  Main( ) is the name given to the function that is called when the program starts.  Lesson A's main is quite simple: First it calls SetupIO( ), then it waits for the 5 second timer to expire, and finally it enters an infinite loop incrementing the LEDs value.  After each increment, the program pauses for 0.3 seconds (3/10).  This is just so us slow humans can see the LED's counting in binary code.  If I took out the WaitTenths call then it would appear that the LEDs were just flickering.

    //-----------------------------------------------------------------
    //  BOB Main Program
    //-----------------------------------------------------------------
    Void Main(Void)
    {
        // Always set up the required IO first.
        SetupIO();
        
        // Wait for 5 second "Start Up" to elapse
        While(ActionTimer.NonZero);
            
        // Cycle the 4 LEDs through all 16 states
        While(cvTrue)
        {
            LEDs.Value += 1 ;   // Increment LED value      
            WaitTenths(3);      // Wait 3/10th of a second before continuing.
        }
    }

    For those of you that don't automatically recognize binary numbers, here's a [video] of the LEDs in action.

    Don't forget the full source code for this example is available on the [Download] page (PBot_BOB-A_VC6.osc).

    Next, in [Lesson B] I will experiment with the Proximity Sensors.

     

    Web content is copyright © PhilBot.com 2005, Deep Creek Lake, MD.
    Contact: Phil Malone 301.387.2331, webmaster@PhilBot.com