Infra Red Signals >>> LED Strip Light

slimplynth

Senior Member
#1
Evenin'


Following on from Tex's poll on what people's recent projects are.. below is the code I used to get a 28X2 to generate IR signals. Originally used Audacity software to record every button press on every remote in the house, plenty of free soundcard oscilloscopes and circuits to google on the web (attached pdf showing the Power signal.. It's easy to run out of Gosubs/program space so I just broke the signals down into 4 bit sequences.. 0000 1111 0011 etc.. gosub zero_zero_zero_zero.. makes debugging easier.. in fact the whole process is a bit boring.. hopefully the code is easy to follow...

Code:
#no_data
'======================LED Strip Light IR Remote Control=================================

setfreq em64 'THIS CODE REQUIRES 20X2 PICAXE OR 28X2 WITH AN EXTERNAL 16MHz RESONATOR)!!!

'IR symbols
symbol Squelch_Hi = b0 'This is the high section of the header
symbol Squelch_Lo = b1 'This is the Low section of the header
symbol Zero_Lo = b2
symbol Zero_Hi = b3
symbol One_Lo = b4
symbol One_Hi = b5
symbol Address_Lo = b6
symbol Gap_Lo = b7
symbol IR_Pin = C.1 
symbol Response = b8
symbol Rx = C.2
'symbol Tx = C.1
symbol dat_BAUD = T9600_64 'Baud rate used when the HC-05 is in Data Mode

'config the IR protocol timings - these need to be quite close to the recorded/cloned signal

Squelch_Hi = 727/10 'DO NOT CHANGE - these 'squelches' are the first two parts of the signal
Squelch_Lo = 35 'DO NOT CHANGE

Zero_Hi = 389/100 'is the trough for zero
Zero_Lo = 310/100 'is the peak for zero

One_Hi = 389/100  'is the trough for one
One_Lo = 1280/100 'is the peak for one

Address_Lo = 30 'these two needed for other RC signals (air conditioner)
Gap_Lo = 950     '

'Total Prog Size = 2293bytes
'============================================================
'============ Remote Control Button Functions ===============
' 
'81 ' Dark Orange = 0010 1010 1101 0101
'82 ' Mid Orange = 0000 1010 1111 0101
'83 'Light Orange = 0011 1000 1100 0111
'84 'Yellow = 0001 1000 1110 0111
'85 'Dark Green = 1011 1000 0100 0111
'86 'Medium Green = 1000 1010 0111 0101
'87 'Light Green = 1010 1010 0101 0101
'88 'Dark Blue = 1010 0010 0101 1101
'89 'Medium Blue = 1011 0010 0100 1101
'90 ' Light Blue = 1111 1000 0000 0111
'91 'Bright Blue = 1001 0010 0110 1101
'92 'Purple with Pink Tinge = 0001 0010 1110 1101
'93 'White = 0010 0010 1101 1101
'94 'Power = 0000 0010 1111 1101
'95 'Fade = 1110 0000 0001 1111
'96 'Bright up = 0011 1010 1100 0101	
'97 'Bright Down = 1011 1010 0100 0101

main:

serin Rx,dat_BAUD,Response ' whatever radio receiver used

select case Response

case 81 ' Dark Orange = 0010 1010 1101 0101

	gosub Device_Code
	gosub zero_zero_one_zero
	gosub one_zero_one_zero
	gosub one_one_zero_one
	gosub zero_one_zero_one
	'gosub One
	goto main
	
case 82 ' Mid Orange = 0000 1010 1111 0101
	gosub Device_Code
	gosub zero_zero_zero_zero
	gosub one_zero_one_zero
	gosub one_one_one_one
	gosub zero_one_zero_one
	'gosub One
	goto main
	
case 83 'Light Orange = 0011 1000 1100 0111
	
	gosub Device_Code
	gosub zero_zero_one_one
	gosub one_zero_zero_zero
	gosub one_one_zero_zero
	gosub zero_one_one_one
	'gosub One
	goto main
	
case 84 'Yellow = 0001 1000 1110 0111
	
	gosub Device_Code
	gosub zero_zero_zero_one
	gosub one_zero_zero_zero
	gosub one_one_one_zero
	gosub zero_one_one_one
	'gosub One
	goto main
	
case 85 'Dark Green = 1011 1000 0100 0111
	
	gosub Device_Code
	gosub one_zero_one_one
	gosub one_zero_zero_zero
	gosub zero_one_zero_zero
	gosub zero_one_one_one
	'gosub One
	
case 86 'Medium Green = 1000 1010 0111 0101
	
	gosub Device_Code
	gosub one_zero_zero_zero
	gosub one_zero_one_zero
	gosub zero_one_one_one
	gosub zero_one_zero_one
	'gosub One
	goto main
	
case 87 'Light Green = 1010 1010 0101 0101
	
	gosub Device_Code
	gosub one_zero_one_zero
	gosub one_zero_one_zero
	gosub zero_one_zero_one
	gosub zero_one_zero_one
	'gosub One
	goto main
	
case 88 'Dark Blue = 1010 0010 0101 1101
	
	gosub Device_Code
	gosub one_zero_one_zero
	gosub zero_zero_one_zero
	gosub zero_one_zero_one
	gosub one_one_zero_one
	'gosub One
	goto main
	
case 89 'Medium Blue = 1011 0010 0100 1101
	
	gosub Device_Code
	gosub one_zero_one_one
	gosub zero_zero_one_zero
	gosub zero_one_zero_zero
	gosub one_one_zero_one
	'gosub One
	goto main
	
case 90 ' Light Blue = 1111 1000 0000 0111
	
	gosub Device_Code
	gosub one_one_one_one
	gosub one_zero_zero_zero
	gosub zero_zero_zero_zero
	gosub zero_one_one_one
	'gosub One
	goto main
	
case 97 'Bright Blue = 1001 0010 0110 1101
	
	gosub Device_Code
	gosub one_zero_zero_one
	gosub zero_zero_one_zero
	gosub zero_one_one_zero
	gosub one_one_zero_one
	'gosub One
	goto main
	
case 98 'Purple with Pink Tinge = 0001 0010 1110 1101
	
      gosub Device_Code
	gosub zero_zero_zero_one
	gosub zero_zero_one_zero
	gosub one_one_one_zero
	gosub one_one_zero_one
	'gosub One
	goto main
	
case 99 'White = 0010 0010 1101 1101
	
	gosub Device_Code
	gosub zero_zero_zero_one
	gosub zero_zero_one_zero
	gosub one_one_one_zero
	gosub one_one_zero_one
	'gosub One
	goto main

case 100 'Power = 0000 0010 1111 1101
	
	gosub Device_Code
	gosub zero_zero_zero_zero
	gosub zero_zero_one_zero
	gosub one_one_one_one
	gosub one_one_zero_one
	'gosub One
	goto main

case 101 'Fade = 1110 0000 0001 1111
	
	gosub Device_Code
	gosub one_one_one_zero
	gosub zero_zero_zero_zero
	gosub zero_zero_zero_one
	gosub one_one_one_one
	'gosub One
	goto main 
	
case 102 'Bright up = 0011 1010 1100 0101

	gosub Device_Code
	gosub zero_zero_one_one
	gosub one_zero_one_zero
	gosub one_one_zero_zero
	gosub zero_one_zero_one
	'gosub One
	goto main 
	
case 103 'Bright Down = 1011 1010 0100 0101
	
	gosub Device_Code
	gosub one_zero_one_one
	gosub one_zero_one_zero
	gosub zero_one_zero_zero
	gosub zero_one_zero_one
	'gosub One
	goto main
	
else 
	goto main
	
endselect

goto main

Device_Code:

' This section generates the header pre device code- Squelch Lo >>> Hi
pwmout pwmdiv4, IR_Pin, 104, 211
pause Squelch_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Squelch_Lo
pwmout pwmdiv4, IR_Pin, 104, 211

' This section generates the Adress Code - TV = 0000 0000 1111 1111
'part One
'zero
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'zero
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'zero
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'zero
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'zero
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'zero
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'zero
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'zero
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'device code part 2

'One
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'One
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'One
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'One
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'One
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'One
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'One
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'One
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

Return

zero_zero_zero_zero:
'0000
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

return

one_one_one_one:
'1111
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

return
 

slimplynth

Senior Member
#2
Code:
one_zero_one_zero:

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

return

zero_one_zero_one:
'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

return

'0010
zero_zero_one_zero:
'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

return

'0011 
zero_zero_one_one:
'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

return

'1000 
one_zero_zero_zero:

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

return

'1100 
one_one_zero_zero:

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

return

'0111
zero_one_one_one:
'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

return

'0001
zero_zero_zero_one:
'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo
return
'1110 
one_one_one_zero:
'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

return

'1011
one_zero_one_one:
'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

return

'0100 
zero_one_zero_zero:
'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo
return


one_one_zero_one:
'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

return

one_zero_zero_one:
'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

return

zero_one_one_zero:
'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'1
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo

'0
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo

return
Zero: 'create a single logical Zero
pwmout pwmdiv4, IR_Pin, 104, 211
pause Zero_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause Zero_Lo
Return

One: 'create a single logical One
pwmout pwmdiv4, IR_Pin, 104, 211
pause One_Hi
pwmout pwmdiv4, IR_Pin, 00,00
pause One_Lo
Return
 

slimplynth

Senior Member
#4
It's pretty mind numbing, counting and measuring the individual bits but I ended up finding that printing the signals off individually in landscape view, then use a ruler to move along and write the 1's and 0's worked well..one last thing, I've got bash scripts set up on a raspberry pi lamp server.. sending the ASCII codes over a 433 tx/rx.. id sent a power signal followed by the fade signal.. for some reason LED light controllers are known for jumbling up their signals... To fix it, press Red then OFF then FADE then ON (repeat until the keys pressed match the observed colour).. that caused me much confusion, thought I'd broken the controller in some way by passing a dodgy command..
 

hippy

Technical Support
Staff member
#5
One thing you can use to save typing and avoid errors is #MACRO ...

Code:
#Macro Output_0
  pwmout pwmdiv4, IR_Pin, 104, 211
  pause Zero_Hi
  pwmout pwmdiv4, IR_Pin, 00,00
  pause Zero_Lo
#EndMacro

#Macro Output_1
  pwmout pwmdiv4, IR_Pin, 104, 211
  pause One_Hi
  pwmout pwmdiv4, IR_Pin, 00,00
  pause One_Lo
#EndMacro

one_zero_one_zero:
  Output_1
  Output_0
  Output_1
  Output_0
  Return
 
Top