Serial Wombat Arduino Library
Public Member Functions | List of all members
SerialWombatTM1637 Class Reference

A Class representing a TM1637 Seven-Segment Display connected to two Serial Wombat pins. More...

#include <SerialWombatTM1637.h>

Inheritance diagram for SerialWombatTM1637:
SerialWombatPin

Public Member Functions

 SerialWombatTM1637 (SerialWombatChip &serialWombat)
 Constructor for SerialWombatTM1637 class. More...
 
int16_t begin (uint8_t clkPin, uint8_t dioPin, uint8_t digits, SWTM1637Mode mode, uint8_t dataSourcePin, uint8_t brightness0to7)
 Initialize an instance of the TM1637 class. More...
 
int16_t writeDigitOrder (uint8_t first, uint8_t second, uint8_t third, uint8_t fourth, uint8_t fifth, uint8_t sixth)
 Used to reorder the digits of the display to match display hardware. More...
 
int16_t writeArray (uint8_t data[6])
 Used to send data to the data array of the driver.
More...
 
int16_t writeDecimalBitmap (uint8_t decimalBitmapLSBleftDigit)
 Set a bitmap of the MSB of each digit to control decimal points. More...
 
int16_t writeBrightness (uint8_t brightness0to7)
 Changes the brightness of the display. More...
 
int16_t writeAnimation (uint16_t bufferIndex, uint16_t delay, uint8_t numberOfFrames, uint8_t data[][6])
 Loads an animation to the Serial Wombat user buffer area and initializes the animation. More...
 
int16_t suppressLeadingZeros (bool suppress)
 Whether or not to suppress leading zeros in decimal mode. More...
 
int16_t writeBlinkBitmap (uint8_t blinkBitmapLSBleftDigit)
 Set a bitmap of the digits that should blink at 2Hz with 7/8 duty cycle. More...
 
virtual size_t write (uint8_t data)
 Write a byte to String mode, shifting other characters. More...
 
virtual size_t write (const uint8_t *buffer, size_t size)
 
virtual int availableForWrite ()
 
- Public Member Functions inherited from SerialWombatPin
 SerialWombatPin (SerialWombatChip &serialWombatChip)
 Instantiates a Serial Wombat Pin. More...
 
 SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin)
 Instantiates a Serial Wombat Pin. More...
 
uint16_t readPublicData ()
 Read the 16 Bit public data associated with this pin. More...
 
void pinMode (uint8_t mode)
 Set pin to INPUT or OUTPUT. More...
 
void pinMode (uint8_t mode, bool pullDown, bool openDrain)
 Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings. More...
 
void digitalWrite (uint8_t val)
 Set output pin High or Low. More...
 
int digitalRead ()
 Reads the state of the Pin. More...
 
uint16_t writePublicData (uint16_t value)
 Write a 16 bit value to this pin. More...
 
uint8_t pin ()
 Returns the current SW pin number. Used primarily for virtual calls by derived classes. More...
 
uint8_t swPinModeNumber ()
 Returns the Mode number. Used primarily by derived classes to populate packet data. More...
 

Additional Inherited Members

- Protected Attributes inherited from SerialWombatPin
uint8_t _pin = 255
 
SerialWombatChip_sw
 
uint8_t _pinMode = 0
 

Detailed Description

A Class representing a TM1637 Seven-Segment Display connected to two Serial Wombat pins.

This class is only supported on the Serial Wombat SW18AB chip. It is not supported on the Serial Wombat 4X line.

This class controls a State Machine driven driver for a TM1637 Seven Segment LED Display.

Each instance of this class uses an average of approximately 5% of the SW18's processing time. This varies by configuration options and usage.

The Serial Wombat TM1637 driver can be configured in a number of ways:

See the available examples in the Arduino Library for usage.

Warning
Different TM1637 displays behave differently based on how the manufacturer routed the LED matrix pins to the TM1637 outputs on the PCB. This can cause digits to be displayed in the wrong order, or cause decimal points or clock colons to malfunction. This is a display issue, not an issue with this library or the Serial Wombat firmware. Display order issues can be corrected with the orderDigits() command.

A tutorial is available here:

https://youtu.be/AwW12n6o_T0

/// ///

Constructor & Destructor Documentation

◆ SerialWombatTM1637()

SerialWombatTM1637::SerialWombatTM1637 ( SerialWombatChip serialWombat)

Constructor for SerialWombatTM1637 class.

Parameters
serialWombatSerialWombatChip on which the PWM will run

Member Function Documentation

◆ availableForWrite()

virtual int SerialWombatTM1637::availableForWrite ( )
inlinevirtual

◆ begin()

int16_t SerialWombatTM1637::begin ( uint8_t  clkPin,
uint8_t  dioPin,
uint8_t  digits,
SWTM1637Mode  mode,
uint8_t  dataSourcePin,
uint8_t  brightness0to7 
)

Initialize an instance of the TM1637 class.

Returns
Returns a negative error code if initialization failed.
Parameters
clkPinThe primary pin for this pin mode, the Serial Wombat pin connected to the clk pin of the TM1637
dioPinThe Serial Wombat pin connected to the DIO/data pin of the TM1637
digitsThe number of digits in the display. This is used to optimze displays shorter than 6 digits
modeThe mode (decimal, hex, char array, raw or animation) of the display driver
dataSourcePinif in decimal or hex mode, the pin from which the 16 bit data will be read. Set this to the clkPin setting if you want to be able to write 16 bit (5 digit) numbers using the SerialWombat.writePublicData() function. Numbers larger than 65535 must be written as strings using the Character Mode
Brightness- a value from 0 (dimmest) to 7 (brightest) based on the TM1637 hardware. This scale is not linear.

◆ suppressLeadingZeros()

int16_t SerialWombatTM1637::suppressLeadingZeros ( bool  suppress)

Whether or not to suppress leading zeros in decimal mode.

Returns
Returns a negative error code if errors occur during configuration
Parameters
supresstrue: suppress leading zeros false: Do not suppress leading zeros

◆ write() [1/2]

size_t SerialWombatTM1637::write ( const uint8_t *  buffer,
size_t  size 
)
virtual

◆ write() [2/2]

size_t SerialWombatTM1637::write ( uint8_t  data)
virtual

Write a byte to String mode, shifting other characters.

This function allows the TM1637 mode to use Arduino Print statements.

Parameters
dataByte to be written to display
Returns
Number of bytes written

◆ writeAnimation()

int16_t SerialWombatTM1637::writeAnimation ( uint16_t  bufferIndex,
uint16_t  delay,
uint8_t  numberOfFrames,
uint8_t  data[][6] 
)

Loads an animation to the Serial Wombat user buffer area and initializes the animation.

The pin should have previously been initialized with the begin() command an animation mode prior to this call.

Parameters
bufferIndexThe index into the User Buffer where the data for the animation should be stored
delayHow long the animation display driver should wait between loading new data
Numberof Frames to be displayed before returning to the first frame. This should be the number of lines in data
dataA 2 dimensional array of width 6 and arbitrary length.
Returns
Returns a negative error code if errors occur during configuration

◆ writeArray()

int16_t SerialWombatTM1637::writeArray ( uint8_t  data[6])

Used to send data to the data array of the driver.

Parameters
dataA 6 byte array that is sent to the display driver
Returns
Returns a negative error code if errors occur during configuration

The meaning of this data varies based on mode. See examples.

◆ writeBlinkBitmap()

int16_t SerialWombatTM1637::writeBlinkBitmap ( uint8_t  blinkBitmapLSBleftDigit)

Set a bitmap of the digits that should blink at 2Hz with 7/8 duty cycle.

This function is useful for creating user interfaces where the user increments or decrements one digit of a number at a time. The blinking digit indicates the digit that will change.

Parameters
blinkBitmapA bitmap indicating if the decimal for each digit should be lit. LSB is first digit Valid values are 0 - 0x3F. 1 = blink
Returns
Returns a negative error code if errors occur during configuration

◆ writeBrightness()

int16_t SerialWombatTM1637::writeBrightness ( uint8_t  brightness0to7)

Changes the brightness of the display.

Parameters
Brightness- a value from 0 (dimmest) to 7 (brightest) based on the TM1637 hardware. This scale is not linear.
Returns
Returns a negative error code if errors occur during configuration

◆ writeDecimalBitmap()

int16_t SerialWombatTM1637::writeDecimalBitmap ( uint8_t  decimalBitmapLSBleftDigit)

Set a bitmap of the MSB of each digit to control decimal points.

Note that TM1637 decimal point implementation varies greatly depending on the display manufacturer. Setting bits may or may not cause decimal points to display, the clock colon to display, or other undefined behavior. Unexpected behavior is likely the result of display pcb implementation, not an issue with this library or the Serial Wombat firmware.

Parameters
decimalBitmapLSBleftDigitA bitmap indicating if the decimal for each digit should be lit. LSB is first digit Valid values are 0 - 0x3F
Returns
Returns a negative error code if errors occur during configuration

◆ writeDigitOrder()

int16_t SerialWombatTM1637::writeDigitOrder ( uint8_t  first,
uint8_t  second,
uint8_t  third,
uint8_t  fourth,
uint8_t  fifth,
uint8_t  sixth 
)

Used to reorder the digits of the display to match display hardware.

TM1637 displays do not have a standardized wiring of LED module to the TM1637 driver pins. This can cause numbers to appear in the wrong order. This can be fixed by displaying the string "012345" on the display. If it appears out of order, then issue this command with the parameters matching what is displayed on the screen.

For instance, if a Six digit display showed 210543 when commanded to show "012345", calling

orderDigits(2,1,0,5,4,3);

after begin() would cause the driver to reorder the output to make the display appear in the desired order.

Returns
Returns a negative error code if errors occur during configuration