http://www.instructables.com/id/5x4-LED-display-matrix-using-a-Basic-Stamp-2-bs2/

For charlieplexing to work you turn on just one led at a time. For this to work with our BS2 we need two basic steps:
1. Set the output modes for the pins by using the OUTS command.
2. Tell the BS2 which pins to use as outputs using the DIRS command

This works because the BS2 can be told which pins to drive high and low and will wait to do so until you specify which pins are outputs.
Let's see if things are hooked up correctly by just trying to blink LED 1. If you look at the schematic you can see that P0 is hooked up to the Cathode (-) of LED 1 and P1 is hooked up to the Anode of that same LED. This means we want to drive P0 low and P1 high. This can be done like so: "OUTS = %11110" which drives P4-P1 high and P0 low.
(% indicates a binary number is to follow. The lowest binary digit is always on the right. 0=LOW, 1=HIGH)
The BS2 stores that information but won't act on it until we declare which pins are outputs. This step is key as only two pins should be outputs at the same time. The rest should be inputs, which sets those pins to High Impedance mode so they will not sink any current. We need to drive P0 and P1 so we will set those to outputs and the rest to inputs like so: "DIRS = %00011".
(% indicates a binary number is to follow. The lowest binary digit is always on the right. 0=INPUT, 1=OUTPUT)
Let's put that together into some useful code:






' {$STAMP BS2e}
' {$PBASIC 2.5}
DO
OUTS = %11110 'Drive P0 low and P1-P4 high
DIRS = %00011 'Set P0-P1 as Outputs and P2-P4 as Inputs
PAUSE 250 'Pause for LED to remain on

DIRS = 0 'Set all pins to Input. This will turn off the LED
PAUSE 250 'Pause for LED to remain off
LOOP