I have a CHR-3 that i added a little IR Motion sensor i got from radioshack. Its make by Parallax, with a simple 1 bit output. Anyways I wanted to modify the PS2 controller program generated by Powerpod to let me hit the R3 button to engage a “Detection” mode. I Installed a red and a Green Led and wrote a Sub-program that turns the green Led on and swithches it to the Red Red when the input goes High. Here is the code
[code];---------------Start of Motion Sensor Code-------------------;
if (DualShock(1).bit2 = 0) and LastButton(1).bit2 then ;R3 Button test (Motion Detection Mode)
gosub All1500
Nap 4
gosub Init
endif
;----------------End of Motion Sensor Code--------------------; [/code]
And the Sub Program is
[code];--------------------------------------------------------------------
;--------This is a Program to flash a Led [and make a noise] when an Infared Sensor is Tripped---------
;------:::::::Conditions::::::-------;
green con P1 ;-- This sets the green Led to P1
Red con P2 ;-- This sets the Red led to P2
;------Note that the sensor input is set to P0 and the In# command is used to check the state of the pin
;------::::::::Initialization:::::::::--------; (needs up to 30 sec to “read” its surroundings)
init
High Green ;-- Turns Led on while Intializing
pause 5000 ;-- Lets the sensor Initialize for 5 seconds
Sound 9,[100\2535, 100\2785, 100\3035, 100\3285, 100\3535, 100\3785, 100\4035, 300\4285] ;-- Plays a Sound to let you know its ready
pause 100
while IN0=0 then ;-- Starts the While and checks the state of the Sensor on Pin 0 is Low
low red ;-- Turns off the red Led
High green ;-- Keep the green led on if the input is low
wend ;-- Ends the While Command
while In0=1 ;-- Starts the While statement and checks Pin 0 if its High
Low green ;-- Turns the green Led off
high red ;-- Turns the Red led on if Pin 0 is High
Sound 9,[250\3000, 250\2000, 250\3000, 250\2000] ;-- Plays the sound when Pin 0 is High
pause 1000 ;-- Pauses the Program for 1 Sec to allow the sensor to Reset
Low Red ;-- Turns the Red led off
wend ;-- Ends the While Command
Return ;-- Loops the Main program
;------::::::::End of Program::::::::------;[/code]
It works this way but i just goes thru this cycle once and resets itself and i have to press R3 again. I want it to repeat this program until i press R3 again and i cant seem to be able to get the code right. I want it to be like the Knee shift when you press start, like a toggle swithch. I know its just a little problem but anyone got any idea’s how i can go about doing that?