IR clicker subroutine

jims

Senior Member
I frequently use an IR clicker to enter data into my programs. This little subroutine is handy to use & it corrects the offset that comes from the numeric keys.

Code:
 '########################################################
'##subroutine to get data from an IR CLICKER & correct
'##the offset from the numeric keys. 20M2 chip.
'#########################################################

symbol ir_clicker=B.0   'B.0 (pin 18 on 20m2)
symbol irdata=b0  	'variable b0

get_1IR:  '##Subroutine    
	irin ir_clicker,irdata  'Get data from the IR clicker on B.0 &
					'put the data in variable b0.
	if irdata=<9 then let irdata=irdata+1:endif  'Correct numeric keys 1 thru 9.
	
      if irdata=10 then let irdata=0:endif	   'Correct the 0 key.
	
	pause 10    		'Probably don't need this pause. 
	  
	return			'clicker data will be in variable b0 when returm to
					' main program.
Jims
 

jims

Senior Member
I frequently use an IR clicker to enter data into my programs. This little subroutine is handy to use & it corrects the offset that comes from the numeric keys.

Code:
 '########################################################
'##subroutine to get data from an IR CLICKER & correct
'##the offset from the numeric keys. 20M2 chip.
'#########################################################

symbol ir_clicker=B.0   'B.0 (pin 18 on 20m2)
symbol irdata=b0  	'variable b0

get_1IR:  '##Subroutine    
	irin ir_clicker,irdata  'Get data from the IR clicker on B.0 &
					'put the data in variable b0.
	if irdata=<9 then let irdata=irdata+1:endif  'Correct numeric keys 1 thru 9.
	
      if irdata=10 then let irdata=0:endif	   'Correct the 0 key.
	
	pause 10    		'Probably don't need this pause. 
	  
	return			'clicker data will be in variable b0 when returm to
					' main program.
Jims
I should have mentioned that I am using a TSOP4038 IR Receiver module connected to input B.0. Jims
 

jims

Senior Member
Here's an updated version of the IR clicker. I've added more comments and some code to pause until the clicker key is released. Prevents possible multiple data from one key press.
Code:
'#####################################################################
'## PICAXE 20M2 chip, and AXE133Y OLED display.
'## Subroutine gets data from an IR CLICKER (using SONY TV '## code 5001);
'## corrects the offset from the numeric keys, & shows data on the OLED display.
'## A "Do loop" pauses until the clicker key is released. Note: My clicker 
'## stops xmitting after about 4 seconds; then the  count goes to zero 
'## (this acts same as releasing the key).
'## This is a good way to see the values returned from an IR clicker.
'#####################################################################

symbol ir_clicker=C.0   'C.0 (pin 10 on 20m2)
symbol irdata=b4  	'variable b4
symbol oled=B.7

#slot 0
#picaxe 20m2
#no_data    	 'Prevents resetting EPROM data (if there is any).

pause 1000  	'Pause to initialize system.
 
serout oled,n2400,(254,1):pause 30  'Clear display

serout oled,n2400,(254,128,"  USE CLICKER   ")

test1:
	call get_1IR
	 
	goto test1

get_1IR:  '##Subroutine to get data from IR clicker.
	 
	irin C.0,irdata  'Get data from the IR clicker on C.0 & put the data in variable b4.
	
	do:let b5=0:count C.0,50,b5:loop until b5=0 'Pauses until key is released.
					
	if irdata<10 then let irdata=irdata+1//10:endif  'Correct numeric keys 1 thru 9.
	
     	
	serout oled,n2400,(254,1):pause 30  	'Clear OLED
	serout oled,n2400,(254,128,"IR DATA WAS: ",#irdata)    'Show key data on OLED.
	
	   'debug    'NOTE: Comment out DEBUG commands when simulating with PE6.
	 
	return
. Jims
 
Last edited:

westaust55

Moderator
@jims,
You might want to revisit the comments.
I did not look far but the first line of "code" /symbol assignments

Symbol ir_clicker = c.0 'B.0 (pin 18 on 20M2)

Is the IR input on C.0 or B.0 ?

I suggest C.0 (physical pin 10 on 20M2) if the code is working but references to pin 18 may catch a newbie or less astute reader out

Then having defined ir_clicker as a symbol/alias in the code you are using C.0 instead of the defined name allocated for the IO pin. Makes it harder (somewhat) if others want to use a different pin and they change the symbol statement only to find it does not then work.

Nevertheless. Thanks for posting your code which others may find a useful start at a future time.
 

jims

Senior Member
@jims,
You might want to revisit the comments.
I did not look far but the first line of "code" /symbol assignments

Symbol ir_clicker = c.0 'B.0 (pin 18 on 20M2)

Is the IR input on C.0 or B.0 ?

I suggest C.0 (physical pin 10 on 20M2) if the code is working but references to pin 18 may catch a newbie or less astute reader out

Then having defined ir_clicker as a symbol/alias in the code you are using C.0 instead of the defined name allocated for the IO pin. Makes it harder (somewhat) if others want to use a different pin and they change the symbol statement only to find it does not then work.

Nevertheless. Thanks for posting your code which others may find a useful start at a future time.
Thank you, Westy. My goof. As I modified the routine, I changed the pin from B.0 (pin 18) to C.0 (pin 10) and never changed the symbol comment from B.0 to C.0. This type of "dumb" mistake seems to happen too often these days. Jims
 
Top