Let's Make Robots!

Help With Visual Basic coding

Hi there ....I want to make something in vb (an application which i made to work with the arduino uno)  and i put a notification icon (in a timer). But i want everytime the value from the arduino uno change send me a message with the notification icon that the value change ....

AttachmentSize
Code.txt1.19 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Not sure exactly what you need, but here is a good example of how to hook up an Arduino to monitor a battery level.

http://arduinotronics.blogspot.com/2011/03/monitoring-voltage-of-dc-battery-supply.html

The guy also shows the code in C-language to do it.  I do not work with Visual Basic, but I am thinking you can change the syntax from C to VB.

 

Dan M.

___________________________________________________________________________________

( Extra Stuff )

 

———————————————————————————————————————

Private Sub Timer4_Tick(sender As System.Object, e As System.EventArgs) Handles Timer4.Tick
        If Label2.Text <= 13.0 And Label2.Text > 9.0 Then
            psm.BalloonTipIcon = ToolTipIcon.Warning
            psm.BalloonTipText = " I'm feeling really listless and drained lately. Maybe I should sit down."
            psm.BalloonTipTitle = "Power System Monitor"
            psm.ShowBalloonTip(1500)
        End If

        If Label2.Text > 8.0 And Label2.Text <= 9.0 Then
            psm.BalloonTipIcon = ToolTipIcon.Warning
            psm.BalloonTipText = " HEY! I'm dying over here!  Doesn't anyone CARE?"
            psm.BalloonTipTitle = "Power System Monitor"
            psm.ShowBalloonTip(1500)
        End If
        If Label2.Text <= 8.0 Then
            My.Computer.Audio.Play(My.Resources.low, AudioPlayMode.WaitToComplete)
            psm.BalloonTipIcon = ToolTipIcon.Warning
            psm.BalloonTipText = " I WARNED you. Now I'm getting dizzy and nauseous, —I'm about to pass out. —Shutting down."
            psm.BalloonTipTitle = "Power System Monitor"
            psm.ShowBalloonTip(1500)
            Dim SAPI
            SAPI = CreateObject("SAPI.spvoice")
            SAPI.Speak(" I'm getting dizzy and nauseous, —I'm going to pass out. —Shutting down.")
        End If
    End Sub

I'm on my phone and as of this morning (00:30 here) I won't have access to my PC for a week. But I can see the issue. Lets assumethe battery voltage is 10.2 or something. Every time your timer ticks its going to see a voltage of 10.2 and trigger the below 13 and trigger the first balloon. If it gets to 8 with your current code structure it will trigger all 3 balloons every time the timer ticks. Its fixable. What you need to do is keep track of whether the notification has been raised already. Only if the notification has NOT been raised should you raise the notification. A simple bool (well 3, 1 for each notification type) will suffice. When the battery voltage is registered as 13, check if notification for low battery has been raised, if no then raise the notification and set the bool to say that you have raised this notification already. It won't be raised again. I would also advise a major restructure, you don't want 3 separate if statements, I would restructure it into either an elseif chain or a switch case. I wouldn't use 3 statements either, I would add a fourth that resets the bools we used for keeping track of those notification bubbles if the battery voltage happens to go up again. I can't post exact code but something like: If battery < 13 . do stuff Elseif battery < 9 . do more stuff Elseif battery < 8 . do yet even more stuff Else . reset the counters because the voltage has gone up Endif Sorry I can't post exact code, I won't be able to for a week either by which point I will have probably forgotten about thus thread. Its pretty straight forward stuff, you should be able to work it out or someone else might be able to help. Oh one last thing. Your using label2.text as a regular variable. Very bad practise. Also label.text is a string so a less than or greater than test with a float may not function correctly, always compare a float with a float and strings with strings. You should add an actual variable to your code for storing the voltage and compare against that, you use this variable to set the label, you don't then use the label as a variable as such unless you are really micro-optimising or have very good reason to. Your if chains are also wrong as you should be using <= the whole way through, you have the if thingy <= 13, then switch to = for the other 2. <= or < the whole way through (either one, but be consistent), = alone will give weird results such as a voltage of 3.4 only triggering the < 13 statement but not the < 9 or < 8 statements.

Ok here more info ...I upload the code.....If  you see is in a timer. When i run it it start to pop up the notification ballons that i great.But after i click to close notification icon it continues to pop up the balloon. And my question is how i can great a repeatedly check of the label and only if the (If) in the code match then pop up the message..