Module TM1637 :: Class FourDigit
[frames] | no frames]

Class FourDigit

source code

Abstraction of the 4 digit 7-segment display based on the TM1637 display driver. 7-bit ASCII characters are mapped as close as possible to the 7 display segments. If a character cannot be mapped, the digit is cleared.

Instance Methods
 
__init__(self, dio=38, clk=40, lum=4)
Creates a display instance that uses the two given GPIO pins for data (dio, default: 38) and clock (clk, default: 40).
source code
 
erase(self)
Clears the display (all digits are turned off).
source code
 
show(self, text, pos=0)
Displays 4 characters of the given text.
source code
 
scroll(self, text)
Starts scrolling the text to the left and blocks until all characters have passed by.
source code
 
toRight(self)
Scrolls the current text one step to the left by decreasing the text pointer.
source code
 
toLeft(self)
Scrolls the current text one step to the left by increasing the text pointer.
source code
 
toStart(self)
Shows the text at the start position by setting the text pointer to its start value.
source code
 
setLuminosity(self, lum)
Sets the brightness of the display.
source code
 
setColon(self, enable)
Enables/disables the colon in the middle of the screen.
source code
Static Methods
 
getDisplayableChars()
Returns a string with all displayable characters taken from PATTERN dictionary.
source code
 
toHex(intValue)
Returns a string with hex digits from given number (>0, any size).
source code
 
toBytes(intValue)
Returns a list of four byte values [byte#24-#31, byte#16-#23, byte#8-#15, byte#0-#7] of given integer.
source code
 
toInt(hexValue)
Returns an integer from given hex string
source code
Class Variables
  myData = [0, 0, 0, 0]
Method Details

getDisplayableChars()
Static Method

source code 

Returns a string with all displayable characters taken from PATTERN dictionary.

Returns:
The character set that can be displayed

toHex(intValue)
Static Method

source code 

Returns a string with hex digits from given number (>0, any size).

Parameters:
  • number - the number to convert (must be positive)
Returns:
string of hex digits (uppercase), e.g. 0xFE

toBytes(intValue)
Static Method

source code 

Returns a list of four byte values [byte#24-#31, byte#16-#23, byte#8-#15, byte#0-#7] of given integer.

Parameters:
  • number - an integer
Returns:
list with integers of 4 bytes [MSB,..., LSB]

toInt(hexValue)
Static Method

source code 

Returns an integer from given hex string

Parameters:
  • number - a string with the number to convert, e.g. "FE" or "fe" or "0xFE" or "0XFE"
Returns:
integer number

__init__(self, dio=38, clk=40, lum=4)
(Constructor)

source code 

Creates a display instance that uses the two given GPIO pins for data (dio, default: 38) and clock (clk, default: 40). It is set to the given luminosiy (0..9, default: 4)

show(self, text, pos=0)

source code 

Displays 4 characters of the given text. The text is considered to be prefixed and postfixed by spaces and the 4 character window is selected by the text pointer pos that determines the character displayed at the leftmost digit, e.g. (_: empty): showText("AbCdEF") -> AbCd showText("AbCdEF", 1) -> bCdE showText("AbCdEF", -1) ->_AbC showText("AbCdEF", 4) -> EF__

Parameters:
  • text - the text to display (string or integer)
  • pos - the start value of the text pointer (character index positioned a leftmost digit)

toRight(self)

source code 

Scrolls the current text one step to the left by decreasing the text pointer.

Returns:
the number of characters hidden, but remaining to be displayed at the left (>=0); -1, if error

toLeft(self)

source code 

Scrolls the current text one step to the left by increasing the text pointer.

Returns:
the number of characters hidden, but remaining to be displayed at the right (>=0); -1, if error

setLuminosity(self, lum)

source code 

Sets the brightness of the display.

Parameters:
  • luminosity, the, brightness, (0..9, 0 - invisible)

setColon(self, enable)

source code 

Enables/disables the colon in the middle of the screen. @param enable if True, the colon is shown in all subsequent text operations