WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

segled.h

Support for an 8 segment LED display.
An 8 segment LED display provides the capability of a single digit on a typical desktop calculator. The 8 segments are made up from 7 vertical or horizontal bars and a decimal point.
These 8 elements are labelled from 'a' to 'h' as follows:-
--a---
|    |
f    b
|    |
--g---
|    |
e    c
|    |
--d--- h
Each of the above elements is turned on or off using an output pin. So we require 8 output pins to control the led segment.
To create a single led we must create it: specifying the output pins for each segment. So, for example, in sys/Axon2.h we specify:
#include "../segled.h"
SEGLED led_display = MAKE_SEGLED(C3,C2,C0,D6,D7,C4,C5,null,FALSE);
There are two things to note here:
1. The first 8 parameters specify the output pins for the segments 'a' to 'h' and you will see that the value for 'h' is 'null' - this means that the decimal point (segment h) is not connected - because we are using elsewhere for the status LED.
2. The last parameter 'FALSE' denotes whether the segments are lit by a high output. Since we say 'FALSE' then each segement is lit by setting the output pin to low.
On an Axon II the LED display is built onto the board and so the above declaration is automatically done for you in axon2.h. If you have added an LED display yourself then you will need to define it yourself in a manner similar to above.
Ok - so we have an LED - but what can we do with it?
Well the first thing is that we can write a character to it using segled_put_char(SEGLED* led, uint8_t byte) This allows us to display an individual character on a specific LED. The supported characters are:
Whilst this is useful - we often want to display a whole message rather than a single character.
So if we had 'one or more' such devices then we could create a calculator style display ie one line of many digits.
This library allows you to do just that - and then scroll the message across the display. This is called a 'marquee' and Windows users may well have used the screen saver with that name/effect.
We have seen above how to define a single 'digit' using MAKE_SEGLED but we could of course use additional output pins, and hardware, to add additional 'digits'.
So the first step to create a marquee is to specify the list of digits that are involved. Example: if we are only using the single on-board digit for the Axon II then this can be done via:
// Create list of 7 segment leds. There is only 1 on the Axon II
SEGLED_LIST PROGMEM _leds_[] = {&led_display};
Now we create a 'marquee' to scroll messages across that list of digits.
// Create a marquee to scroll text along these leds
MAKE_WRITER(marquee_put_char); // Forward definition
MARQUEE marquee = MAKE_MARQUEE(_leds_, (TICK_COUNT)600000, (TICK_COUNT)2000000, &marquee_put_char);
// Now define a Writer that can send data to the marquee
MAKE_WRITER(marquee_put_char){
    return marqueeSendByte(&marquee,byte);
}
The first parameter to the MAKE_MARQUEE is the list of LED digits used to show a portion of the message.
The second parameter is the delay in microseconds (ie 250ms) for scrolling.
The third parameter is the delay in microseconds (ie 1 second) to pause at the end of the message before starting to show the message again. A value of 0 means that the message will only be shown once - a 'one-shot message'.
The final parameter is the address of a Writer routine which can be used to write data to this marquee.
That may sound complex - but dont worry - the axon2.h already defines all of the above for the built in LED digit.
For Axon II builds then note that the defaults are:
The delays can also be modified at runtime. For example the values specified in the above example of MAKE_MARQUEE can be modified using:
When the message is scrolling across the marquee then there will be a brief flash if, and only if, the displayed characters for frame N are the same as for frame N-1. So if the message 'Webbot' is being scrolled across a single LED then there will be a brief flash to separate the two 'b' characters. However: there would be not flash if there are two leds as the sequence 'We', 'eb', 'bb', 'bo' and 'ot' are all unique.

 

Function

 


void segled_init(SEGLED* led)

Initialise the LED ie turn all segments off.

uint8_t segled_put_char(SEGLED* led, uint8_t byte)

Output a character to the LED display.
The return value is the same character.
The first parameter specifies the 8 segment LED to output the data to, and the second parameter is the character to be output.
Given the restrictions of such a simple display then only certain characters can be shown. Currently supported are:
NB If the LED display does not support the decimal point (segment 'h') then the '.' character will be shown by using segment 'd' instead. This is done so that numbers, with decimal points, can be shown with some indication as to where the decimal point should occur.
So we now have a single character display, well on the Axon II at least. But of course there is nothing to stop you adding hardware for additional ones: on the Axon II or any other board - you are only limited by output pins. The result is a calculator like display of one or more 'digits'.
Whilst it is sometimes useful to be able to set each 'digit' to its own value independently it is also useful to be able to use this calculator display to display a single message. Often this message is longer than the number of available 'digits'. To overcome this problem we use what is known as a 'marquee'. Windows users may well be familiar with 'marquee' as a screen saver but if you are not then it is also similar to those billboards - ie a scrolling message.
In order to create a marquee effect we need to tell the library about all the individual digits that can be used to display a portion of the message. This would be at least one but may be more.
Looking at axon2.h we can see how it is defined for a single 'digit':
// Define the on-board digit display - ignoring the decimal point used as the status led
SEGLED led_display = MAKE_SEGLED(C3,C2,C0,D6,D7,C4,C5,null,FALSE);
 
// Create list of 7 segment leds. There is only 1 on the Axon II
SEGLED_LIST PROGMEM _leds_[] = {&led_display};
 
// Create a marquee to scroll text along these leds
MARQUEE marquee = MAKE_MARQUEE(_leds_, (TICK_COUNT)600000, (TICK_COUNT)1000000);
led_display is the definition of a single digit.
_leds_ is the list of 'digits' across the calculator display - there is only one
The MAKE_MARQUEE command specifies the list of _leds_ to use, the TICK_COUNT in microseconds to use when scrolling (600ms), and the TICK_COUNT to pause before repeating the message (1 second).
Since the Axon II has a built-in LED digit then any error codes are automatically defaulted to be displayed as a marquee using this digit unless subsequently redirected by you by calling setErrorLog.

void segled_on(SEGLED* led, SEGLED_SEGMENT segment)

Turn on an individual segment of the LED display.
The first parameter is the address of the display.
The second parameter is the segment and can be any of the following:
SEGMENT_A
SEGMENT_B
SEGMENT_C
SEGMENT_D
SEGMENT_E
SEGMENT_F
SEGMENT_G
SEGMENT_H
On the Axon II the on board LED display is called 'led_display'. So to turn on segment E then we write:
segled_on(&led_display, SEGMENT_E);

void segled_off(SEGLED* led, SEGLED_SEGMENT segment)

Turn off an individual segment of the LED display.
The first parameter is the address of the display.
The second parameter is the segment and can be any of the following:
SEGMENT_A
SEGMENT_B
SEGMENT_C
SEGMENT_D
SEGMENT_E
SEGMENT_F
SEGMENT_G
SEGMENT_H
On the Axon II the on board LED display is called 'led_display'. So to turn off segment E then we write:
segled_off(&led_display, SEGMENT_E);

void segled_set(SEGLED* led, SEGLED_SEGMENT segment, boolean value)

Turn on or off an individual segment of the LED display.
The first parameter is the address of the display.
The second parameter is the segment and can be any of the following:
SEGMENT_A
SEGMENT_B
SEGMENT_C
SEGMENT_D
SEGMENT_E
SEGMENT_F
SEGMENT_G
SEGMENT_H
The last parameter is a boolean value. If this is TRUE then the segment is turned on, otherwise it is turned off.
On the Axon II the on board LED display is called 'led_display'. So to turn off segment E then we could write:
segled_set(&led_display, SEGMENT_E, FALSE);

marqueeStop(MARQUEE* marquee)

Stop an auto-repeating marquee message.
If there is an existing message being scrolled repetitively then this will cause it to be stopped in a clean fashion. ie not necessarily immediately but will at least guarantee that it will not start from the beginning again.

boolean marqueeIsActive(const MARQUEE * marquee)

Does the marquee have an active scrolling message?
If the marquee was created as a repeating message, and a message has been set, then this will always return TRUE unless marqueeStop(MARQUEE* marquee) is called to stop it.
If this is a one shot message then this will return TRUE until the whole message has been displayed when it will then display FALSE.

marqueeSetCharDelay(MARQUEE* marquee,TICK_COUNT delay)

Change the duration (in microseconds) for scrolling characters in the marquee.
Note that this may not take effect until the next message scroll.

marqueeSetEndDelay(MARQUEE* marquee,TICK_COUNT delay)

Change the delay for an auto-repeating message or make it non-repeating by specifying a delay of 0.
Note that this may not take effect immediately.

Writer marqueeGetWriter(MARQUEE* marquee)

Returns a Writer that can be used to write to the marquee.
The returned writer is normally passed to rprintfInit to redirect rprintf to the marquee.
For example on the Axon II:-
rprintfInit( marqueeGetWriter(&marquee) );
will redirect all rprintf statements to output to the onboard LED.

Valid XHTML 1.0 Transitional