AberLED shield library
Library for the bicolor LED (and TFT screen) shield used in CS12020
Public Member Functions | Static Public Member Functions | List of all members
AberLEDClass Class Reference

The class for the AberLED shield. One object of this class, called AberLED, is automatically created (similar to how Serial works). Yes, all this time you've been writing C++, not C. You should put AberLED. before every function, so AberLED.begin() instead of just begin(). More...

#include <AberLED.h>

Public Member Functions

void begin (AberLEDFlags flags=AF_TFTDISPLAY, uint8_t *colourMap=NULL)
 Initialises all pin modes, clears the buffers, starts the interrupt and begins to output data to the LED. More...
 
void swap ()
 Call this code to finish drawing operations. It swaps the back and front buffer, so that the newly written back buffer becomes the front buffer and is displayed. More...
 
void set (int x, int y, unsigned char col)
 This sets the given pixel in the back buffer to the given value. The pixel values are 0 (off), 1 (green), 2 (red) or 3 (yellow), but the macros BLACK, GREEN, RED and YELLOW should be used. More...
 
void clear ()
 Set all pixels in the back buffer to black. More...
 
int getButton (unsigned char c)
 Return nonzero if a given switch is pressed - switches are numbered 1 to 5, which is against my Golden Rule of computers numbering things from zero, but that's how they're labelled on the physical board. It's better to use the UP, DOWN, LEFT, RIGHT and FIRE constants instead of numbers. More...
 
int getButtonDown (unsigned char c)
 Return nonzero if the button has been pressed since the last swap(). It's better to use the UP, DOWN, LEFT, RIGHT and FIRE constants instead of numbers. More...
 
uint16_t * getBuffer ()
 Call this to write to the back buffer directly. It returns a pointer to the buffer: a set of 8 16-bit ints, each pair of bits representing a pixel. More...
 
int getTicks ()
 Return the number of interrupt ticks which occurred in the last swap()-swap() cycle. More...
 
void clearText ()
 clear the string which is written to the text area on a TFT display. More...
 
void addToText (const char *s)
 Append a string to the text area on a TFT display. Does nothing if the display is not a TFT display. This just stores the data in an internal variable, the actual writing is done when swap() is called. If the resulting string would be too long, nothing is done. More...
 
void addToText (int n)
 Write a number to the text area - see the string version for details. More...
 

Static Public Member Functions

static void refresh ()
 Use only when interrupts are disabled - copies the front buffer to the display. More...
 
static void setRevision (int rev)
 Call this to set the revision, after AberLED.begin() (which will set it to REV01 by default). Only relevant to LED matrix boards, and only the really old beige ones. You shouldn't ever need to use this. More...
 
static const char * version ()
 return the version string More...
 

Detailed Description

The class for the AberLED shield. One object of this class, called AberLED, is automatically created (similar to how Serial works). Yes, all this time you've been writing C++, not C. You should put AberLED. before every function, so AberLED.begin() instead of just begin().

Warning
If you are using an bicolor LED display, you should call AberLED.begin(AF_LEDDISPLAY)!

Calling begin() will initialise the display, setting all the pins to the appropriate mode and setting up the interrupt handler. Thereafter, every nth of a second the Arduino will automatically send the front buffer to the matrix. Calling getBuffer() will give a pointer to the back buffer, which can be be written to. Alternatively, pixels can be written by calling set() with x,y coordinates and a colour (GREEN, RED, YELLOW or BLACK). Once writing is complete, calling swap() will exchange the front and back buffers, so that the Arduino will now write the new front buffer to the matrix every interrupt tick.

The format of the buffers is 8 16-bit integers: unsigned shorts. Each integer represents a single row. Each pixel - individual LED - is represented by 2 adjacent bits with the most significant bit being red and the least significant bit being green.

Definition at line 87 of file AberLED.h.

Member Function Documentation

void AberLEDClass::addToText ( const char *  s)

Append a string to the text area on a TFT display. Does nothing if the display is not a TFT display. This just stores the data in an internal variable, the actual writing is done when swap() is called. If the resulting string would be too long, nothing is done.

Definition at line 300 of file AberLED.cpp.

void AberLEDClass::addToText ( int  n)

Write a number to the text area - see the string version for details.

Definition at line 314 of file AberLED.cpp.

void AberLEDClass::begin ( AberLEDFlags  flags = AF_TFTDISPLAY,
uint8_t *  colourMap = NULL 
)

Initialises all pin modes, clears the buffers, starts the interrupt and begins to output data to the LED.

Parameters
flagsthe flags to use - AF_LEDDISPLAY for a bicolor LED display, AF_TFTDISPLAY for a TFT display, AF_NOINTERRUPT to use disable interrupts. If you specify AF_NOINTERRUPT, the display will not be refreshed automatically and you will have to call refresh() frequently.
colourMapa pointer to an array of 9 8-bit integers - each triple defines how to convert the 2-bit colour into RGB. The first 3 bytes are for BLACK, the next 3 for GREEN, the next 3 for RED and the last 3 for YELLOW. The default is the "standard" colours but this could be useful for people with colour vision deficiencies.

Definition at line 158 of file AberLED.cpp.

void AberLEDClass::clear ( )

Set all pixels in the back buffer to black.

Definition at line 356 of file AberLED.cpp.

void AberLEDClass::clearText ( )

clear the string which is written to the text area on a TFT display.

Definition at line 291 of file AberLED.cpp.

uint16_t * AberLEDClass::getBuffer ( )

Call this to write to the back buffer directly. It returns a pointer to the buffer: a set of 8 16-bit ints, each pair of bits representing a pixel.

Definition at line 334 of file AberLED.cpp.

int AberLEDClass::getButton ( unsigned char  c)

Return nonzero if a given switch is pressed - switches are numbered 1 to 5, which is against my Golden Rule of computers numbering things from zero, but that's how they're labelled on the physical board. It's better to use the UP, DOWN, LEFT, RIGHT and FIRE constants instead of numbers.

Parameters
cthe button code (UP, DOWN, LEFT, RIGHT or FIRE)

Definition at line 321 of file AberLED.cpp.

int AberLEDClass::getButtonDown ( unsigned char  c)

Return nonzero if the button has been pressed since the last swap(). It's better to use the UP, DOWN, LEFT, RIGHT and FIRE constants instead of numbers.

Parameters
cthe button code (UP, DOWN, LEFT, RIGHT or FIRE)

Definition at line 326 of file AberLED.cpp.

int AberLEDClass::getTicks ( )

Return the number of interrupt ticks which occurred in the last swap()-swap() cycle.

Definition at line 109 of file AberLED.cpp.

void AberLEDClass::refresh ( )
static

Use only when interrupts are disabled - copies the front buffer to the display.

Definition at line 411 of file AberLED.cpp.

void AberLEDClass::set ( int  x,
int  y,
unsigned char  col 
)

This sets the given pixel in the back buffer to the given value. The pixel values are 0 (off), 1 (green), 2 (red) or 3 (yellow), but the macros BLACK, GREEN, RED and YELLOW should be used.

Parameters
xthe x coordinate of the pixel to write (0-7)
ythe y coordinate of the pixel to write (0-7)
colthe colour to use: BLACK, GREEN, RED or YELLOW.

Definition at line 341 of file AberLED.cpp.

void AberLEDClass::setRevision ( int  rev)
static

Call this to set the revision, after AberLED.begin() (which will set it to REV01 by default). Only relevant to LED matrix boards, and only the really old beige ones. You shouldn't ever need to use this.

Parameters
revrevision number - REV00 or REV01.

Definition at line 88 of file AberLED.cpp.

void AberLEDClass::swap ( )

Call this code to finish drawing operations. It swaps the back and front buffer, so that the newly written back buffer becomes the front buffer and is displayed.

Definition at line 259 of file AberLED.cpp.

const char * AberLEDClass::version ( )
static

return the version string

Definition at line 27 of file AberLED.cpp.


The documentation for this class was generated from the following files: