Author Topic: Led's Demo  (Read 2476 times)

0 Members and 2 Guests are viewing this topic.

Peter

  • Guest
Led's Demo
« on: February 10, 2011, 10:20:14 AM »
Deleted

.
« Last Edit: April 11, 2015, 08:54:19 AM by Peter »

Charles Pegge

  • Guest
Re: Led's Demo
« Reply #1 on: February 10, 2011, 06:04:45 PM »

Binary counter:

Code: [Select]
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

Charles Pegge

  • Guest
Re: Led's Demo
« Reply #2 on: February 11, 2011, 03:48:19 PM »
Hi Peter

Your code tolerates infinities:  tan(pi*.5)  tan(pi*1.5) Interesting!

Regarding my LED example - some things are better expressed in Assembler than Basic :)

Thanks

Charles

PS I found a bug with the asm test instruction with immediate values less than 256. Its encoding rules are slightly different from the other Arithmetic and Logical operations. I will release this fix very soon. (Alpha029)