Support for display on/off and intensity

This commit is contained in:
rjbatista@gmail.com
2011-08-04 00:25:01 +00:00
parent d1e51e6ffa
commit 1b3265f0cc
3 changed files with 25 additions and 9 deletions

View File

@@ -61,7 +61,7 @@ const byte ERROR[] = {
0
};
TM1638::TM1638(byte dataPin, byte clockPin, byte strobePin)
TM1638::TM1638(byte dataPin, byte clockPin, byte strobePin, boolean activateDisplay, byte intensity)
{
this->dataPin = dataPin;
this->clockPin = clockPin;
@@ -74,8 +74,8 @@ TM1638::TM1638(byte dataPin, byte clockPin, byte strobePin)
digitalWrite(strobePin, HIGH);
digitalWrite(clockPin, HIGH);
sendCommand(0x8B);
sendCommand(0x40);
sendCommand(0x80 | (activateDisplay ? 8 : 0) | min(7, intensity));
digitalWrite(strobePin, LOW);
send(0xC0);
@@ -85,6 +85,12 @@ TM1638::TM1638(byte dataPin, byte clockPin, byte strobePin)
digitalWrite(strobePin, HIGH);
}
void TM1638::setupDisplay(boolean active, byte intensity)
{
sendCommand(0x80 | (active ? 8 : 0) | min(7, intensity));
}
void TM1638::setDisplayToHexNumber(unsigned long number, byte dots)
{
for (int i = 0; i < 8; i++) {

View File

@@ -28,8 +28,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
class TM1638
{
public:
TM1638(byte dataPin, byte clockPin, byte strobePin);
public:
/** Instantiate a tm1638 module specifying the display state, the starting intensity (0-7) data, clock and stobe pins. */
TM1638(byte dataPin, byte clockPin, byte strobePin, boolean activateDisplay = true, byte intensity = 7);
/** Set the display (segments and LEDs) active or off and intensity (range from 0-7). */
void setupDisplay(boolean active, byte intensity);
/** Set the display to a unsigned hexadecimal number */
void setDisplayToHexNumber(unsigned long number, byte dots);

View File

@@ -6,13 +6,13 @@ unsigned char hello[] = {
TM1638 module1(2, 3, 4);
TM1638 module2(2, 3, 5);
unsigned long value = 87654321L;
unsigned long value = 0L;
boolean state = true;
void setup()
{
module1.setDisplay(helloLCD);
module2.setDisplay(helloLCD);
module1.setDisplay(hello);
module2.setDisplay(hello);
module1.setLEDs(0b00011111 | 0b11111000 << 8);
@@ -21,7 +21,6 @@ void setup()
module2.setLED(TM1638_COLOR_RED | TM1638_COLOR_GREEN, 7);
}
void loop()
{
byte key1, key2;
@@ -42,6 +41,13 @@ void loop()
module2.setDisplayToBinNumber(key1, 0);
module1.setLEDs(key1);
if (key1 & 128) {
state = !state;
delay(200); // just wait for button up
}
module1.setupDisplay(state, key1 >> 1);
}
if (key2 != 0) {