' SEQ1.BS2 ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' This program uses the random number generator to select from a fixed set of ' patterns for turning the output pins on and off. Each pattern comprises a single ' byte. The leftmost six bits control the six outputs (pins 2-7). The rightmost ' two bits define the duration of the pattern display: 00 = 5 seconds; 01 = 10 ' seconds; 10 = 20 seconds; 11 = 40 seconds. n VAR Word ' a random number idx VAR Nib ' current pattern location pattern VAR Byte ' sequence pattern + duration duration VAR Nib ' Pattern + duration defintions DATA %11100000 DATA %10011101 DATA %00011110 DATA %00111011 DATA %11001001 DATA %10001110 DATA %01010100 DATA %00001111 DATA %10010001 DATA %10110110 DATA %01100001 DATA %10001100 DATA %00111110 DATA %01010111 DATA %11101000 DATA %00111100 DATA %00010101 DATA %00011100 DATA %01101101 DATA %11010000 Setup: n = 12345 DIRL = %11111111 ' set all pins to output Test: OUTL = %11111111 ' turn on all outputs for 10 seconds PAUSE 10000 OUTL = %00000000 ' turn off all outputs Main: DO RANDOM n idx = n / 3277 MIN 0 ' scale n to fit 0-19 range READ idx, pattern ' read in sequencer pattern duration.BIT0 = pattern.BIT0 ' get the duration duration.BIT1 = pattern.BIT1 ' get the duration pattern.BIT0 = 0 ' turn off last two bits of pattern (not used for this app) pattern.BIT1 = 0 ' turn off last two bits of pattern (not used for this app) OUTL = pattern ' turn on the outputs SELECT duration ' sleep for amount of seconds indicated by duration CASE %00 SLEEP 5 CASE %01 SLEEP 10 CASE %10 SLEEP 20 CASE %11 SLEEP 40 ENDSELECT LOOP END