Csub NECSend for the PicoMite


Author Message
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3321
Posted: 12:11pm 21 Feb 2024      

Cleaned the sub up a bit and removed debug prints.
Const IRpin = MM.Info(pinno gp1)  'output pin, change as needed
SetPin IRpin, dout : Pin(IRpin) = 0 ' IR code output

Do
 'Your program here.
 Input "Enter Device and Key codes "; dev, key
 NECsend IRpin, dev, key
Loop

Sub NECsend IRpin As integer, dev As integer, key As integer
 Local integer word, d(2200), m, n = 1

 word = (dev<<16) + (key<<8) + ((255 Xor key )And 255) 'assemble 32 bits

 Math set 13 , d() '13=1000/(38*2)uS duration of a half cycle @ 38kHz
 d(672) = 4500  'pause after start pulse train

 For m = 714 To 2100 Step 42  'load data after start sequence
   d(m) = (((word>>(32-n)) And 1)*2 + 1) * 562.5  'convert bits to duration (short = 0, long = 1)
   Inc n 'step to next data bit
 Next

 Device bitstream IRpin, 2199, d() 'send the data

 Pause 100
 Pin(IRpin) = 0
End Sub


Edit.
Trimmed it down a bit further. End sequence removed, which flags a long button press.
This seemed to be needed for the Power button on one device (to guard against an accidental press, I guess).
If it's a problem let me know and I will put it back in.
Edited 2024-02-22 12:41 by phil99