Class to interface with Sparkfun's Blackberry Trackball Breakout Board.

Dependents:   BBTrackball_Sample

Embed: (wiki syntax)

« Back to documentation index

CBBTrackball Class Reference

CBBTrackball Class Reference

A class to interface with the Sparkfun Blackberry Trackball Breakout Board. More...

#include <BBTrackball.h>

Data Structures

struct  SColour
 A structure used to represent the colour of the illumination for the trackball. More...
struct  SState
 A structure in which the current state of the trackball is returned from the GetState() method. More...

Public Member Functions

 CBBTrackball (PinName BluePin, PinName RedPin, PinName GreenPin, PinName WhitePin, PinName UpPin, PinName DownPin, PinName LeftPin, PinName RightPin, PinName ButtonPin)
 Create a CBBTrackball object, binds it to the specified input/output pins, and initializes the required interrupt handling.
void GetState (SState *pState)
 Gets current state of the trackball.
void SetColour (const SColour *pColour)
 Sets the colour of the trackball illumination.

Detailed Description

A class to interface with the Sparkfun Blackberry Trackball Breakout Board.

http://www.sparkfun.com/products/9320

This breakout board uses a hall effect for each direction of motion (up, down, left, right) and generates pulses as the trackball is rotated in each of these directions. This class counts both the rising and falling edges of these pulses in an interrupt handler. The main program can query for the number of pulses that have been generated since the previous query was made.

The breakout board also has a push button placed beneath the trackball so that user presses can be detected as well. This class will provide the state of this button as well after filtering it for the purpose of debouncing.

The last feature of this breakout board that is supported by the class includes the 4 LEDs that have been placed beneath the trackball. This class allows the caller to specify an individual brightness value for each of the LEDs (red, blue, green, white).

Example:

#include <mbed.h>
#include <USBMouse.h>
#include "BBTrackball.h"

int main() 
{
    static const CBBTrackball::SColour GreenColour = { 0, 255, 0, 0 };
    static CBBTrackball Trackball(p20,  // BLU
                                  p25,  // RED
                                  p26,  // GRN
                                  p10,  // WHT
                                  p5,   // UP
                                  p6,   // DWN
                                  p7,   // LFT
                                  p8,   // RHT
                                  p9);  // BTN
    static USBMouse     Mouse;
    
    // Turn the green LED on.
    Trackball.SetColour(&GreenColour);
    
    for(;;)
    {
        CBBTrackball::SState    TrackballState;
        int                     DeltaX;
        int                     DeltaY;
        
        Trackball.GetState(&TrackballState);

        // NOTE: The breakout board is rotated 90 degrees on my breadboard.
        DeltaX = TrackballState.Up - TrackballState.Down;
        DeltaY = TrackballState.Right - TrackballState.Left;

        Mouse.update(DeltaX, 
                     DeltaY, 
                     TrackballState.ButtonPressed ? MOUSE_LEFT : 0,
                     0);
    }
}

Definition at line 88 of file BBTrackball.h.


Constructor & Destructor Documentation

CBBTrackball ( PinName  BluePin,
PinName  RedPin,
PinName  GreenPin,
PinName  WhitePin,
PinName  UpPin,
PinName  DownPin,
PinName  LeftPin,
PinName  RightPin,
PinName  ButtonPin 
)

Create a CBBTrackball object, binds it to the specified input/output pins, and initializes the required interrupt handling.

Parameters:
BluePinThe mbed pin which is connected to the BLU pin of the breakout board. Must be a pin on which the mbed supports PwmOut.
RedPinThe mbed pin which is connected to the RED pin of the breakout board. Must be a pin on which the mbed supports PwmOut.
GreenPinThe mbed pin which is connected to the GRN pin of the breakout board. Must be a pin on which the mbed supports PwmOut.
WhitePinThe mbed pin which is connected to the WHT pin of the breakout board. Must be a pin on which the mbed supports PwmOut.
UpPinThe mbed pin which is connected to the UP pin of the breakout board. Must be a pin on which the mbed supports InterruptIn.
DownPinThe mbed pin which is connected to the DWN pin of the breakout board. Must be a pin on which the mbed supports InterruptIn.
LeftPinThe mbed pin which is connected to the LFT pin of the breakout board. Must be a pin on which the mbed supports InterruptIn.
RightPinThe mbed pin which is connected to the RHT pin of the breakout board. Must be a pin on which the mbed supports InterruptIn.
ButtonPinThe mbed pin which is connected to the BTN pin of the breakout board.

Definition at line 140 of file BBTrackball.h.


Member Function Documentation

void GetState ( SState pState )

Gets current state of the trackball.

Returns state indicating how much the trackball has moved in each direction since the last call to GetState() and the current state of the push button.

Parameters:
pStatepoints to the state structure to be filled in with the current state.
void SetColour ( const SColour pColour )

Sets the colour of the trackball illumination.

Parameters:
pColourpoints to the colour structure used to determine the illumination contribution from each of the 4 LEDs found beneath the trackball.