[comp.sys.apple] Reading Button with PDL

dr@ski.UUCP (David Robins) (12/25/87)

In article <> tgm@xroads.UUCP (Sloan Tash) writes:
>In article <1564@ttidca.TTI.COM>, paulb@ttidca.TTI.COM (Paul Blumstein) writes:
>> Easily done!  The open-apple and closed-apple correspond to joystick
>> buttons 1 & 2.
>
>Actually, they're buttons 0 and 1. (You can read them with the PDL(0) or
>PDL(1) commands).
>
>TGM
>-- 
>\  /  C r o s s r o a d s  C o m m u n i c a t i o n s
> \/   (602) 971-2240
> /\   (602) 992-5007 300|1200 Baud 24 hrs/day
>/  \  ihnp4!mot!nud!xroads!*

WRONG.  The Applesoft PDL(n) function reads the paddle inputs, which
are analog inputs.  This gives a reading of 0-255, depending on
the resistance (150K pot is standard) used in the potentiometer
voltage divider on the input.

To read the switch inputs (buttons 0,1,2 on joysticks, or Open-Apple,
Closed Apple, and nothing on the keyboard) you need to use PEEKs from
Applesoft.  The addresses to peek are:

	Switch input 0 (open apl)  : 49249
	Switch input 1 (close apl) : 49250
	Switch input 2             : 49251

The are read as PEEK(49249), for example.
The switch input affects only bit 7 of the address.
To see if sw. 0 is closed do this:
	A= PEEK (49249)
	PRINT A
If A is less than 128, then the switch is open.  
If A is 128 or greater, it is closed.
(Note than the reading at this address may vary; only its relationship
to the number 128 is of any consequence.)

You can also use the syntax:
	IF PEEK (49249) < 128 THEN ...
or	IF PEEK (49249) >= 128 THEN ...
-- 
					-dave

====================================================================
David Robins, M.D.  (ophthalmologist / electronics engineer)
Smith-Kettlewell Eye Research Foundation
(previously known as: Smith-Kettlewell Institute of Visual Sciences)
2232 Webster St; San Francisco CA 94115
415/561-1705 (voice)
			{ihnp4,qantel,dual}!ptsfa!ski!dr

The opinions expressed herein do not reflect the opinion of the Institute!