TM1638_plus  2.0.0
Arduino library for Tm1638 modules
Public Member Functions | List of all members
TM1638plus_Model2 Class Reference

Class for Model 2. More...

#include <TM1638plus_Model2.h>

Inheritance diagram for TM1638plus_Model2:
Inheritance graph
[legend]
Collaboration diagram for TM1638plus_Model2:
Collaboration graph
[legend]

Public Member Functions

 TM1638plus_Model2 (uint8_t strobe, uint8_t clock, uint8_t data, bool swap_nibbles=false, bool high_freq=false)
 Constructor for class TM1638plus_Model2. More...
 
uint8_t ReadKey16 (void)
 Read push buttons method ( one of two methods available) More...
 
uint16_t ReadKey16Two (void)
 Read push buttons method ( one of two methods available) More...
 
void DisplaySegments (uint8_t segment, uint8_t segmentValue)
 Send seven segment value to display. More...
 
void DisplayHexNum (uint16_t numberUpper, uint16_t numberLower, uint8_t dots, boolean leadingZeros=true, AlignTextType_e=TMAlignTextLeft)
 Display an Hexadecimal number in each nibble (4 digits on display) More...
 
void DisplayDecNum (unsigned long number, uint8_t dots, boolean leadingZeros=true, AlignTextType_e=TMAlignTextLeft)
 Display an decimal number. More...
 
void DisplayStr (const char *string, const uint16_t dots=0)
 Display a string, with decimal point display. More...
 
void ASCIItoSegment (const uint8_t values[])
 Takes in Array of 8 ASCII bytes , Called from DisplayStr . Scans each ASCII byte converts to array of 8 segment bytes where each byte represents a segment. Then calls DisplaySegments() method to display segments on display. More...
 
void DisplayDecNumNibble (uint16_t numberUpper, uint16_t numberLower, uint8_t dots, boolean leadingZeros=true, AlignTextType_e=TMAlignTextLeft)
 Display an integer in each nibble (4 digits on display) More...
 
- Public Member Functions inherited from TM1638plus_common
 TM1638plus_common ()
 Constructor for class TM1638plus_common.
 
void displayBegin ()
 Begin method , sets pin modes and activate display. More...
 
void reset (void)
 Reset / clear the display. More...
 
void brightness (uint8_t brightness)
 Sets the brightness level of segments in display on a scale of brightness. More...
 

Additional Inherited Members

- Protected Member Functions inherited from TM1638plus_common
uint8_t HighFreqshiftin (uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)
 Shifts in a byte of data from the Tm1638 SPI-like bus. More...
 
void HighFreqshiftOut (uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
 Shifts out a byte of data on to the Tm1638 SPI-like bus. More...
 
void sendCommand (uint8_t value)
 Send command to display. More...
 
void sendData (uint8_t data)
 Send Data to display. More...
 
- Protected Attributes inherited from TM1638plus_common
uint8_t _STROBE_IO
 
uint8_t _DATA_IO
 
uint8_t _CLOCK_IO
 
bool _HIGH_FREQ = false
 

Detailed Description

Class for Model 2.

Constructor & Destructor Documentation

◆ TM1638plus_Model2()

TM1638plus_Model2::TM1638plus_Model2 ( uint8_t  strobe,
uint8_t  clock,
uint8_t  data,
bool  swap_nibbles = false,
bool  high_freq = false 
)

Constructor for class TM1638plus_Model2.

Parameters
strobeGPIO STB pin
clockGPIO CLK pin
dataGPIO DIO pin
swap_nibblesdefault false, if true, swaps nibbles on display byte.
high_freqChanges the value of parameter _HIGH_FREQ which is default false.
Note
_HIGH_FREQ is used when running high freq MCU CPU (~>100Mhz) because of issues with button function. Pass true to turn on.

Member Function Documentation

◆ ASCIItoSegment()

void TM1638plus_Model2::ASCIItoSegment ( const uint8_t  values[])

Takes in Array of 8 ASCII bytes , Called from DisplayStr . Scans each ASCII byte converts to array of 8 segment bytes where each byte represents a segment. Then calls DisplaySegments() method to display segments on display.

Parameters
valuesAn array of 8 ASCII bytes
Note
byte 0 represents a in segment and then each bit represents the a segment in each digit. So for "00000005" is converted by DisplayStr to ASCII hex"3F 3F 3F 3F 3F 3F 3F 6D" where left is first digit. this is converted to hex "FF FE FF FF FE FF 01 00" by ASCIItoSegment, Where left is first segment. So "a" segment is turned on for all digits and "b" is on for all except last digit. The bits are mapping below abcdefg(dp) = 01234567 ! . See for mapping of seven segment to digit https://en.wikipedia.org/wiki/Seven-segment_display We have to do this as TM1638 model 2 is addressed by segment not digit unlike Model 1&3

◆ DisplayDecNum()

void TM1638plus_Model2::DisplayDecNum ( unsigned long  number,
uint8_t  dots,
boolean  leadingZeros = true,
AlignTextType_e  TextAlignment = TMAlignTextLeft 
)

Display an decimal number.

Parameters
numberinteger to display 2^32.
dotsDecimal point display, switch's on decimal point for those positions.
leadingZerosleading zeros set, true on , false off.
TextAlignmentleft or right text alignment on display.
Note
Converts to string internally

◆ DisplayDecNumNibble()

void TM1638plus_Model2::DisplayDecNumNibble ( uint16_t  numberUpper,
uint16_t  numberLower,
uint8_t  dots,
boolean  leadingZeros = true,
AlignTextType_e  TextAlignment = TMAlignTextLeft 
)

Display an integer in each nibble (4 digits on display)

Parameters
numberUpperupper nibble integer 2^16
numberLowerlower nibble integer 2^16
dotsTurn on or off decimal points to 0xFF d7d6d5d4d3d2d1d0
leadingZerosleading zeros set, true on , false off
TextAlignmentleft or right text alignment on display
Note
Divides the display into two nibbles and displays a Decimal number in each. takes in two numbers 0-9999 for each nibble.

◆ DisplayHexNum()

void TM1638plus_Model2::DisplayHexNum ( uint16_t  numberUpper,
uint16_t  numberLower,
uint8_t  dots,
boolean  leadingZeros = true,
AlignTextType_e  TextAlignment = TMAlignTextLeft 
)

Display an Hexadecimal number in each nibble (4 digits on display)

Parameters
numberUpperupper nibble integer 2^16
numberLowerlower nibble integer 2^16
dotsDecimal point display, switch's on decimal point for those positions. 0 to 0xFF
leadingZerosleading zeros set, true on , false off
TextAlignmentleft or right text alignment on display
Note
Divides the display into two nibbles and displays a Decimal number in each. takes in two numbers 0-9999 for each nibble. Converts to string internally.

◆ DisplaySegments()

void TM1638plus_Model2::DisplaySegments ( uint8_t  segment,
uint8_t  digit 
)

Send seven segment value to display.

Parameters
segment0-7 byte of data corresponding to segments abcdefg(dp) 01234567.
digitdisplay digit position, 0x00 to 0xFF d8d7d6d5d54d3d2d1.
Note

for segment parameter a is 0 , dp is 7 , segment Value is which segments are off or on for each digit. To to set all "a" on send (0x00,0xFF). To set all segment "g" off (0x06,0X00)

◆ DisplayStr()

void TM1638plus_Model2::DisplayStr ( const char *  string,
const uint16_t  dots = 0 
)

Display a string, with decimal point display.

Parameters
stringpointer to char array
dotsTurn on or off decimal points 0 to 0xFF d7d6d5d4d3d2d1d0
Note
Takes in string , converts it to ASCII using the font and masks for the decimal point. Then passes array of eight ASCII bytes to DisplayValues function

◆ ReadKey16()

unsigned char TM1638plus_Model2::ReadKey16 ( void  )

Read push buttons method ( one of two methods available)

Returns
0 if no button pressed or a decimal value of buttons 1-16 (1 for S1 ... 16 for S16 ).
Note
User may have to debounce buttons depending on application.. model 2 example here in ADC file TM1638plus_ADC_TEST_Model2.ino

◆ ReadKey16Two()

uint16_t TM1638plus_Model2::ReadKey16Two ( void  )

Read push buttons method ( one of two methods available)

Returns
A 16 bit integer where each bit correspond to a switch.
  1. S1 = 0x0001
  2. S16 = 0x8000
  3. S1 + S16 together = 0x8001
Note
Can detect multiple key presses. However, See notes section in readme regarding, problems with seven segment display when pressing certain keys in combination.

The documentation for this class was generated from the following files: