#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
Public Serial1 As Serial
Private SerialStream As AsyncStreams
Private Timer1 As Timer
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
SerialStream.Initialize(Serial1.Stream, "SerialStream_DataReceived", "SerialStream_Error")
'Start the IR receiver
RunNative("enableIRIn", Null)
Timer1.Initialize("Timer1_Tick", 100)
Timer1.Enabled = True
End Sub
Sub Timer1_Tick
'Poll the IR Receiver...
Dim res As UInt = RunNative("read", Null)
'If a IR Signal was received....
If res > 0 Then
SerialStream.Write(res) '<------- Don't know what to do here.
End If
End Sub
Sub SerialStream_DataReceived (Buffer() As Byte)
Log("Received: ", Buffer)
End Sub
Sub SerialStream_Error
Log("error")
End Sub
#if C
#include "IRremote.h"
//Signal pin
IRrecv irrecv(11);
decode_results results;
B4R::Object res;
void enableIRIn(B4R::Object* o) {
irrecv.enableIRIn();
}
B4R::Object* read(B4R::Object* o) {
ULong result = 0;
if (irrecv.decode(&results)) {
irrecv.resume();
b4r_main::_lastread = millis();
result = results.value;
}
return res.wrapNumber(result);
}
#end if