Infrared Remote Control Examples - Command Code 030
Here are some examples of how to use the remote control function within the Infrared Control Freak. The command allows you to take control of your robot, using a standard Sony SIRC remote control unit. If two infrared Control Freaks are used, then one unit can be programmed to control the other unit.

Most of the multi-function remote control units can be configured for Sony SIRC IR standard. The command code 030 is used to set the Infrared Control Freak into Infrared receiving mode.

Any of the button could be used to control different functions for the robot. I have chosen the following button codes:
| Handset Button | Button Code | Translated on the Basic Stamp |
| Fast Forward | 58 | Left |
| Fast Rewind | 59 | Right |
| Volume down | 18 | Forwards |
| Volume Up | 19 | Backwards |
The corresponding LED will illuminate on the Infrared Control Freak
The middle green LED on the Infrared Control Freak will illuminate when this command is selected.

If an infrared signal is detected the circular display will show this pattern:

Videos
Depending on the bandwidth of your Internet connection, these videos may take some time to download.
Place your mouse pointer over the videos and then wait for the video to start.
Basic Stamp Source Code:
'{$STAMP BS2}
'**********************************
'* www.robotmaker.co.uk *
'**********************************
' This program demonstrates the remote control
' command (030) of the Infrared Control Freak
' The Infrared control is connected to the BOE-BOT / GROWBOT
' Which has a Basic Stamp
' The servos are connected to pin 14 and 13 of the Basic Stamp
BUTTON_CODE VAR BYTE 'Infrated Button Code
DEVICE_CODE VAR BYTE 'Infrared Device Code
X VAR WORD 'Simple counter
'The pins on the Basic Stamp are defined
'Where they are connected to on the BOE-BOT
'The Grow bot uses different pin settings
'Servo Connection
RIGHT_SERVO con 14 'Pin 14 for right servo
LEFT_SERVO con 13 'Pin 13 for left servo
'Speaker Connection
SPEAKER con 12 'speaker connected to Pin 12
DELAY con 10 'distance constant
SPEED con 50 'speed constant
'***************************
'* MAIN PROGRAM *
'***************************
MAIN:
Gosub Cricket 'Make a Cricket sound on each cycle
GOSUB COMMAND_030 'Send the Remote control Command to Infrated Control Freak
DEBUG HOME 'Set the cursor on the debug screeen
debug cls 'Clear the debug Screen
GOTO MAIN
'***************************
'* SUBROUTINES *
'***************************
'***************************
'This routine just makes a sound
'like a cricket chirping
CRICKET:
FOR X =18 to 12
freqout 8,X,1900
'toggle spk
NEXT
RETURN
COMMAND_030:
SEROUT 2, 16468, [30]
'***************************
'* SERIAL INPUT LOOP *
'***************************
'This routine send a command to the
'Infrared control freak
Loop:
SERIN 4, 16468,1000,main, [device_code, button_code]
DEBUG "button code =", dec Button_Code," Device Code =",dec Device_code," ", cr
DEBUG " ",CR
DEBUG "____________________________",cr
DEBUG HOME
' This is the Remote Control Branch
'
' Depending on which button is pressed,
' the Basic Stamp will jump to the appropriate routine.
' The following button codes
' where used in this program.
' Any button code could have been used
' If no button code is recognised
' nothing will happen
'
' Button code 18 is volume up
' Button code 19 is volume down
' Button code 58 is fast forward
' Button code 59 is fast rewind
If Button_code = 18 then forward
If Button_code = 19 then back
If Button_code = 58 then left
If Button_code = 59 then right
GOTO Loop
RETURN
'***************************
'* BC 18 *
'***************************
forward: 'otherwise move forward
debug "forward",cr 'debug direction to screen
for x = 1 to delay*2 'distance
pulsout left_servo,750+speed 'pulse left servo
pulsout right_servo,750-speed 'pulse right servo
pause 20 'pause 20 ms
next 'repeat x times
goto MAIN 'jump to sense routine
'***************************
'* BC 19 *
'***************************
back: 'move backward
debug "backward",cr 'debug direction to screen
for x=1 to delay*3 'distance
pulsout left_servo,750-speed 'pulse left servo
pulsout right_servo,750+speed 'pulse right servo
pause 20 'pause 20 ms
next 'repeat x times
goto MAIN 'turn right when done
'***************************
'* BC 58 *
'***************************
left: 'move left
debug "left",cr 'debug direction to screen
for x = 1 to delay*1 'distance
pulsout left_servo,750-speed 'pulse left servo
pulsout right_servo,750-speed 'pulse right servo
pause 20 'pause 20 ms
next 'repeat x times
goto MAIN 'jump to sense routine
'***************************
'* BC 59 *
'***************************
right: 'move right
debug "right",cr 'debug direction to screen
for x = 1 to delay *1 'distance
pulsout left_servo,750+speed 'pulse left servo
pulsout right_servo,750+speed 'pulse right servo
pause 20 'pause 20 ms
next 'repeat x times
goto MAIN 'jump to sense routine
END
|