Results 1 to 40 of 68

Thread: [RESOLVED] Converting voltage level into graphical display

Hybrid View

  1. #1
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: [RESOLVED] Converting voltage level into graphical display

    Quote Originally Posted by catherine0136 View Post
    [CODE] i replace the ( , ) value to the values of where the x and y line intersect each other ?
    Exactly.

    Code:
    g.DrawLine(BluePen, 50, 120, 260, 120)  'horizontal line
    If that line is your X axis, it extends from point (50, 120) to point (260, 120), so must be 210 pixels long. You could fill in that 210 everywhere instead of xAxisLength, but it would be better to keep using the variable name instead:
    vb.net Code:
    1. Dim xAxisLength As Integer = 210
    2.  
    3. 'and then, as before:
    4.  
    5. x = Origin.X + CInt(i * xAxisLength / 40)
    The same obviously applies to the Y axis. This way there is just one place where you set the axis length. It will be easier to change you layout if you need to. After all, you may need to play around with these figures to get the graph looking right.

    You realize of course that xAxisLength is just a name I made up. An important part of the art of programming is thinking up good names for variables. To come to think of it, it would be better to replace that "40" by a variable to represent the number of data points to be plotted. In that case you would have to declare (with Dim or Private) whatever name you have chosen for the variable. You should do it outside the sub, for example with other variables near the top of the form code, because it is also referred to in the timer Tick sub.

    BB
    Last edited by boops boops; Jan 10th, 2010 at 07:49 AM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    I had this error :
    Code:
    'ElementAt' is not a member of 'System.Collections.Generic.Queue(Of Single)'
    How do i resolve this?

  3. #3
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: [RESOLVED] Converting voltage level into graphical display

    That must be because you are using an older version of Visual Studio than 2008. I hadn't thought of that. It means the Paint sub I posted in #47 needs a couple of small changes. Add this before line 10 of the sub:

    Code:
    'Turn the queue into an array:
    Dim voltsQarray As Single() = voltsQ.ToArray
    and change the present line 17 to this:
    Code:
    Dim v As Single = voltsQarray(i)
    That should fix it. BB

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: [RESOLVED] Converting voltage level into graphical display

    I just spotted another error in the Paint sub: the code will fail if voltsQ is empty. In fact there is not much sense in trying to draw the curve until there are at least 3 data points in the queue. So you should enclose all the code after drawing the axes in this If statement:
    Code:
    If VoltsQ.Count > 2
    ...
    End If
    BB

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    Thanks for helping ! =)

    Am i right to place the VoltsQ.Count>2 as follows, please correct me if i'm wrong.

    Code:
    If VoltsQ.Count > 2
    
     'Put your code for drawing the axes etc. here.
    
    
                'Details of the graph layout -- fill in your own values here!
                Dim Origin As New Point(50, 119)
                Dim xAxisLength As Integer = 210
                Dim yAxisLength As Integer = -120
    
                'Turn the queue into an array:
                Dim voltsQarray As Single() = voltsQ.ToArray
    
                'Define an array of data points:
                Dim DataPoints(voltsQ.Count - 1) As Point
                Dim x, y As Integer
    
                'Fill in the array using the voltage readings:
                For i As Integer = 0 To voltsQ.Count - 1
                    'Get the volts value from the queue:
                    Dim v As Single = voltsQarray(i)
                    'Find the distance along the x axis:
                    x = Origin.X + CInt(i * xAxisLength / 40)
                    'find the height of the data point on the Y axis:
    
                    y = Origin.Y + CInt(v * yAxisLength / maxVolts)
                    'Put the point in the array
                    DataPoints(i) = New Point(x, y)
    
                Next
                'Draw the waveform:        
                e.Graphics.DrawCurve(Pens.Green, DataPoints)
    
            End If

    Btw, after placing all the code into the program, this is what i observe [ please see attached image ] Hmm.. its still a straight line though but it is varying quantity against time. So i believe its correct ?
    Attached Images Attached Images  

  6. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: [RESOLVED] Converting voltage level into graphical display

    Quote Originally Posted by catherine0136 View Post
    Thanks for helping ! =)
    Am i right to place the VoltsQ.Count>2 as follows, please correct me if i'm wrong.
    That should work, but it would be neatest to put it after drawing the axes. That way they will still show when there is no signal. It must come before you define voltsQarray.

    Btw, after placing all the code into the program, this is what i observe [ please see attached image ] Hmm.. its still a straight line though but it is varying quantity against time. So i believe its correct ?
    It's not what I would expect if everything is working properly. There might be something wrong in the code, but you should try to eliminate other possibilities. What happens when you change the light on the solar cell? What happens to the line when you disconnect the solar cell or the RS232 interface? And what happens when you type a different value in the textbox?

    BB

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    Code:
    It's not what I would expect if everything is working properly. There might be something wrong in the code, but you should try to eliminate other possibilities. What happens when you change the light on the solar cell? What happens to the line when you disconnect the solar cell or the RS232 interface? And what happens when you type a different value in the textbox?

    Originally, it shows a straight line because it is taking the voltage from the "Average Voltage" textbox.

    I edited so that i'll let the waveform follow the voltage from the "Voltage Level in Volts(V)" textbox, in which the voltages displayed in "Voltage Level in volts varies greatly from 2.30V to slightly above 3.0V, and the waveform will be like this (see attached image - Solar Cell).

    When my hand is place over the solar cell, i am able to observe that the voltage level will decrease and the waveform will also move lower. (See attached image - Solar Cell 1)

    Is it whole waveform correct?

    I'll attached the coding which i insert into my program in the next thread.
    Attached Images Attached Images   

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width