Parallel Port Interface Real Time Counter Trouble.

chr
01-22-2008, 10:26 AM
Greetings to all, I am having small issues with a Visual Basic 6 code I am working on to widen my knowledge. I'm new to the programming scene, hopefully someone here will be able to help.

I'll be lighting up LED lights via Parallel Port. My code is written in Vb6. I'm using the inpout32.dll to send my signals to the pins. I am using a breadboard to establish the circuit. Basically what I am having trouble is to code a counter that can count how many times the LED light is blinking. I have little knowledge about Timers, everything I read about it isn't really helping me. I'll paste my code down here and try and explain it as well as I can in English.

MAIN PROBLEM : Coding a counter that can detect how many times the LED light blinks in real time. I know how to make the light stop blinking after X amount of seconds, that's simple to do. I am just lost on how to be able to make the counter detect how many times it's actually blinking in real time.

Private Declare Function Inp Lib "inpout32.dll" _
Alias "Inp32" (ByVal sgnGo As Integer) As Integer

Private Declare Sub Out Lib "inpout32.dll" _
Alias "Out32" (ByVal sgnGo As Integer, ByVal Value As Integer)


'Variable to send the signals to the pins

Dim sgnGo As String 'Variable to send the single
Dim onOff as Long 'Variable to make the LED blink on/off

'The HEX code for the LPT1 port defined in form_load

Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 1000
Timer2.Enabled = False
Timer2.Interval = 2000
sgnGo = &H378
End Sub

'Out is to simply send the signal to the pin using inpout32.dll

Private Sub pn1_Click()
Timer1.Enabled = True
Timer2.Enabled = False
Out sgnGo, 1
End Sub

Private Sub Timer1_Timer()
Timer1.Enabled = True
Timer2.Enabled = False
onOff = onOff Xor 1 'Light blinks on/off every 1 second
Out sgnGo, onOff
End Sub

Private Sub pn2_Click()
Timer2.Enabled = True
Timer1.Enabled = False
Out sgnGo, 2
End Sub

Private Sub Timer2_Timer()
Timer2.Enabled = True
Timer1.Enabled = False
onOff = onOff Xor 2 'Light blinks on/off every 2 seconds
Out sgnGo, onOff
End Sub

'Procedure to turn off LED lights
Private Sub sgnArret_Click()
Timer1.Enabled = False
Timer2.Enabled = False
Out sgnGo, 0
End Sub

passel
01-22-2008, 07:05 PM
I'm not sure what the question is.
Do you just want to display a total running count for both in one value, or a running count for each, or what?

If a running count, then there are several approaches you can take.
Since you toggle the light every time the timer fires, you could just increment a value in the timer and display that number divided by 2.

Led1_Counter = Led1_Counter + 1
Label_Cnt_1.Caption = Led1_Counter \ 2

You could just check the bit being set in the timer and increment the counter,

If onOff And 1 then Led1_Counter = Led1_Counter + 1
Label_Cnt_1.Caption = Led1_Counter

If onOff And 2 Then Led2_Counter = Led2_Counter + 1
Label_Cnt_2.Caption = Led2_Counter

I'm not sure it that is what you are after.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum