***program start*** 10 '*************** Dynamic Lighting ****************** 20 SevenSegDispStr="000":SevenSegDispStrUpdate=1 30 gosub 10000:' init SevenSegDisp 1000 '-------- main loop ------------ 1010 while 1 1020 'gosub 10600: 'turn off 1 char 1100 gosub 10200: 'disp 1ch 1110 if in(18)=0 then 1115 a=inAn(8)*999/1023 1120 SevenSegDispStr=format("%03D",a) 1130 SevenSegDispStrUpdate=1 1140 endif 1500 end while 1599 gosub 10700:'turn off all char 1600 end 10000 '----------- init SevenSegDisp -------------- 10001 ' ------- 10002 ' | a | 10003 ' | f | b 10004 ' | g | 10005 ' ------- 10006 ' | | 10007 ' |e | c 10008 ' | d | 10009 ' ------- 10010 ' a:1 b:2 c:4 d:8 e:16 f:32 g:64 10011 ' 0: 63 = a+b+c+d+e+f 10012 ' 1: 6 = b+c 10013 ' 2: 91 = a+b+g+e+d 10014 ' 3: 79 = a+b+g+c+d 10015 ' 4: 102 = f+g+b+c 10016 ' 5: 109 = a+f+g+c+d 10017 ' 6: 125 = a+f+g+c+d+e 10018 ' 7: 7 = a+b+c 10019 ' 8: 127= a+b+c+d+e+f+g 10020 ' 9: 111= a+b+c+d+f+g 10030 ' output: SevenSegCharData[],SevenSegDispCharPosIndicator 10040 ' SevenSegDispChar[],SevenSegCommonDOpinNo[] 10050 dim SevenSegCharData[10] 10060 SevenSegCharData[0]=63 10070 SevenSegCharData[1]=6 10080 SevenSegCharData[2]=91 10090 SevenSegCharData[3]=79 10100 SevenSegCharData[4]=102 10110 SevenSegCharData[5]=109 10120 SevenSegCharData[6]=125 10130 SevenSegCharData[7]=7 10140 SevenSegCharData[8]=127 10150 SevenSegCharData[9]=111 10170 SevenSegDispCharPosIndicator=0 10180 dim SevenSegDispChar[3]:SevenSegDispChar[0]=0 10181 SevenSegDispChar[1]=0:SevenSegDispChar[2]=0 10182 dim SevenSegCommonDOpinNo[3]:SevenSegCommonDOpinNo[0]=0 10183 SevenSegCommonDOpinNo[1]=2:SevenSegCommonDOpinNo[2]=5 10190 return 10200 '------------------- disp 1ch ------------------------ 10210 ' input: SevenSegDispStr 10220 ' SevenSegDispStrUpdate - 0:none 1:update 10230 ' SevenSegDispCharPosIndicator - disp char Position (0-2) 10240 ' change: SevenSegDispStrUpdate 10250 ' output: SevenSegDispChar[] 10260 if SevenSegDispStrUpdate=1 then 10270 SevenSegDispChar[0]=val(mid(SevenSegDispStr,0,1)) 10280 SevenSegDispChar[1]=val(mid(SevenSegDispStr,1,2)) 10290 SevenSegDispChar[2]=val(mid(SevenSegDispStr,2,3)) 10300 SevenSegDispStrUpdate=0 10310 end if 10400 '----------- disp 1 char -------------- 10410 ' a-7:IO7 b-6:IO6 c-4:IO4 d-3:IO3 e-1:IO1 f-16:DO0 g:17:DO1 10420 ' input:SevenSegDispCharArg (0-9) 10421 out SevenSegCommonDOpinNo[SevenSegDispCharPosIndicator],1 10422 SevenSegDispCharPosIndicator=SevenSegDispCharPosIndicator+1 10423 if SevenSegDispCharPosIndicator>2 then SevenSegDispCharPosIndicator=0 10425 temp1=SevenSegDispChar[SevenSegDispCharPosIndicator] 10430 temp=SevenSegCharData[temp1] 10440 if temp>=64 then out 17,1:temp=temp-64 else out 17,0 10450 if temp>=32 then out 16,1:temp=temp-32 else out 16,0 10460 if temp>=16 then out 1,1:temp=temp-16 else out 1,0 10470 if temp>=8 then out 3,1:temp=temp-8 else out 3,0 10480 if temp>=4 then out 4,1:temp=temp-4 else out 4,0 10490 if temp>=2 then out 6,1:temp=temp-2 else out 6,0 10500 if temp>=1 then out 7,1 else out 7,0 10510 out SevenSegCommonDOpinNo[SevenSegDispCharPosIndicator],0 10540 return 10600 '--------- turn off 1 char ----------- 10610 'out SevenSegCommonDOpinNo[SevenSegDispCharPosIndicator],1 : return 10620 'out 0,1:out 2,1:out 5,1:return 10700 '--------- disp 3 char end ---------------- 10720 out 17,0:out 16,0:out 1,0:out 3,0:out 4,0:out 6,0:out 7,0 10730 out 0,0:out 2,0:out 5,0 10750 return ***program end***