My Project
 All Classes Functions Variables Pages
MAX7219.h
1 /*
2  * LedControl.h - A library for controling Leds with a MAX7219/MAX7221
3  * Copyright (c) 2007 Eberhard Fahle
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without
8  * restriction, including without limitation the rights to use,
9  * copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following
12  * conditions:
13  *
14  * This permission notice shall be included in all copies or
15  * substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24  * OTHER DEALINGS IN THE SOFTWARE.
25  */
26 
27 #ifndef MAX7219_h
28 #define MAX7219_h
29 
30 #include <SPI.h>
31 
52 class MAX7219 {
53 public:
61  MAX7219(SPI* spi, int numDevices = 1);
62 
63 
69  void clearDisplay(int addr);
70 
71 
76  int getDeviceCount();
77 
78 
92  void setChar(int digit, char value, bool dp=false, int addr = 0);
93 
94 
102  void setColumn(int col, uint8_t value, int addr = 0);
103 
104 
113  void setDigit(int digit, uint8_t value, bool dp=false, int addr = 0);
114 
115 
122  void setIntensity(int intensity, int addr = 0);
123 
124 
133  void setLed(int row, int col, bool state, int addr = 0);
134 
135 
144  void setNumber(uint32_t number, int addr = 0);
145 
146 
154  void setRow(int row, uint8_t value, int addr = 0);
155 
156 
166  void setScanLimit(int limit, int addr = 0);
167 
168 
176  void shutdown(bool status, int addr = 0);
177 
178 private:
179  /* Send out a single command to the device */
180  void spiTransfer(int addr, uint8_t opcode, uint8_t data);
181 
182  /* We keep track of the led-status for all 8 devices in this array */
183  uint8_t status[64];
184 
185  /* The maximum number of devices we use */
186  int maxDevices;
187  SPI* spi;
188 
189 };
190 
191 #endif // MAX7219.h
192 
MAX7219 and MAX7221 controller.
Definition: MAX7219.h:52
void setNumber(uint32_t number, int addr=0)
Display a number on the 7-Segment display.
Definition: MAX7219.cpp:238
int getDeviceCount()
Gets the number of devices attached to this MAX7219.
Definition: MAX7219.cpp:103
Handle SPI protocol.
Definition: SPI.h:15
MAX7219(SPI *spi, int numDevices=1)
Create a new MAX7219 controller.
Definition: MAX7219.cpp:79
void setColumn(int col, uint8_t value, int addr=0)
Set all 8 Led's in a column to a new state.
Definition: MAX7219.cpp:178
void setScanLimit(int limit, int addr=0)
Set the number of digits (or rows) to be displayed. See datasheet for side effects of the scanlimit o...
Definition: MAX7219.cpp:119
void setLed(int row, int col, bool state, int addr=0)
Set the status of a single Led.
Definition: MAX7219.cpp:147
void shutdown(bool status, int addr=0)
Set the shutdown (power saving) mode for the device.
Definition: MAX7219.cpp:108
void setDigit(int digit, uint8_t value, bool dp=false, int addr=0)
Display a hexadecimal digit on a 7-Segment Display.
Definition: MAX7219.cpp:191
void setChar(int digit, char value, bool dp=false, int addr=0)
Display a character on a 7-Segment display.
Definition: MAX7219.cpp:205
void setRow(int row, uint8_t value, int addr=0)
Set all 8 Led's in a row to a new state.
Definition: MAX7219.cpp:168
void setIntensity(int intensity, int addr=0)
Set the brightness of the display.
Definition: MAX7219.cpp:127
void clearDisplay(int addr)
Switch all Leds on the display off.
Definition: MAX7219.cpp:135