Hi All,
Still working on my R/C Dyno software(see my other threads).
Have dug up my very first code that I wrote for reading impulses.
It didn't work the way I intended.
It reads the incoming impulses for one second,and writes them to a TextBox.
Problem was,during the 1 second timer interval,you could see the impulses being counted.1,2,3,4,5............101,102,103 and so on until the timer interval was finished,then it would start over at zero,and count up again.Slightly unreadable.
But now I think I can use this to my advantage.
What I would like to accomplish is to have it still visably read the impulses,like it does now,but instead of starting over at zero it should hold it's last count until the impulses change.Like if impulses count up to 25 and level off,I want to see it count 1,2,3,4.....23,24,25,25,25,25,.And if the count goes up or down I want to see it,as in 25,26,27,27,27 or 25,24,23,23,23.If a change occurs from "steady" state,it should'nt start over counting at zero.
If at all possible I would like to utilise the Timer I already have,and not use a 2nd timer .I already have working code that uses 2 timers to hold the last interval count but it counts in the background ,so I don't see the count between intervals.
Is this even possible to do?
(I know this code is ragged looking ,but I'll fine tune it later.)
Still working on my R/C Dyno software(see my other threads).
Have dug up my very first code that I wrote for reading impulses.
It didn't work the way I intended.
It reads the incoming impulses for one second,and writes them to a TextBox.
Problem was,during the 1 second timer interval,you could see the impulses being counted.1,2,3,4,5............101,102,103 and so on until the timer interval was finished,then it would start over at zero,and count up again.Slightly unreadable.
But now I think I can use this to my advantage.
What I would like to accomplish is to have it still visably read the impulses,like it does now,but instead of starting over at zero it should hold it's last count until the impulses change.Like if impulses count up to 25 and level off,I want to see it count 1,2,3,4.....23,24,25,25,25,25,.And if the count goes up or down I want to see it,as in 25,26,27,27,27 or 25,24,23,23,23.If a change occurs from "steady" state,it should'nt start over counting at zero.
If at all possible I would like to utilise the Timer I already have,and not use a 2nd timer .I already have working code that uses 2 timers to hold the last interval count but it counts in the background ,so I don't see the count between intervals.
Is this even possible to do?
(I know this code is ragged looking ,but I'll fine tune it later.)
VB.NET:
Public Class Form1
Dim Rev As Double
Dim updatetext As Integer
Dim impulse As Integer = 1
Dim imp_count As Integer = 0
Dim RPM As Integer
Dim time_sec As Integer
Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.Open() 'open the port for access
Timer1.Enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SerialPort1.Close()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Interval = 1000 'set the time interval
While Timer1.Interval < 1000
TextBox1.Text = imp_count
End While
imp_count = 0
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
time_sec = time_sec + 1
'imp_count = 0
time_sec = 0
If impulse > 0 Then
imp_count = imp_count + 1
End If
RPM = imp_count
Rev = imp_count / 3
updatetext = RPM
Me.Invoke(New EventHandler(AddressOf TextUpdate))
End Sub
Private Sub TextUpdate(ByVal sender As Object, ByVal e As EventArgs)
TextBox1.Text = updatetext
TextBox2.Text = updatetext
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
TextBox2.Text = Rev
End Sub
End Class