'-------------------------------------------------------- ' variable declarations val02 var byte ' value where reading is stored i var byte ' count variable for loop '-------------------------------------------------------- ' constant declarations cl con 14 ' pin 14 is output (clock) dt con 15 ' pin 15 is the input (data) '-------------------------------------------------------- ' I/O pin setup for detector INPUT dt ' make pin 15 the input HIGH cl ' make pin 14 output and high '-------------------------------------------------------- ' main loop DEBUG "Start", CR ' indicate beginning FOR i = 1 TO 100 ' take and display 100 readings GOSUB read02 ' call measurement routine DEBUG dec val02, CR ' display the value PAUSE 100 ' stall so display readable NEXT DEBUG "Finish" ' indicate end END ' stop Stamp when done '-------------------------------------------------------- ' subroutine read02 ' ' This subroutine takes a reading from the connected ' GP2D02 detector and stores the value in "val02". ' Any two pins can be used. Set "dt" to the data line ' of the GP2D02 (pin 4 on JST connector, yellow wire). ' Set cl to the clock line of the GP2D02 (pin 2 on the ' JST connector, green wire). read02: LOW cl ' turn on detector for reading rl: IF IN15 = 0 THEN rl ' wait for input high SHIFTIN dt, cl, MSBPOST, [val02] HIGH cl ' turn detector off PAUSE 1 ' let detector reset RETURN