B4R Question Help with inline C

derez

Expert
Licensed User
Longtime User
There is a library that I want to use, called Tlc5940, it is included in Arduino's examples.
It is used for increasing the number of GPIO pins.
There are 4 simple methods:
Tlc.init();
Tlc.clear();
Tlc.set(channel , value); // channel is int, the output pin # , value is PWM between 0 to 4095
Tlc.update();

Can someone show me how to write the inline C for them ?
Thanks.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Something like:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private TlcChannel, TlcValue As Int
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   RunNative("TlcClear", Null)
End Sub

Private Sub TlcSet(Channel As Int, Value As Int)
   TlcChannel = Channel
   TlcValue = Value
   RunNative("TlcSet", Null)
End Sub

#If C
#include <Tlc5940.h>

void TlcInit(B4R::Object* o) {
 Tlc.init();
}
void TlcClear(B4R::Object* o) {
 Tlc.clear();
}
void TlcSet(B4R::Object* o) {
 Tlc.set(b4r_main::_tlcchannel, b4r_main::_tlcvalue);
 Tlc.update();
}
#End If
 
Upvote 0

derez

Expert
Licensed User
Longtime User
Thank you !
I have made a slight change to match the original definitions of the library - TLC.udpate is updating all the sets that where done before it, so you can change the whole set of pins together.

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
   Public Serial1 As Serial
   Private TlcChannel, TlcValue As Int
   Private tmr As Timer
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   RunNative("TlcInit", Null)
   RunNative("TlcClear", Null)
   tmr.Initialize("tmr_Tick",2000)
   tmr.Enabled = True
End Sub

Sub tmr_Tick
    TlcSet(11,4000)
    TlcSet(12,4000)
    TlcSet(14,4000)
    RunNative("TlcUpdate", Null)
    Delay(1000)
    TlcSet(11,0)
    TlcSet(12,0)
    TlcSet(14,0)
    RunNative("TlcUpdate", Null)
End Sub

Private Sub TlcSet(Channel As Int, Value As Int)
   TlcChannel = Channel
   TlcValue = Value
   RunNative("TlcSet", Null)
End Sub

#If C
#include <Tlc5940.h>

void TlcInit(B4R::Object* o) {
Tlc.init();
}
void TlcClear(B4R::Object* o) {
Tlc.clear();
}
void TlcSet(B4R::Object* o) {
Tlc.set(b4r_main::_tlcchannel, b4r_main::_tlcvalue);
}
void TlcUpdate(B4R::Object* o) {
Tlc.update();
}
#End If
 
Upvote 0

derez

Expert
Licensed User
Longtime User
To connect the TLC5940 to Arduino uno you have to use 5 pins: 3,9,10,11,13 (but you gain 16 pins instead).
I have found that you can connect pins 11,13 to the central pins of the ISCP but this does not make 11,13 useable for other things...

I have still to find out how to connect the 5 pins to Wemos D1...
 
Last edited:
Upvote 0
Top