Johan Kritzinger / Mbed 2 deprecated FRDMKL25Z-ShiftBrite

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

shiftBriteDisplay Class Reference

shiftBriteDisplay Class Reference

shiftBriteDisplay class. More...

#include <sbDriver.h>

Public Member Functions

 shiftBriteDisplay (DigitalOut &latch, DigitalOut &enable, DigitalOut &reset, SPI &spiPort, unsigned int moduleCount)
 Constructor See the example code for usage instructions.
void setLed (unsigned int moduleNum, unsigned long int rgbValue)
 used to set the colour for a specific dot (LED) using the RGB system.
void setLed (unsigned int moduleNum, unsigned short int red, unsigned short int green, unsigned short int blue)
 used to set the colour for a specific dot (LED) using the full ability of the ShiftBrite modules.
void setCurrentCorr (unsigned short int red, unsigned short int green, unsigned short int blue)
 used to adjust the maximum current to each colour.
void setCurrentCorr ()
 Overloaded version of above but calls up the stored values.
void displayFrame ()
 used to refresh the display.
void rotateLeft ()
 rotateLeft() is used to shift the whole display colours one step left.
void shiftLeft (unsigned short int inR=0, unsigned short int inG=0, unsigned short int inB=0)
 shiftLeft() is used to shift the whole display colours one step left.
void rotateRight ()
 rotateRight() is used to shift the whole display colours one step right.
void shiftRight (unsigned short int inR=0, unsigned short int inG=0, unsigned short int inB=0)
 shiftRight() is used to shift the whole display colours one step right.
void turnOn ()
 Display output is turned enabled.
void turnOff ()
 Display output is turned disabled.
void flip ()
 Used to exchange display values left to right and right to left.
void invert ()
 Changes all display colours with it's mathematical opposite.

Detailed Description

shiftBriteDisplay class.

Used to write data to one (or more) shiftBrite module(s) via the SPI port on FRDM KL25Z module.

Dynamically allocates storage for each module, based on <moduleCount> provided to the constructor. Takes in references for the required hardware: SPI, Latch, Enable, and, if implemented, Reset. Shiftbrite modules does NOT have a reset line but can be reset by removing the power. The reset line referenced will toggle to allow you to implement the required hardware.

Parameters:
SerialPointer to instance of Serial object.
LatchPin used to control data latching on shiftbrite module.
EnablePin used to control LED output buffers of shiftbrite module.
ResetPin used to signal a circuit that control the +ve power to the shiftbrite modules. This can be ignored if no reset required.
SPIPort to send serial data to shoftbrite module. (Data and Clock).
moduleCountint, the number of connected modules.

Example:

    #include "mbed.h"
    #include "sbDriver.h"
    DigitalOut latch(PTC16);//to LI pin of shiftBrite module
    DigitalOut enable(PTA13);//to EI pin of shiftBrite module
    DigitalOut reset(PTC12);//to power control circuit of your doing - NOT MANDATORY
    SPI spi(PTD2,NC,PTD1);//PDT2 = MOSI to DI and PDT1 to CI of shiftBrite module

    shiftBriteDisplay sbDisplay(latch, enable, reset, spi,6);//for, say, 6 modules wired in SERIES.
    
    //If you wish to change the DOT CORR registers
    sbDisplay.setCurrentCorr(0x78,0x64,0x64);//use values you want to set as default. These are the suggested values
    
    //Now, you can either call a member function to update the actual display OR
    //set it up using a Ticker. This is how you setup a ticker
    Ticker t;
    t.attach_us(&sbDisplay,&shiftBriteDisplay::displayFrame,41666);//call updateFrame 24 times per second (every 41666uS)
    //Ticker will automatically call sbDisplay.displayFrame()
    while(1){
        //Now just fill in the colours you want
        sbDisplay.setLed(0,1023,0,0); //FULL on red on the LAST display in the chain
        sbDisplay.setLed(5,0,1023,0); //FULL on green on first (remember the display has 6 leds in this example) LED
        //etc......
    }
Note:
- Usage of shifBriteDisplay::setLed() member is as follows:
 object.setLed(LedModuleNum,red, green, blue); //where colours are in the range of 0-1023
or
 object.setLed(LedModuleNnum,RGB);// where RGB is in a range from 0x000000 to 0XFFFFFF (0xRRGGBB)
NB, In the second method each colour has a range of 0-255 (0-0xFF) but that is expanded to the full range. This can be convenient but I suggest the first method is the best.

Definition at line 116 of file sbDriver.h.


Constructor & Destructor Documentation

shiftBriteDisplay ( DigitalOut &  latch,
DigitalOut &  enable,
DigitalOut &  reset,
SPI &  spiPort,
unsigned int  moduleCount 
)

Constructor See the example code for usage instructions.

Definition at line 116 of file sbDriver.cpp.


Member Function Documentation

void displayFrame (  )

used to refresh the display.

All colour values are written out.

Definition at line 236 of file sbDriver.cpp.

void flip (  )

Used to exchange display values left to right and right to left.

Definition at line 306 of file sbDriver.cpp.

void invert (  )

Changes all display colours with it's mathematical opposite.

Definition at line 316 of file sbDriver.cpp.

void rotateLeft (  )

rotateLeft() is used to shift the whole display colours one step left.

The first colour is rotated around and shifted in the last dot.

for(loop=0; loop !=NumOfLeds; loop++){
    sbDisplay.rotateLeft();
    sbDisplay.displayFrame();
    wait(0.2);
}

Definition at line 259 of file sbDriver.cpp.

void rotateRight (  )

rotateRight() is used to shift the whole display colours one step right.

The first colour is rotated around and shifted in the last dot.

for(loop=0; loop !=NumOfLeds; loop++){
    sbDisplay.rotateRight();
    sbDisplay.displayFrame();
    wait(0.2);
}

Definition at line 280 of file sbDriver.cpp.

void setCurrentCorr ( unsigned short int  red,
unsigned short int  green,
unsigned short int  blue 
)

used to adjust the maximum current to each colour.

Consists of 3 values, one each for red, green and blue. This allow you to adjust the brightness level of the reds, green and blues. Is usefull if one colour is brighter than the others that causes colours to mix incorrectly. When used it will record the arguments as the default values. Range is from 0 to 127 for each colour. This equated to rought 30% to 100% full brightness. NOTE, This is NOT for setting the brightness of the display (even though it can be abused that way), it is intended for adjusting the brightness balance between colours so that, for example, 0X3FF red and 0X3FF green makes yellow and not reddy-yellow or greeny-yellow etc.

    myDisplay.setCurrentCorr(0x78,0x64,0x64); // set and record values as default. Retained only until master reset or powerdown.

Definition at line 142 of file sbDriver.cpp.

void setCurrentCorr (  )

Overloaded version of above but calls up the stored values.

These can either be the default (as Suggested by the ShiftBrite manufacturer) if they were not overwritten with the alternate member function (above).

Definition at line 184 of file sbDriver.cpp.

void setLed ( unsigned int  moduleNum,
unsigned short int  red,
unsigned short int  green,
unsigned short int  blue 
)

used to set the colour for a specific dot (LED) using the full ability of the ShiftBrite modules.

Each colour is supplied individualy in the range of 0-1023 (0-0x3FF). Example:

    myDisplay.setLed(ledNum,0,512,0);//Set led module 'ledNum' to  half brightness green using a decimal no
    myDisplay.setLed(ledNum+1,0,0x3FF,0); // Set module 'ledNum+1' to full brightness green using a hex no

Definition at line 199 of file sbDriver.cpp.

void setLed ( unsigned int  moduleNum,
unsigned long int  rgbValue 
)

used to set the colour for a specific dot (LED) using the RGB system.

e.g. 0XFF0000 is full blue. I would suggest not using this unless you have no option because it only allows specifying 256 levels for each colour whereas the ShiftBright modules are capable of 1024. Use the overloaded member function. Example:

    myDisplay.setLed(ledNum,0X007F00);//Set led module 'ledNum' to  half brightness green
    myDisplay.setLed(ledNum+1,0X00FF00); // Set module 'ledNum+1' to full brightness green

Definition at line 194 of file sbDriver.cpp.

void shiftLeft ( unsigned short int  inR = 0,
unsigned short int  inG = 0,
unsigned short int  inB = 0 
)

shiftLeft() is used to shift the whole display colours one step left.

A blank dot is shifted in unless a colour is given in the argument.

for(loop=0; loop !=NumOfLeds; loop++){
    sbDisplay.shiftLeft();//or, to shift in a colour .shiftLeft(1000,200,0);
    sbDisplay.displayFrame();
    wait(0.2);
}

Definition at line 269 of file sbDriver.cpp.

void shiftRight ( unsigned short int  inR = 0,
unsigned short int  inG = 0,
unsigned short int  inB = 0 
)

shiftRight() is used to shift the whole display colours one step right.

A blank dot is shifted in unless a colour is given as an argument.

for(loop=0; loop !=NumOfLeds; loop++){
    sbDisplay.shiftRight(); // or, to feed in a colour sbDisplay.shiftRight(0,0XF0,0x30);
    sbDisplay.displayFrame();
    wait(0.2);
}

Definition at line 289 of file sbDriver.cpp.

void turnOff (  )

Display output is turned disabled.

Definition at line 302 of file sbDriver.cpp.

void turnOn (  )

Display output is turned enabled.

Definition at line 299 of file sbDriver.cpp.