Initial Revision

This commit is contained in:
rjbatista@gmail.com
2011-08-02 00:28:15 +00:00
commit dda259d7f0
4 changed files with 367 additions and 0 deletions

66
TM1638.h Normal file
View File

@@ -0,0 +1,66 @@
/*
TM1638.h - Library for TM1638.
Copyright (C) 2011 Ricardo Batista <rjbatista at gmail dot com>
Based on a sketch by: Martin Hubacek (http://www.martinhubacek.cz)
This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TM1638_h
#define TM1638_h
#include <WProgram.h>
#define TM1638_COLOR_RED 1
#define TM1638_COLOR_GREEN 2
class TM1638
{
public:
TM1638(byte dataPin, byte clockPin, byte strobePin);
/** Set the display to a unsigned hexadecimal number */
void setDisplayToHexNumber(unsigned long number, byte dots);
/** Set the display to a unsigned decimal number */
void setDisplayToDecNumber(unsigned long number, byte dots);
/** Set the display to a unsigned binary number */
void setDisplayToBinNumber(byte number, byte dots);
/** Set a single display at pos (starting at 0) to a digit (left to right) */
void setDisplayDigit(byte digit, byte pos, boolean dot);
/** Set the display to the 8 values (left to right) */
void setDisplay(const byte values[]);
/** Set the LED at pos to color (TM1638_COLOR_RED, TM1638_COLOR_GREEN or both) */
void setLED(byte color, byte pos);
/** Set the LEDs. MSB byte for the green LEDs, LSB for the red LEDs */
void setLEDs(word led);
/** Returns the pressed buttons as a bit set (left to right). */
byte getButtons();
protected:
void sendCommand(byte led);
void sendData(byte add, byte data);
void send(byte data);
byte receive();
private:
byte dataPin;
byte clockPin;
byte strobePin;
};
#endif