B4R Library rTM1638 - 8 Seven Segment LED Display with Keys And LEDs

Library supporting the 8 Seven Segment LED Display with Keys And LEDs using the TM1638.
Based upon this open source project: https://github.com/rjbatista/tm1638-library

The library enables to display numbers in various ways, text, control the 8 LEDs and handle button press events for the 8 Buttons. The example source shows all the functions.

The device displaying a nice text
upload_2017-2-6_18-25-57.png


Example
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Public tm As TM1638
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    'Init the device with data pin 8, clock pin 9 and strobe pin 7, show leading zeros, low intensity
    tm.Initialize(8,9,7,True,2)
    'Add the listener for the key S1 - S8 pressed
    tm.AddListener("Button_Pressed")

    'Clear the display
    tm.ClearDisplay

    'Display DEC 1958 with no leading zeros and no dots
    'Result: 1958
    tm.SetDisplayToSignedDecNumber(1958,0,False)
    Delay(2000)

    'Display digit 9 at the 4th LED which is pos 3 as position are 0 - 7
    tm.ClearDisplay
    tm.SetDisplayDigit(9,3,False)
    Delay(2000)

    'Clear at the 4th LED which is pos 3 as position are 0 - 7
    tm.ClearDisplayDigit(3,False)
    Delay(2000)

    'Display a string (max 8 chars)
    Dim s As String = "B4R=COOL"
    tm.ClearDisplay
    tm.SetDisplayToString(s)
    Delay(2000)

    'Display DEC 9081958 with leading zeros and no dots
    'Result: 09081958
    tm.ClearDisplay
    tm.SetDisplayToSignedDecNumber(9081958,0,True)
    Delay(2000)

    'Display HEX 9 to the right with leading zeros and no dots
    'Result: 00000009
    tm.ClearDisplay
    tm.SetDisplayToDecNumber(9,0,True)
    Delay(2000)

    'Display HEX and set the left 4 dots on (F0)
    'Result: 1.2.3.4.ABCD
    tm.ClearDisplay
    tm.SetDisplayToHexNumber(0x1234ABCD, 0xF0, False)
    Delay(2000)

    'Display HEX 1111 as DEC with no dots and no leading zeros
    'Result: 4369
    tm.ClearDisplay
    tm.SetDisplayToDecNumber(0x1111, 0x00, False)
    Delay(2000)

    'Display HEX 59 as digital with dots (FF)
    'Result: 0.1.0.1.1.0.0.1
    tm.ClearDisplay
    tm.SetDisplayToBinNumber(0x59, 0xFF)
    Delay(2000)

    'Turn LED3 ON
    tm.SetLED(tm.TM1638_COLOR_RED, 2)
    Delay(2000)
    'Turn LED3 OFF
    tm.SetLED(tm.TM1638_COLOR_NONE, 2)
    Delay(2000)

    'Turn the 4 right LEDs ON (LED5-8)
    tm.SetLEDs(0xF0)
    Delay(2000)

    'Turn the 4 left LEDs ON (LED1-4)
    tm.SetLEDs(0x0F)
    Delay(2000)

    'Turn all LEDs OFF
    tm.SetLEDs(0x00)

    'Set the display on to high intensity from the range 0 (lowest) - 7 (highest)
    tm.SetupDisplay(True, 7)

    'Close off with a ByeBye string
    Dim s As String = "Bye BYE"
    tm.ClearDisplay
    tm.SetDisplayToString(s)
End Sub

'Handle Button Pressed Event.
'Key Return Values S1 = 1, S2 = 2, S3 = 4, S4 = 8, S5 = 16, S6 = 32, S7 = 64, S8 = 128
Private Sub Button_Pressed(Keys As Byte)
    Log("KeyPressed:", Keys)
    'Turn the according LED on or off, e.g. pressing Key S1 = LED1 ON
    Dim l As UInt = Keys
    tm.SetLEDs(l)
End Sub

ChangeLog
20170207 v1.1: NEW SetupDisplay enabling to turn LED display on/off and set the intensity 0 - 7
20170206 v1.0
 

Attachments

  • rTM1638.zip
    13.2 KB · Views: 663
Last edited:

KalaCanel

New Member
Hi...is this 7 segment display a replacement for the old one, or is the original display unit causing the problem, if its a replacement the pin out for the display might differ from the original, the anode cathode connections might be in different positions.

But if the problem is the original display, then it might be the IC driving the display unit, other members will have more experience than me, but my modest input would think one of the above is the problem.

pcb assembly services iso9001:2015
 
Last edited:
Top