Binary counter:
IndexBase 0
Include "Func.inc"
Include "A.inc"
Dim Map(40) As Long
Dim hdc,Led,ibx,idx,icx,iax,F As Long
SetWindow "Leds",646,52,ws_overlapped
hdc = BufferDC
SetFps 24
Led = LoadSprite hdc,"media/ledstrip.bmp",40,40
For ibx=0 To 31
Map(ibx) =1
Next
Sub ShowLeds()
For idx=0 To 31
iF Map(idx) =1
DrawSprite hdc,Led,idx*20,4,20,20,0
End iF
iF Map(idx) =2
DrawSprite hdc,Led,idx*20,4,20,20,1
End iF
Next
End Sub
Sub LedOn(byval x as long)
Map(x-1) =2
End Sub
Sub LedOff(byval x as long)
Map(x-1) =1
End Sub
Sub LedFlush(byval Led as long)
iF F >=4 and F <=32 'duration
LedOn Led
Else
LedOff Led
End iF
End Sub
sub ledbin(byval v as long) 'shows binary value with the LEDs
mov eax,v
mov ecx,32
lea edx,map
(
mov [edx],1
(
shl eax,1
jnc exit
mov [edx],2
)
add edx,4
dec ecx
jnz repeat
)
end sub
long vv 'counter
iax =1
While WinExit =0
ClearBuffer RGB(0,200,0)
LedBin(vv)
ShowLeds
F +=8 'step speed
iF F >=32
F=0
vv+=1
End iF
DoEvents
FlipBuffer
WaitFps
Wend
FreeSprite led
WinEnd
Charles