The transmitter is kept in a compartment of our car which is intended for a mobile phone. It has a USB connector for charging.
Codes for controlling lights
#rem Keyboard_Transmitter.bas
Mainly used to open/close the garage door, but can also control lights.
* The * button always cancels everything.
* The # button always transmits codes1-3 if valid. depending on lamp or door protocol
* The A - D keys immediately send specific lamp messages. All 3 LEDS flash once.
* The transmitter returns to idle on timeout
John Saunders 6/29/2017
#endrem
#picaxe 18M2
rem Output ports
symbol Col1 = B.4
symbol Col2 = B.5
symbol Col3 = B.6
symbol Col4 = B.7
symbol TXKey = B.3
symbol RedLED = B.2
symbol YellowLED = B.1
symbol BlueLED = B.0
rem variables for GetKeyHex
symbol RowIn = b1
symbol Iter = b2
symbol KeyHex = b3
rem variables for main
symbol PressCount = b4 '0=Idle,1=First key,2=Second Key,3=third key
symbol LoopCount = w13
rem global variables
symbol Code1 = b5
symbol Code2 = b6
symbol Code3 = b7
rem variables for Transmit and Express
symbol KeyAlpha1 = b8
symbol KeyAlpha2 = b9
symbol KeyAlpha3 = b10
rem constants for GetKeyHex
symbol RowMask = %11000011
symbol Row1val = 2
symbol Row2val = 4
symbol Row3val = 8
symbol Row4val = 1
symbol Col1val = 0
symbol Col2val = 16
symbol Col3val = 32
symbol Col4val = 48
symbol Key0 = Col2val + Row4val
symbol Key1 = Col1val + Row1val
symbol Key2 = Col2val + Row1val
symbol Key3 = Col3val + Row1val
symbol Key4 = Col1val + Row2val
symbol Key5 = Col2val + Row2val
symbol Key6 = Col3val + Row2val
symbol Key7 = Col1val + Row3val
symbol Key8 = Col2val + Row3val
symbol Key9 = Col3val + Row3val
symbol KeyA = Col4val + Row1val
symbol KeyB = Col4val + Row2val
symbol KeyC = Col4val + Row3val
symbol KeyD = Col4val + Row4val
symbol KeyStar = Col1val + Row4val
symbol KeyHash = Col3val + Row4val
rem constants for Transmit
symbol AlphaBase = "0"
symbol AlphaMax = "o"
rem constants for main
symbol Timeout = 800 '17.6 sec
rem Express lamp codes
DATA 10,("R") 'Ceiling Light ON
DATA 11,("B") 'Plays baBa
DATA 12,("i") 'Pole Light ON
DATA 13,("k") 'Pole Light Off
Init:
SETFREQ m8
LOW RedLED
LOW YellowLED
LOW BlueLED
LET Code1=16
LET Code2=16
LET Code3=16
LET PressCount=0
ZeroLoopCount:
LET LoopCount=0
DO 'Wait fot Idle
GOSUB GetKeyHex
LOOP WHILE KeyHex < 16
main: 'Idle loop duration = 22 ms
INC LoopCount
IF LoopCount>=Timeout THEN Init
GOSUB GetKeyHex
SELECT KeyHex
CASE 16
GOTO main
CASE 14
GOTO Init
CASE 15
GOSUB Transmit
CASE 10 TO 13
GOSUB Express
ELSE 'Must be 0-9
SELECT PressCount
CASE 0
HIGH RedLED
LET Code1=KeyHex
LET PressCount=1
CASE 1
LOW RedLED
HIGH YellowLED
LET Code2=KeyHex
LET PressCount=2
CASE 2
LOW YellowLED
HIGH BlueLED
LET Code3=KeyHex
LET PressCount=3
ELSE '3 Ignore more presses
PAUSE 200
ENDSELECT
ENDSELECT
GOTO ZeroLoopCount
END
GetKeyHex: 'Returns the hex value of the key 0-15(*=14,#=15) or 16
LET KeyHex = 16
LOW Col1
LOW Col2
LOW Col3
LOW Col4
FOR Iter = 0 TO 3 'Check each column in turn for a key press
BRANCH Iter,(SetCol1,SetCol2,SetCol3,SetCol4)
SetCol1:
HIGH Col1
GOTO CheckRows
SetCol2:
LOW Col1
HIGH Col2
GOTO CheckRows
SetCol3:
LOW Col2
HIGH Col3
GOTO CheckRows
SetCol4:
LOW Col3
HIGH Col4
GOTO CheckRows
CheckRows:
LET RowIn = pinsC
LET RowIn = RowIn & RowMask
IF RowIn <> 0 THEN
IF RowIn > 15 THEN
LET RowIn = RowIn / 16 'To keep it in 1 byte
ENDIF
LET RowIn = 16 * Iter + RowIn 'Arbitary value for columns
' SERTXD (#RowIn,",")
LOOKDOWN RowIn,(Key0,Key1,Key2,Key3,Key4,Key5,Key6,Key7,Key8,Key9,KeyA,KeyB,KeyC,KeyD,KeyStar,KeyHash),KeyHex
ENDIF
NEXT Iter
RETURN
Transmit:
#rem
* If Code1 is a 9, then the Codes 2&3 cause a lamp message to be sent with a single character
which is the ASXII character with that value + 48 (up to o). The unlock code is 14L1776.
* For Code1 = 0-8 Codes1-3 are sent with unlock code 5Y1234
* The Red and Yellow LEDs flash once.
#endrem
IF Code1 >= 16 OR Code2 >= 16 OR Code3 >= 16 THEN InvalidCodes
IF Code1=9 THEN
LET KeyAlpha1=10*Code2 + Code3 + AlphaBase
IF KeyAlpha1>AlphaMax THEN InvalidCodes
HIGH TxKey
PAUSE 40
LOW TxKey
PAUSE 20
SEROUT TxKey,N2400_8,("14L1776",KeyAlpha1,13,10)
ELSE
LET KeyAlpha1 = Code1 + "0"
LET KeyAlpha2 = Code2 + "0"
LET KeyAlpha3 = Code3 + "0"
HIGH TxKey
PAUSE 40
LOW TxKey
PAUSE 20
SEROUT TxKey,N2400_8,("5Y1234”,KeyAlpha1,KeyAlpha2,KeyAlpha3,13,10)
ENDIF
HIGH RedLED
HIGH YellowLED
PAUSE 500
LOW RedLED
LOW YellowLED
InvalidCodes:
RETURN
Express:
READ KeyHex,KeyAlpha1
HIGH TxKey
PAUSE 40
LOW TxKey
PAUSE 20
SEROUT TxKey,N2400_8,("14L1776",KeyAlpha1,13,10)
HIGH RedLED
HIGH YellowLED
HIGH BlueLED
PAUSE 500
LOW RedLED
LOW YellowLED
LOW BlueLED
RETURN