Hi,
now I had my first go at a library for the arduino. I love the little thingy, even library-creation
is quite simple!
The question now is , how much memory is one willing to trade for conveniance in software development.
My current implementation will cost you about 1.2 kB of memory and here is what will get for it.
/* Create a new device
* Params :
* int dataPin The pin on the Arduino where data gets shifted out
* int clockPin The pin for the clock
* int csPin The pin for selecting the device when data is to be sent
* int pos Devices can be chained to a single SPI-Line. This is the position
* of the device on the line
* int numDigits The number of digits (or rows) attached to this device
*/
LedControl(int dataPin, int clockPin, int csPin, int pos, int numDigits);
/* Set the shutdown (power saving) mode for the device
* Params :
* boolean b If true the device goes into power-down mode. If false
* device goes into normal operation
*/
void shutdown(bool b);
/* Set the number of digits (or rows) to be displayed.
* See datasheet for sideeffects of the scanlimit on the brightness
* of the display.
* Params :
* int limit The number of digits to be displayed
* Returns:
* boolean false if you try to set the limit to something smaller
* the numDigits param in the constructor.
* true if scan-limit is set to the new value
*/
boolean setScanLimit(int limit);
/* Set the brightness of the display.
* Params:
* int intensity the brightness of the display.
* Only values between 0(darkest) and 15(brightest) are valid.
* Returns:
* boolean false if intensity is not a valid value, true on success.
*/
boolean setIntensity(int intensity);
/* Switch all Leds on the display off. */
void clearDisplay();
/* Set the status for a specific Led.
* Params :
* int row the row in which the led is located
* Only values between 0 and 7 are valid.
* int col the column in which the led is located
* Only values between 0 and 7 are valid.
* boolean state If true the led is switched on, if false it is switched off
* Returns:
* boolean false if either the row or column argument was invalid.
* true on sucess
*/
boolean setLed(int row, int col, boolean state);
/* Set the 8 Led's in a row to a new state
* Params:
* int row The row on which the led's are to be set
* Only values between 0 and 7 are valid.
* byte value A bit set to 1 in this value will light up the
* corresponding led.
* Returns:
* boolean false if the row argumnet was invalid
*/
boolean setRow(int row, byte value);
/* Set the 8 Led's in a column to a new state
* Params:
* int col The column on which the led's are to be set
* Only values between 0 and 7 are valid.
* byte value A bit set to 1 in this value will light up the
* corresponding led.
* Returns:
* boolean false if the col argumnet was invalid
*/
boolean setColumn(int col, byte value);
/* Display a hexadecimal digit on a 7-Segment Display
* Params:
* int digit the position of the digit on the display
* Only values between 0 and the numDigits argument
* from the constructor are valid.
* byte value the value to be displayed.
* Only values between 0x00 and 0x0F are valid.
* boolean dp If true also switches on the decimal point.
* Returns:
* boolean false if the digit or value argument are invalid.
*/
boolean setDigit(int digit, byte value, boolean dp);
/* Display a character on a 7-Segment display.
* The char that can be acutally displayed are obviously quite limited.
* Here is the whole set :
* '0','1','2','3','4','5','6','7','8','9','0','A','b','c','d','E','F','.','-'
* Params:
* int digit the position of the character on the display
* Only values between 0 and the numDigits argument
* from the constructor are valid.
* byte value the character to be displayed. (See the limited set above!)
* boolean dp If true also switches on the decimal point.
* Returns:
* boolean false if the digit or value argument are invalid.
*/
boolean setChar(int digit, char value, boolean dp);
All comments on the function-declaration are very welcome.
Do you think the memory-consumption is way too much for your projects?
Do miss a function for a specific problem?
please speak up!
Status:
The lib already works fine when only a single MAX7221 is hooked up to the board. I ordered 2 more of these today.
I want to do some tests with more than one device before a public release.
But I will send you the code on e-mail request.
Eberhard