Sub Process_Globals
  Public Serial1 As Serial
  Private lastRead As UInt 'ignore
  Private mData As ULong 'ignore
  Private mNbits As Int 'ignore
  Private pin8 As Pin
End Sub
Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   RunNative("enableIRIn", Null)
   AddLooper("Looper1")
   pin8.Initialize(8,pin8.MODE_INPUT_PULLUP)
    pin8.AddListener("Button")
End Sub
Sub SendSony (data As ULong, nbits As Int)
   mData = data
   mNbits = nbits
   RunNative("sendSony", Null)
End Sub
Sub SendNEC (data As ULong, nbits As Int)
   mData = data
   mNbits = nbits
   RunNative("sendNEC", Null)
Log("sent nec")
End Sub
Sub Looper1
  If Millis > lastRead + 500 Then
      Dim res As UInt = RunNative("read", Null)
      If res > 0 Then
          Log("Received: ", res)
      End If
  End If
End Sub
Sub Button(State As Boolean)
    If State Then
        SendNEC(4335,4) ' I don't understand the meaning of the nbits (4) , tried other numbers also.
        'SendNEC(0x20DF10EF,20)
    End If
End Sub
#if C
#include "IRremote.h"
IRrecv irrecv(5); //signal pin. Change as needed
IRsend irsend;
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);
}
void sendSony (B4R::Object* o) {
   irsend.sendSony(b4r_main::_mdata, b4r_main::_mnbits);
}
void sendNEC(B4R::Object* o) {
    irsend.sendNEC(b4r_main::_mdata, b4r_main::_mnbits);
}
#end if