Newsgroups: comp.sys.apple2.programmer Path: blue.weeg.uiowa.edu!news.uiowa.edu!uunet!comp.vuw.ac.nz!actrix.gen.nz!dempson From: dempson@actrix.gen.nz (David Empson) Subject: Re: That Cockroach Problem Again! Message-ID: Organization: Actrix Information Exchange References: <303qej$lba@paperboy.gsfc.nasa.gov> Date: Fri, 15 Jul 1994 14:38:47 GMT Lines: 64 In article <303qej$lba@paperboy.gsfc.nasa.gov>, Bill North wrote: > In article > Jim Yurasits, jay7a@virginia.edu writes: > > > [snip] > > > >100 button1=49249 > >110 button2=40250 Another typo: the above should be button2=49250 > >120 count=0 : roach = 0 > >200 REM *Start of loop* > >210 count=count+1 > >220 if peek(button1)>127 then roach = roach +1 > >230 if peek(button1)>127 then goto 400 : rem Other button was pressed, > >exit > > I presume you meant: > 230 if peek(button2)>127 then goto 400 > ^ > Also remember that button1 & button2 are the same > variable in Applesoft, named "bu". Not only that, but they contain the reserved word ON, so will cause syntax errors. > You also may need a delay between the button peeks to prevent > "paddle read interference." This is only a problem for reading paddles (analog inputs), not buttons (digital inputs). One problem that may come up with all variations of this program: how long does it take the cockroach to pass the sensor, and how does this relate to the speed at which the BASIC program is sampling? Consider the following two situations: 1. The cockroach is racing past the sensor, and the BASIC program isn't polling fast enough, so several counts are missed (the cockroach had already passed the sensor by the time the BASIC program polled it). 2. The cockroach is dawdling, and the BASIC program polls the input several times before the cockroach moves away, registering several counts for the same "pass". The ideal solution in this case would be to write a small machine language routine to do the sampling. It can sample fast enough to guarantee that it won't miss any passes, and it should also ignore consecutive samples during which the input is still active, so that the cockroach is only counted once for each pass. A hardware solution may also be possible, by using a monostable to hold the "cockroach detect" signal for long enough to be read by the BASIC program, in conjunction with ignoring consecutive "on" readings in the program. -- David Empson dempson@actrix.gen.nz Snail mail: P.O. Box 27-103, Wellington, New Zealand