Sub Process_Globals
Public Serial1 As Serial
Private astream As AsyncStreams
Private tmr As Timer
Private Weight As Float
Private bc As ByteConverter
Private Calfactor = 329, mult = 1 As Float
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
astream.Initialize(Serial1.Stream, "Astream_NewData", "Astream_Error")
RunNative("Begin", Null)
RunNative("Set_scale", Null)
RunNative("Tare", Null)
tmr.Initialize("tmr_Tick",1000)
' tmr.Enabled = True
End Sub
Sub Astream_NewData (Buffer() As Byte)
Log("Received: ", Buffer)
If Buffer = "a" Then Calfactor = Calfactor + mult
If Buffer = "z" Then Calfactor = Calfactor - mult
If Buffer = "q" Then mult = 10*mult
If Buffer = "w" Then mult = mult/10
RunNative("Set_scale", Null)
Delay(100)
RunNative("Get_units", Null)
Delay(100)
Log("Weight= " , Weight, " cal factor= " , Calfactor, " mult= " ,mult)
End Sub
Sub AStream_Error
Log("error")
End Sub
Sub tmr_tick
RunNative("Get_units", Null)
Log(Weight)
End Sub
#If C
#include <HX711.h>
#define DOUT 3
#define CLK 2
//#define calfactor 329
HX711 scale( DOUT , CLK);
void Begin(B4R::Object* o)
{
scale.begin(DOUT , CLK);
}
void Set_scale(B4R::Object* o)
{
scale.set_scale(b4r_main::_calfactor);
}
void Tare(B4R::Object* o)
{
scale.tare();
}
void Get_units(B4R::Object* o)
{
b4r_main::_weight = scale.get_units();
}
#End If