Blinkin Lites


1 DIM L(8),D(8),A(10),C(10)
2 DATA -50,50,200,10,50,150,1,200,1,150,150,20,70,20,-50,150,-50,150,-20,150
3 FOR I = 1 TO 10: READ A(I),C(I): NEXT
4 FOR I = 0 TO 7: L(I)=1: D(I)=20*RND: NEXT
5 LSB=0: MSB=0: POLD=0: PNEW=0: GOTO 40
7 REM display LEDs & wait in busy loop using switch input
8 REM
9 OUT 255,Z: IF INP(255)=0 THEN 11: REM test for zero wait
10 FOR X=1 TO INP(255)+100+A(P): NEXT: REM adjusted busy wait
11 K=K-1: RETURN
20 REM main loop. select pattern & repeat count
30 REM
40 P=INT((RND10)+1) 45 K=INT(RNDC(P)+10)
50 WHILE K>0:ON P GOSUB 100,200,300,400,500,600,700,800,900,1000:WEND
60 GOTO 40
100 REM scan left and right
101 REM
110 FOR I=0 TO 7: Z=255-(2^I): GOSUB 9: NEXT
120 FOR I=7 TO 0 STEP -1: Z=255-(2^I): GOSUB 9: NEXT
130 RETURN
200 Z=170: GOSUB 9: Z=85: GOSUB 9: RETURN :REM emergency
300 Z=INT(RND*254): GOSUB 9: RETURN: REM random number
400 Z=255-(2^INT(8*RND)): GOSUB 9: RETURN: REM random bit
500 REM two random bits at a time
510 REM
520 Z=255-((2^INT(8RND))+(2^INT(8RND))): IF Z<0 THEN 520
530 GOSUB 9: RETURN
600 Z=240: GOSUB 9: Z=15: GOSUB 9: RETURN: REM L/R nibble
700 FOR I=0 TO 3: Z=255-((2^I)+(2^(7-I))): GOSUB 9: NEXT: RETURN
800 REM random bits on/off for random on/off durations
801 REM
810 Z=0
820 FOR I=0 TO 7: D(I)=D(I)-1
830 IF (D(I)>0) AND (L(I)=1) THEN Z=Z+2^I
840 NEXT
850 GOSUB 9
860 FOR I=0 TO 7: IF D(I)<0 THEN D(I)=20RND: L(I)=-1L(I)
870 NEXT
880 RETURN
900 REM looks like a VU meter
901 REM
910 MSB=INT(RND*9): IF MSBMSB THEN 930
940 FOR I=MSB TO LSB STEP -1: Z=256-(2^I): GOSUB 9: NEXT
950 RETURN
1000 REM simpler more realistic VU meter
1010 REM
1020 POLD=PNEW: PNEW=INT(RND*9)
1030 IF POLD>PNEW THEN FOR I=PNEW TO POLD: Z=256-(2^I): GOSUB 9: NEXT
1040 IF PNEW<POLD THEN FOR I=POLD TO PNEW STEP -1: Z=256-(2^I): GOSUB 9: NEXT
1050 RETURN