79 #ifndef ERRIEZ_TM1638_H_ 80 #define ERRIEZ_TM1638_H_ 85 #define TM1638_CMD_DATA 0x40 86 #define TM1638_CMD_CTRL 0x80 87 #define TM1638_CMD_ADDR 0xc0 90 #define TM1638_DATA_WRITE 0x00 91 #define TM1638_DATA_READ_KEYS 0x02 92 #define TM1638_DATA_AUTO_INC_ADDR 0x00 93 #define TM1638_DATA_FIXED_ADDR 0x04 96 #define TM1638_CTRL_PULSE_1_16 0x00 97 #define TM1638_CTRL_PULSE_2_16 0x01 98 #define TM1638_CTRL_PULSE_4_16 0x02 99 #define TM1638_CTRL_PULSE_10_16 0x03 100 #define TM1638_CTRL_PULSE_11_16 0x04 101 #define TM1638_CTRL_PULSE_12_16 0x05 102 #define TM1638_CTRL_PULSE_13_16 0x06 103 #define TM1638_CTRL_PULSE_14_16 0x07 104 #define TM1638_CTRL_DISPLAY_OFF 0x00 105 #define TM1638_CTRL_DISPLAY_ON 0x08 107 #define TM1638_NUM_GRIDS 16 111 #define TM1638_CLK_LOW() { *portOutputRegister(_clkPort) &= ~_clkBit; } 112 #define TM1638_CLK_HIGH() { *portOutputRegister(_clkPort) |= _clkBit; } 113 #define TM1638_CLK_INPUT() { *portModeRegister(_clkPort) &= ~_clkBit; } 114 #define TM1638_CLK_OUTPUT() { *portModeRegister(_clkPort) |= _clkBit; } 116 #define TM1638_DIO_LOW() { *portOutputRegister(_dioPort) &= ~_dioBit; } 117 #define TM1638_DIO_HIGH() { *portOutputRegister(_dioPort) |= _dioBit; } 118 #define TM1638_DIO_INPUT() { *portModeRegister(_dioPort) &= ~_dioBit; } 119 #define TM1638_DIO_OUTPUT() { *portModeRegister(_dioPort) |= _dioBit; } 120 #define TM1638_DIO_READ() ( *portInputRegister(_dioPort) & _dioBit ) 122 #define TM1638_STB_LOW() { *portOutputRegister(_stbPort) &= ~_stbBit; } 123 #define TM1638_STB_HIGH() { *portOutputRegister(_stbPort) |= _stbBit; } 124 #define TM1638_STB_INPUT() { *portModeRegister(_stbPort) &= ~_stbBit; } 125 #define TM1638_STB_OUTPUT() { *portModeRegister(_stbPort) |= _stbBit; } 127 #define TM1638_CLK_LOW() { digitalWrite(_clkPin, LOW); } 128 #define TM1638_CLK_HIGH() { digitalWrite(_clkPin, HIGH); } 129 #define TM1638_CLK_INPUT() { pinMode(_clkPin, INPUT); } 130 #define TM1638_CLK_OUTPUT() { pinMode(_clkPin, OUTPUT); } 132 #define TM1638_DIO_LOW() { digitalWrite(_dioPin, LOW); } 133 #define TM1638_DIO_HIGH() { digitalWrite(_dioPin, HIGH); } 134 #define TM1638_DIO_INPUT() { pinMode(_dioPin, INPUT); } 135 #define TM1638_DIO_OUTPUT() { pinMode(_dioPin, OUTPUT); } 136 #define TM1638_DIO_READ() ( digitalRead(_dioPin) ) 138 #define TM1638_STB_LOW() { digitalWrite(_stbPin, LOW); } 139 #define TM1638_STB_HIGH() { digitalWrite(_stbPin, HIGH); } 140 #define TM1638_STB_INPUT() { pinMode(_stbPin, INPUT); } 141 #define TM1638_STB_OUTPUT() { pinMode(_stbPin, OUTPUT); } 145 #if F_CPU >= 20000000UL 146 #define TM1638_PIN_DELAY() { delayMicroseconds(1); } 148 #define TM1638_PIN_DELAY() 157 TM1638(uint8_t clkPin, uint8_t dioPin, uint8_t stbPin,
158 bool displayOn=
true, uint8_t brightness=5);
160 virtual void begin();
165 virtual void clear();
166 virtual void writeData(uint8_t address, uint8_t data);
167 virtual void writeData(uint8_t address,
const uint8_t *buf, uint8_t len);
194 #endif // ERRIEZ_TM1638_H_ uint8_t _brightness
Display brightness for display control register.
virtual void writeByte(uint8_t data)
Write byte to TM1638.
TM1638(uint8_t clkPin, uint8_t dioPin, uint8_t stbPin, bool displayOn=true, uint8_t brightness=5)
TM1638 constructor.
virtual void writeDisplayControl()
Write display control register.
virtual void setBrightness(uint8_t brightness)
Set brightness LED's.
virtual void clear()
Turn all LED's off.
uint8_t _clkPin
Clock pin.
virtual void begin()
Initialize TM1638 controller.
virtual void writeData(uint8_t address, uint8_t data)
Write display register.
virtual uint32_t getKeys()
Get key states.
virtual void writeCommand(uint8_t cmd)
Write command to TM1638.
virtual void displayOff()
Turn display off.
virtual void end()
Disable pins.
uint8_t _stbPin
Enable pin.
virtual void displayOn()
Turn Display on.
bool _displayOn
Display on and off status for display control register.
virtual uint8_t readByte()
Read byte from TM1638.