Linked from: https://karma-laboratory.com/petridish/2005/02/working_progres_3.html.

//Author: Pearl Chen (pearl at karma-laboratory.com)
//Date: Feb 27, 2005

float row = 0;      //a floating number for the rows since pow() doesn't accept integer numbers

void setup() { 
  beginSerial();    //begin serial connection, keep default of 9600 baud
} 

void loop() { 

  for (int i=0; i<=7; i++) {    //going to make a pattern here use a counter to do
    row = row + pow( 2, i );    //    some binary math.  The first time through it's
                                //    00000001 = 1, then 00000011 = 3, then 00000111 = 7, etc.
    println(i + ": " + row);    //for debugging                            
    serialWrite(int(row));      //send the row to the Basic Stamp as an integer via the serial port
    delay(50);                  //gives the Basic Stamp some time to receive the serial data
  }
   
  for (int i=7; i>=1; i--) {    //same deal here except the pattern is inverted
    row = row - pow( 2, 7-i );  //    01111111 = 254, then 00111111 = 252, then 00011111, etc.
    println(i + ": " + row);    //there's also a bit of an offset in terms of the counter so
    serialWrite(int(row));      //the pattern shifts down one row each time
    delay(50);
  }
  
  row=0;  //reset to 0
  
}