/trunk/libraries/MAX7219/MAX7219.cpp |
---|
0,0 → 1,240 |
/**************************************************************************//** |
* \brief MAX7219 library for Arduino |
* \author Copyright (C) 2011 Julien Le Sech - www.idreammicro.com |
* \version 1.0 |
* \date 20110801 |
* |
* This file is part of the MAX7219 library for Arduino. |
* |
* This library is free software: you can redistribute it and/or modify it under |
* the terms of the GNU Lesser General Public License as published by the Free |
* Software Foundation, either version 3 of the License, or (at your option) any |
* later version. |
* |
* This library is distributed in the hope that it will be useful, but WITHOUT |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
* details. |
* |
* You should have received a copy of the GNU Lesser General Public License |
* along with this program. If not, see http://www.gnu.org/licenses/ |
******************************************************************************/ |
/**************************************************************************//** |
* \file MAX7219.cpp |
******************************************************************************/ |
/****************************************************************************** |
* Header file inclusions. |
******************************************************************************/ |
#include <WProgram.h> |
#include <SPI.h> |
#include <MAX7219.h> |
/****************************************************************************** |
* Private macros. |
******************************************************************************/ |
#define REG_NO_OP 0x00 |
#define REG_DIGIT_0 0x01 |
#define REG_DIGIT_1 0x02 |
#define REG_DIGIT_2 0x03 |
#define REG_DIGIT_3 0x04 |
#define REG_DIGIT_4 0x05 |
#define REG_DIGIT_5 0x06 |
#define REG_DIGIT_6 0x07 |
#define REG_DIGIT_7 0x08 |
#define REG_DECODE_MODE 0x09 |
#define REG_INTENSITY 0x0A |
#define REG_SCAN_LIMIT 0x0B |
#define REG_SHUTDOWN 0x0C |
#define REG_DISPLAY_TEST 0x0F |
/****************************************************************************** |
* Public method definitions. |
******************************************************************************/ |
/**************************************************************************//** |
* \fn MAX7219::MAX7219(byte csPin) |
* |
* \brief Constructor. |
* |
* \param csPin Chip select pin number. |
******************************************************************************/ |
MAX7219::MAX7219 |
( |
byte csPin |
){ |
m_csPin = csPin; |
} |
/**************************************************************************//** |
* \fn void MAX7219::initialize() |
* |
* \brief Initialize SPI to drive MAX7219. |
******************************************************************************/ |
void |
MAX7219::initialize() |
{ |
// Configure chip select pin as output. |
pinMode(m_csPin, OUTPUT); |
// Wait a little to allow MAX7219 to see a correct logic level on CS pin. |
delay(1); |
// Configure SPI. |
SPI.begin(); |
SPI.setBitOrder(MSBFIRST); |
SPI.setDataMode(SPI_MODE0); |
SPI.setClockDivider(SPI_CLOCK_DIV4); |
} |
/**************************************************************************//** |
* \fn void MAX7219::setDecodeMode(DecodeModes mode) |
* |
* \brief Set MAX7219 decode mode. |
* |
* \param mode Decode mode to set. |
******************************************************************************/ |
void |
MAX7219::setDecodeMode |
( |
DecodeModes mode |
){ |
write(REG_DECODE_MODE, mode); |
} |
/**************************************************************************//** |
* \fn void MAX7219::setIntensity(Intensities intensity) |
* |
* \brief Set MAX7219 intensity. |
* |
* \param itensity Intensity to set. |
******************************************************************************/ |
void |
MAX7219::setIntensity |
( |
Intensities intensity |
){ |
write(REG_INTENSITY, intensity); |
} |
/**************************************************************************//** |
* \fn void MAX7219::setScanLimit(ScanLimits limit) |
* |
* \brief Set MAX7219 scan limit. |
* |
* \param limit Scan limit to set. |
******************************************************************************/ |
void |
MAX7219::setScanLimit |
( |
ScanLimits limit |
){ |
write(REG_SCAN_LIMIT, limit); |
} |
/**************************************************************************//** |
* \fn void MAX7219::setShutdownMode(ShutdownModes mode) |
* |
* \brief Set MAX7219 shutdown mode. |
* |
* \param mode Shutdown mode to set. |
******************************************************************************/ |
void |
MAX7219::setShutdownMode |
( |
ShutdownModes mode |
){ |
write(REG_SHUTDOWN, mode); |
} |
/**************************************************************************//** |
* \fn void MAX7219::setDisplayTestMode(DisplayTestModes mode) |
* |
* \brief Set MAX7219 display test mode. |
* |
* \param mode Display test mode to set. |
******************************************************************************/ |
void |
MAX7219::setDisplayTestMode |
( |
DisplayTestModes mode |
){ |
write(REG_DISPLAY_TEST, mode); |
} |
/**************************************************************************//** |
* \fn void MAX7219::writeDigit( |
* Digits digit, |
* Characters character, |
* bool decimalPoint) |
* |
* \brief Write character on digit. |
* |
* \param digit Digit to write. |
* \param character Character to write. |
* \param decimalPoint Display decimal point if true. |
******************************************************************************/ |
void |
MAX7219::writeDigit |
( |
Digits digit, |
Characters character, |
bool decimalPoint |
){ |
byte value = character; |
if (decimalPoint) |
{ |
// If decimal point must be switched on. |
value |= Segment_DP; |
} |
write(digit, value); |
} |
/**************************************************************************//** |
* \fn void MAX7219::writeDigit(Digits digit, Segments segments) |
* |
* \brief Set segment(s) on digit. |
* |
* \param digit Digit to write. |
* \param segment Segment(s) to set. |
******************************************************************************/ |
void |
MAX7219::writeDigit |
( |
Digits digit, |
Segments segments |
){ |
write(digit, segments); |
} |
/****************************************************************************** |
* Private method definitions. |
******************************************************************************/ |
/**************************************************************************//** |
* \fn void MAX7219::write(byte address, byte value) |
* |
* \brief Write value into MAX7219 register. |
* |
* \param address Register address. |
* \param value Value to write. |
******************************************************************************/ |
void |
MAX7219::write |
( |
byte address, |
byte value |
){ |
// Reset chip select pin to select the device. |
digitalWrite(m_csPin, LOW); |
// Transmit data to the device, register address and value. |
SPI.transfer(address); |
SPI.transfer(value); |
// Set chip select pin to valid data onto the device. |
digitalWrite(m_csPin, HIGH); |
} |
/trunk/libraries/MAX7219/lgpl-3.0.txt |
---|
0,0 → 1,165 |
GNU LESSER GENERAL PUBLIC LICENSE |
Version 3, 29 June 2007 |
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> |
Everyone is permitted to copy and distribute verbatim copies |
of this license document, but changing it is not allowed. |
This version of the GNU Lesser General Public License incorporates |
the terms and conditions of version 3 of the GNU General Public |
License, supplemented by the additional permissions listed below. |
0. Additional Definitions. |
As used herein, "this License" refers to version 3 of the GNU Lesser |
General Public License, and the "GNU GPL" refers to version 3 of the GNU |
General Public License. |
"The Library" refers to a covered work governed by this License, |
other than an Application or a Combined Work as defined below. |
An "Application" is any work that makes use of an interface provided |
by the Library, but which is not otherwise based on the Library. |
Defining a subclass of a class defined by the Library is deemed a mode |
of using an interface provided by the Library. |
A "Combined Work" is a work produced by combining or linking an |
Application with the Library. The particular version of the Library |
with which the Combined Work was made is also called the "Linked |
Version". |
The "Minimal Corresponding Source" for a Combined Work means the |
Corresponding Source for the Combined Work, excluding any source code |
for portions of the Combined Work that, considered in isolation, are |
based on the Application, and not on the Linked Version. |
The "Corresponding Application Code" for a Combined Work means the |
object code and/or source code for the Application, including any data |
and utility programs needed for reproducing the Combined Work from the |
Application, but excluding the System Libraries of the Combined Work. |
1. Exception to Section 3 of the GNU GPL. |
You may convey a covered work under sections 3 and 4 of this License |
without being bound by section 3 of the GNU GPL. |
2. Conveying Modified Versions. |
If you modify a copy of the Library, and, in your modifications, a |
facility refers to a function or data to be supplied by an Application |
that uses the facility (other than as an argument passed when the |
facility is invoked), then you may convey a copy of the modified |
version: |
a) under this License, provided that you make a good faith effort to |
ensure that, in the event an Application does not supply the |
function or data, the facility still operates, and performs |
whatever part of its purpose remains meaningful, or |
b) under the GNU GPL, with none of the additional permissions of |
this License applicable to that copy. |
3. Object Code Incorporating Material from Library Header Files. |
The object code form of an Application may incorporate material from |
a header file that is part of the Library. You may convey such object |
code under terms of your choice, provided that, if the incorporated |
material is not limited to numerical parameters, data structure |
layouts and accessors, or small macros, inline functions and templates |
(ten or fewer lines in length), you do both of the following: |
a) Give prominent notice with each copy of the object code that the |
Library is used in it and that the Library and its use are |
covered by this License. |
b) Accompany the object code with a copy of the GNU GPL and this license |
document. |
4. Combined Works. |
You may convey a Combined Work under terms of your choice that, |
taken together, effectively do not restrict modification of the |
portions of the Library contained in the Combined Work and reverse |
engineering for debugging such modifications, if you also do each of |
the following: |
a) Give prominent notice with each copy of the Combined Work that |
the Library is used in it and that the Library and its use are |
covered by this License. |
b) Accompany the Combined Work with a copy of the GNU GPL and this license |
document. |
c) For a Combined Work that displays copyright notices during |
execution, include the copyright notice for the Library among |
these notices, as well as a reference directing the user to the |
copies of the GNU GPL and this license document. |
d) Do one of the following: |
0) Convey the Minimal Corresponding Source under the terms of this |
License, and the Corresponding Application Code in a form |
suitable for, and under terms that permit, the user to |
recombine or relink the Application with a modified version of |
the Linked Version to produce a modified Combined Work, in the |
manner specified by section 6 of the GNU GPL for conveying |
Corresponding Source. |
1) Use a suitable shared library mechanism for linking with the |
Library. A suitable mechanism is one that (a) uses at run time |
a copy of the Library already present on the user's computer |
system, and (b) will operate properly with a modified version |
of the Library that is interface-compatible with the Linked |
Version. |
e) Provide Installation Information, but only if you would otherwise |
be required to provide such information under section 6 of the |
GNU GPL, and only to the extent that such information is |
necessary to install and execute a modified version of the |
Combined Work produced by recombining or relinking the |
Application with a modified version of the Linked Version. (If |
you use option 4d0, the Installation Information must accompany |
the Minimal Corresponding Source and Corresponding Application |
Code. If you use option 4d1, you must provide the Installation |
Information in the manner specified by section 6 of the GNU GPL |
for conveying Corresponding Source.) |
5. Combined Libraries. |
You may place library facilities that are a work based on the |
Library side by side in a single library together with other library |
facilities that are not Applications and are not covered by this |
License, and convey such a combined library under terms of your |
choice, if you do both of the following: |
a) Accompany the combined library with a copy of the same work based |
on the Library, uncombined with any other library facilities, |
conveyed under the terms of this License. |
b) Give prominent notice with the combined library that part of it |
is a work based on the Library, and explaining where to find the |
accompanying uncombined form of the same work. |
6. Revised Versions of the GNU Lesser General Public License. |
The Free Software Foundation may publish revised and/or new versions |
of the GNU Lesser General Public License from time to time. Such new |
versions will be similar in spirit to the present version, but may |
differ in detail to address new problems or concerns. |
Each version is given a distinguishing version number. If the |
Library as you received it specifies that a certain numbered version |
of the GNU Lesser General Public License "or any later version" |
applies to it, you have the option of following the terms and |
conditions either of that published version or of any later version |
published by the Free Software Foundation. If the Library as you |
received it does not specify a version number of the GNU Lesser |
General Public License, you may choose any version of the GNU Lesser |
General Public License ever published by the Free Software Foundation. |
If the Library as you received it specifies that a proxy can decide |
whether future versions of the GNU Lesser General Public License shall |
apply, that proxy's public statement of acceptance of any version is |
permanent authorization for you to choose that version for the |
Library. |
/trunk/libraries/MAX7219/examples/MAX7219.pde |
---|
0,0 → 1,91 |
/**************************************************************************//** |
* \brief MAX7219 library for Arduino - Demo program |
* \author Copyright (C) 2011 Julien Le Sech - www.idreammicro.com |
* \version 1.0 |
* \date 20110801 |
* |
* This file is part of the MAX7219 library for Arduino. |
* |
* This library is free software: you can redistribute it and/or modify it under |
* the terms of the GNU Lesser General Public License as published by the Free |
* Software Foundation, either version 3 of the License, or (at your option) any |
* later version. |
* |
* This library is distributed in the hope that it will be useful, but WITHOUT |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
* details. |
* |
* You should have received a copy of the GNU Lesser General Public License |
* along with this program. If not, see http://www.gnu.org/licenses/ |
******************************************************************************/ |
/**************************************************************************//** |
* \file MAX7219.pde |
******************************************************************************/ |
/****************************************************************************** |
* Header file inclusions. |
******************************************************************************/ |
#include <WProgram.h> |
#include <SPI.h> |
#include <MAX7219.h> |
/****************************************************************************** |
* Private variable declaration. |
******************************************************************************/ |
static MAX7219 max7219(10); |
/****************************************************************************** |
* Public function definitions. |
******************************************************************************/ |
/**************************************************************************//** |
* \fn void setup() |
******************************************************************************/ |
void setup() |
{ |
// Initiliaze MAX7219. |
max7219.initialize(); |
// Set scan limit. |
max7219.setScanLimit(MAX7219::ScanLimit_Digit0To7); |
// Set decode mode. |
max7219.setDecodeMode(MAX7219::DecodeMode_AllDigits); |
// Set intensity. |
max7219.setIntensity(MAX7219::Intensity_Level15); |
// Set shutdown mode. |
max7219.setShutdownMode(MAX7219::ShutdownMode_NormalOperation); |
} |
/**************************************************************************//** |
* \fn void loop() |
******************************************************************************/ |
void loop() |
{ |
// To write digit values, a loop may be more elegant but a bit more |
// complicated for this example. |
// Write digit 0 value. |
max7219.writeDigit(MAX7219::Digit_0, MAX7219::Character_Zero); |
// Write digit 1 value. |
max7219.writeDigit(MAX7219::Digit_1, MAX7219::Character_One); |
// Write digit 2 value. |
max7219.writeDigit(MAX7219::Digit_2, MAX7219::Character_Two); |
// Write digit 3 value. |
max7219.writeDigit(MAX7219::Digit_3, MAX7219::Character_Three); |
// Write digit 4 value. |
max7219.writeDigit(MAX7219::Digit_4, MAX7219::Character_Four); |
// Write digit 5 value. |
max7219.writeDigit(MAX7219::Digit_5, MAX7219::Character_Five); |
// Write digit 6 value. |
max7219.writeDigit(MAX7219::Digit_6, MAX7219::Character_Six); |
// Write digit 7 value. |
max7219.writeDigit(MAX7219::Digit_7, MAX7219::Character_Seven); |
// Wait a little before next loop. |
delay(1000); |
} |
/trunk/libraries/MAX7219/MAX7219.h |
---|
0,0 → 1,319 |
/**************************************************************************//** |
* \brief MAX7219 library for Arduino |
* \author Copyright (C) 2011 Julien Le Sech - www.idreammicro.com |
* \version 1.0 |
* \date 20110801 |
* |
* This file is part of the MAX7219 library for Arduino. |
* |
* This library is free software: you can redistribute it and/or modify it under |
* the terms of the GNU Lesser General Public License as published by the Free |
* Software Foundation, either version 3 of the License, or (at your option) any |
* later version. |
* |
* This library is distributed in the hope that it will be useful, but WITHOUT |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
* details. |
* |
* You should have received a copy of the GNU Lesser General Public License |
* along with this program. If not, see http://www.gnu.org/licenses/ |
******************************************************************************/ |
/**************************************************************************//** |
* \headerfile MAX7219.h |
******************************************************************************/ |
#ifndef MAX7219_h |
#define MAX7219_h |
/****************************************************************************** |
* Header file inclusions. |
******************************************************************************/ |
#include <WProgram.h> |
/**************************************************************************//** |
* \class MAX7219 |
******************************************************************************/ |
class MAX7219 |
{ |
public: |
/******************************************************************//** |
* \enum DecodeModes |
* \typedef DecodeMode_t |
**********************************************************************/ |
typedef enum DecodeModes |
{ |
DecodeMode_NoDecode = 0x00, |
DecodeMode_Digit0 = 0x01, |
DecodeMode_Digit1 = 0x02, |
DecodeMode_Digit2 = 0x04, |
DecodeMode_Digit3 = 0x08, |
DecodeMode_Digit4 = 0x10, |
DecodeMode_Digit5 = 0x20, |
DecodeMode_Digit6 = 0x40, |
DecodeMode_Digit7 = 0x80, |
DecodeMode_AllDigits = 0xFF |
} DecodeMode_t; |
/******************************************************************//** |
* \enum DecodeModes |
* \typedef DecodeMode_t |
**********************************************************************/ |
typedef enum Intensities |
{ |
Intensity_Level0 = 0x00, |
Intensity_Level1 = 0x01, |
Intensity_Level2 = 0x02, |
Intensity_Level3 = 0x03, |
Intensity_Level4 = 0x04, |
Intensity_Level5 = 0x05, |
Intensity_Level6 = 0x06, |
Intensity_Level7 = 0x07, |
Intensity_Level8 = 0x08, |
Intensity_Level9 = 0x09, |
Intensity_Level10 = 0x0A, |
Intensity_Level11 = 0x0B, |
Intensity_Level12 = 0x0C, |
Intensity_Level13 = 0x0D, |
Intensity_Level14 = 0x0E, |
Intensity_Level15 = 0x0F |
} Intensity_t; |
/******************************************************************//** |
* \enum ScanLimits |
* \typedef ScanLimit_t |
**********************************************************************/ |
typedef enum ScanLimits |
{ |
ScanLimit_Digit0 = 0x00, |
ScanLimit_Digit0To1 = 0x01, |
ScanLimit_Digit0To2 = 0x02, |
ScanLimit_Digit0To3 = 0x03, |
ScanLimit_Digit0To4 = 0x04, |
ScanLimit_Digit0To5 = 0x05, |
ScanLimit_Digit0To6 = 0x06, |
ScanLimit_Digit0To7 = 0x07 |
} ScanLimit_t; |
/******************************************************************//** |
* \enum ShutdownModes |
* \typedef ShutdownMode_t |
**********************************************************************/ |
typedef enum ShutdownModes |
{ |
ShutdownMode_Shutdown = 0x00, |
ShutdownMode_NormalOperation = 0x01 |
} ShutdownMode_t; |
/******************************************************************//** |
* \enum DisplayTestModes |
* \typedef DisplayTestMode_t |
**********************************************************************/ |
typedef enum DisplayTestModes |
{ |
NormalOperation = 0x00, |
TestMode = 0x01 |
} DisplayTestMode_t; |
/******************************************************************//** |
* \enum Digits |
* \typedef Digit_t |
**********************************************************************/ |
typedef enum Digits |
{ |
Digit_0 = 0x01, |
Digit_1 = 0x02, |
Digit_2 = 0x03, |
Digit_3 = 0x04, |
Digit_4 = 0x05, |
Digit_5 = 0x06, |
Digit_6 = 0x07, |
Digit_7 = 0x08 |
} Digit_t; |
/******************************************************************//** |
* \enum Characters |
* \typedef Character_t |
**********************************************************************/ |
typedef enum Characters |
{ |
Character_Zero = 0x00, |
Character_One = 0x01, |
Character_Two = 0x02, |
Character_Three = 0x03, |
Character_Four = 0x04, |
Character_Five = 0x05, |
Character_Six = 0x06, |
Character_Seven = 0x07, |
Character_Eight = 0x08, |
Character_Nine = 0x09, |
Character_Dash = 0x0A, |
Character_E = 0x0B, |
Character_H = 0x0C, |
Character_L = 0x0D, |
Character_P = 0x0E, |
Character_Blank = 0x0F |
} Character_t; |
/******************************************************************//** |
* \enum Segments |
* \typedef Segment_t |
**********************************************************************/ |
typedef enum Segments |
{ |
Segment_DP = 0x80, |
Segment_A = 0x40, |
Segment_B = 0x20, |
Segment_C = 0x10, |
Segment_D = 0x08, |
Segment_E = 0x04, |
Segment_F = 0x02, |
Segment_G = 0x01 |
} Segment_t; |
public: |
/******************************************************************//** |
* \fn MAX7219(byte csPin) |
* |
* \brief Constructor. |
* |
* \param csPin Chip select pin number. |
**********************************************************************/ |
MAX7219 |
( |
byte csPin |
); |
/******************************************************************//** |
* \fn void initialize() |
* |
* \brief Initialize SPI to drive MAX7219. |
**********************************************************************/ |
void |
initialize(); |
/******************************************************************//** |
* \fn void setDecodeMode(DecodeModes mode) |
* |
* \brief Set MAX7219 decode mode. |
* |
* \param mode Decode mode to set. |
**********************************************************************/ |
void |
setDecodeMode |
( |
DecodeModes mode |
); |
/******************************************************************//** |
* \fn void setIntensity(Intensities intensity) |
* |
* \brief Set MAX7219 intensity. |
* |
* \param itensity Intensity to set. |
**********************************************************************/ |
void |
setIntensity |
( |
Intensities intensity |
); |
/******************************************************************//** |
* \fn void setScanLimit(ScanLimits limit) |
* |
* \brief Set MAX7219 scan limit. |
* |
* \param limit Scan limit to set. |
**********************************************************************/ |
void |
setScanLimit |
( |
ScanLimits limit |
); |
/******************************************************************//** |
* \fn void setShutdownMode(ShutdownModes mode) |
* |
* \brief Set MAX7219 shutdown mode. |
* |
* \param mode Shutdown mode to set. |
**********************************************************************/ |
void |
setShutdownMode |
( |
ShutdownModes mode |
); |
/******************************************************************//** |
* \fn void setDisplayTestMode(DisplayTestModes mode) |
* |
* \brief Set MAX7219 display test mode. |
* |
* \param mode Display test mode to set. |
**********************************************************************/ |
void |
setDisplayTestMode |
( |
DisplayTestModes mode |
); |
/******************************************************************//** |
* \fn void writeDigit( |
* Digits digit, |
* Characters character, |
* bool decimalPoint = false) |
* |
* \brief Write character on digit. |
* |
* \param digit Digit to write. |
* \param character Character to write. |
* \param decimalPoint Display decimal point. |
**********************************************************************/ |
void |
writeDigit |
( |
Digits digit, |
Characters character, |
bool decimalPoint = false |
); |
/******************************************************************//** |
* \fn void writeDigit(Digits digit, Segments segments) |
* |
* \brief Set segment(s) on digit. |
* |
* \param digit Digit to write. |
* \param segment Segment(s) to set. |
**********************************************************************/ |
void |
writeDigit |
( |
Digits digit, |
Segments segment |
); |
private: |
byte m_csPin; |
/******************************************************************//** |
* \fn void write(byte address, byte value) |
* |
* \brief Write value into MAX7219 register. |
* |
* \param address Register address. |
* \param value Value to write. |
**********************************************************************/ |
void |
write |
( |
byte address, |
byte value |
); |
}; |
#endif // MAX7219_h |