i have a k8055 and i am building a pine wood derby timer i used 2 photoresisters wired in series to the digital input i have it kinda working on an excel spread sheet i found on the forum about a lap counter. i am new and not very good on writing code. could someone help or at least point me i the right direction to have input #1 is triggered to start the timer and when it is trigger again to stop .The problem is the input is inverted
Is it enough to have only one lane - or more?
If more than one - how many lanes do you like to have?
How many lap times should be displayed?
Thank you for your reply.I only have one lane right now but would like to build a second so 2 lanes and I just need on show
2 lap times per lane
Now the Excel VBA macro is slightly modified.
Now it works with inverted inputs.
You can emulate the phototransistors by using the buttons on the K8055 card.
Now releasing the button is the “active” state.
There are time counters for each lane.
The first release of the button starts the lap time counter of the lane.
The next release of the button means that the first lap is complete and the lap time will be displayed.
Here is the link to download the Excel workbook:
box.com/s/zza3pt7u2q1g1qf5fti7
The VBA code is in “Module1”.
Here is the code:
[code]
Option Explicit
Private Declare Function OpenDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib “k8055d.dll” ()
Private Declare Function ReadAllDigital Lib “k8055d.dll” () As Long
Private Declare Function SetTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long
Dim TimerID As Long
Dim TimerSeconds As Single
Dim time(0 To 4) As Long
Dim lap(0 To 4) As Long
Dim timecounter_enabled(0 To 4) As Boolean
Dim timecounter(0 To 4) As Long
Dim timecounter_old(0 To 4) As Long
Dim old_data As Long
Sub Button1_Click()
Dim h As Long
Dim i As Long
For i = 0 To 4
timecounter_enabled(i) = False
timecounter(i) = 0
timecounter_old(i) = 0
time(i) = 0
lap(i) = 0
Next i
h = OpenDevice(0)
If h = 0 Then
ActiveSheet.Cells(1, 8) = “Card 0 Connected”
TimerSeconds = 0.01 ’ the timer interval is now 0.01 sec.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
Else
ActiveSheet.Cells(1, 8) = “Card 0 Not Found”
End If
End Sub
Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long)
On Error Resume Next
Dim data As Long
Dim diff As Long
Dim i As Long
For i = 0 To 4
If timecounter_enabled(i) = True Then ' check if the timecounter for this lane is started
timecounter(i) = timecounter(i) + 1 ' increment the time counter by 10 milliseconds
End If
Next i
data = ReadAllDigital()
If data < old_data Then ' check if any one of the digital inpus is pulled UP by the phototransistor or switch.
diff = old_data - data
For i = 0 To 4
If (diff And 2 ^ i) > 0 Then ' find the input who changed state
lap(i) = lap(i) + 1 ' increment lap counter for this lane
timecounter_enabled(i) = True ' enable time counter for this lane
ActiveSheet.Cells(lap(i) + 1, i + 2) = 0.01 * (timecounter(i) - timecounter_old(i)) ' print the lap time for this lane in seconds
timecounter_old(i) = timecounter(i) ' save the time counter value
End If
Next i
End If
old_data = data
End Sub
Sub Button2_Click()
KillTimer 0&, TimerID
CloseDevice
ActiveSheet.Cells(1, 8) = “Card 0 Closed”
End Sub[/code]
Thank you very much it works great