Linked from: https://karma-laboratory.com/petridish/2005/04/wp_part_vii_bs2.html.
'{$STAMP BS2sx} '{$PBASIC 2.5} 'Author: Pearl Chen (pearl at karma-laboratory.com) 'Date: Mar 8, 2004 'Revisions: put SERIN in the loop (using a counter now instead of FOR...NEXT) ' which replaces PAUSE so the animation will refresh more often '***** PINS ***** 'Columns (negative / anode) 1 through 8 are pins 8 through 15 respectively 'Rows (positive / cathode) A through H are pins 0 through 7 '***** CONSTANTS ****** P CON 2 'Pause length for how long a row stays lit up Baudmode CON 0 'Baudmode for BS2sx @ 125000 bps SerialPin CON 16 'Pin 16 is the dedicated serial I/O pin on my Stamp '***** VARIABLES ******* col VAR Byte(8) 'col will be a decimal number coming in from Processing to turn on pins 0-7 row VAR Byte 'row will be used as a counter to turn on the pins 8-15 '***** INIT ******* Init: DIRS = %1111111111111111 'Set the direction of all pins to output OUTS = %0000000000000000 'Init all pins to LOW (off) row = 0 'Start off at 0 '***** FUNCTIONS ****** RowScan1: 'RowScan1 is the first half of a routine to handle the appearance of all the LEDs lit up at once HIGH row 'turn on row OUTH = col(row) 'turn on relevant columns all at once (target pins 8-15 by using OUTH) 'Wait for data from Processing via the serial port 'Give it a window of approx. 7ms, otherwise keep on row scanning with current data SERIN SerialPin, Baudmode, 7, RowScan2, [WAIT("A"), STR col\8] 'If data was received, respond back to Processing with a "1" SEROUT SerialPin, Baudmode, ["1"] RowScan2: 'RowScan2 is the second half of a routine to handle the appearance of all the LEDs lit up at once OUTH = 0 'turn off all the columns LOW row 'turn off row row = row + 1 'increment row, if we're at 8, we need to start back at 0 IF (row = 8) THEN row = 0 GOTO RowScan1