' ========================================================================= ' File...... bs2_joystick_diagnostics ' Purpose... Joystick Testing application ' Author.... Firestorm_v1 ' E-mail.... firestorm.v1@gmail.com ' Website... http://www.yourwarrantyisvoid.com ' Date...... 01/27/2010 ' Version... 1.0 ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ Program Description ]--------------------------------------------- ' This application is designed to let you test the analog joystick for ' operability and demonstrates the use of RCTIME to detect the joystick's ' position with minimal additional hardware needed. Also allows you to ' test the two buttons on the analog joystick to validate that they are ' working and that your hookups are valid before proceeding. ' -----[ I/O Definitions ]------------------------------------------------- Xaxispin PIN 0 'Pin of X axis pot on joystick Yaxispin PIN 1 'pin of Y axis pot on joystick trigger PIN 2 'Pin for joystick trigger button (Button 1) thumb PIN 3 ' Pin for thumb button (Button 2) ' -----[ Variables ]------------------------------------------------------- time VAR Word 'Generic timer variable (GOSUBs only) pulse VAR Word 'Generic pulse variable (GOSUBs only) rcXtime VAR Word 'Time of cap decay on X axis pot rcYtime VAR Word 'Time of cap decay on Y axis pot ' -----[ EEPROM Data ]----------------------------------------------------- 'None ' -----[ Initialization ]-------------------------------------------------- 'None ' -----[ Program Code ]---------------------------------------------------- DO GOSUB Xaxis 'Get X axis values GOSUB Yaxis 'Get Y axis values DEBUG CRSRXY,0,0 'Home the cursor DEBUG "X time: ",DEC5 rcXtime,CR 'Print X's RCTIME DEBUG "Y time: ",DEC5 rcYtime,CR 'Print Y's RCTIME DEBUG "Button 0:",BIN1 trigger,CR 'Print state of Button 0 (trigger) DEBUG "Button 1:",BIN1 thumb,CR 'Print state of Button 1 (thumb) LOOP '0 = Not pressed, 1 = pressed END ' -----[ Subroutines ]----------------------------------------------------- Xaxis: HIGH Xaxispin 'Charge X axis cap PAUSE 20 ' Wait a few ms RCTIME Xaxispin,1,rcXtime 'Time it's decay and set to rcXtime RETURN Yaxis: HIGH Yaxispin 'Charge Y axis cap PAUSE 20 'Wait a few ms RCTIME Yaxispin,1,rcYtime 'Time it's decay and set to rcYtime RETURN ' -------------------------------------------------------------------------