5,702,921 members and growing! (21,205 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » General     Intermediate

Analog and LED Meter

By Kent Andersson

VU or Level meter, LED or Analog display
C#, Windows, .NET, Visual Studio, Dev

Posted: 23 Oct 2006
Updated: 1 Dec 2007
Views: 51,695
Bookmarked: 97 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
22 votes for this Article.
Popularity: 5.97 Rating: 4.44 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
1 vote, 4.5%
3
8 votes, 36.4%
4
13 votes, 59.1%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Sample Image - VuMeter_Demo.jpg

Introduction

I've been searching a lot for a easy to use VU meter to use in a simple Audio player/recorder, but I havn't been lucky. I found some samples of LED meters, but not quite what I wanted.

It's good that I'm a bit stubborn, but unfortunatly I'm also a complete beginner in C#, but that is the language I want to learn so I started my little project 2 weeks ago. This is the result.

The Code

I started out from a System.Windows.Forms.UserControl, but I don't know how to get rid of all the proporties that I don't use (please help if you can). (Thank you BruceN) I decided that the size should be calculated from the number of LED:s being used (I started with the LED, and added the analog this weekend), and added proporties for LED size and spacing. The colors is user selectable in three different areas (up to 32 LED:s in each) with different settings for LED on and off so they could have a glow when idle.

BackColor is used for the border round the LED:s.

The LED:s are made up of filled rectangles, with a solid brush, easy to use and didn't take much time to get working, next I added the possibility to enable a PeakHold with selectable Hold time, and then I wanted to have a vertical version also, this solution is quite ugly, but it works ok.

As I wanted to use the LED:s for a VU meter, I wanted both analog and logarithmic scale (Log10) so that came next, and this was a bit tricky for me, but I made it and was very happy with my solution, but then suddenly I got the idea: But I want an old style analog meter, so I started searching, but found nothing (for free anyway), and the meters that had a desent price tag was ugly! I did find some extremly beautiful gauge meters, but almost 700$ is way beond my budget!

So the only way was the hard way, started last week, (on my spare time!) this was fun! I havn't learnt so much in many years, and I'm learning new things every day now, and I did get results!

I got the analog meter running in the weekend, but at a fixed size, and I couldnt make the background transparent, so I wasn't quite satisfied yet (I don't lie if I tell you that I had a lot of trouble getting the math:s together for the analog meter). To solve the background I found the example code in C# Help for a round button, setting a region, and that did the trick, finaly! But it would be nice to be able to have a different size, the TI-66 (I know its old, but it has nostalgic value for me) did some number crunching, and I began to change in the code, suddenly terrified that I hadn't made a backup before the changes, my test application didn't work anymore?!?! what to do, ctrl-z a wonderful key-combination, but when I found the error (I set the size to 0,0 by mistake) I just had to re enter everything again. And now, tonight, I'm quite satisfied with my work, so the next thing is getting MP3 recording to work (don't now how yet, but I'm leaning towards BASS) so I could get some practical use of my wonderful meters.

Using the code

I've done my best to make it easy to use, but I'm a bit annoyed of all the proporties that is not in use, that I wan't to get rid of. but anyway, here is a small explanation of how to use it.

First, drag the DLL to your Toolbox, then you could place a VuMeter on your Form.

To set it up the way you wan't it go to the proporties and look in Analog Meter, VU Meter and VU Meter - Colors. BackColor, Font and Size is also in use.

Analog Meter proporties:

Analog Meter - True or False (default False) tells the meter if it should be LED or analog.

DialBackGround, is the color of the dial. DialTextNegativ, Positive and Zero is what color the text above the dial should have dependant on the value (text uses DialTextPositive).

NeedleColor and PeakNeedleColor is of course the color of the needle and peak indicator.

ShowDial Only - True or False (default False) removes the background around the meterdial so you could place it above some nice meter image or anything else you want.

ShowTextInDial - True or False (default True) tells if the text (values) should be shown in the dial, and the values is placed in TextInDial (a String array) and all the values are distributed in the upper part of the dial.

VuText is a text you could have in the dial (Default VU)

In the VU Meter category you find more options:

Led1(2 and 3)Count number of LED:s in each area (default 6, 6 and 4) max value 32 for each area and minimum 0 (but there must be 1 LED in one of the areas) this is also the number of indicators that are shown in the analog dial.

LedSize (default 6;14) size of each led in pixels, same size is used in the analog meter so to get smaller "ticks" change the size here.

LedSpace (default 3) pixels between LED:s and also width of border around LED:s

Level input level to meter determines number of LED:s to light or position of needle in analog view.

LevelMax (default 65535) Max input value also the level that turns on all the LED:s.

MeterScale Analog or Log10 (default Log10) what math to use when calculating Level.

PeakHold True or False (default True) if you should use PeakIndicator

Peakms (default 1000) number of ms to hold peak value (max 10000)

VerticalBar True or False (default False) if you want a vertical LED-bar instead.

VU Meter - Colors, you figure it out for yourself ;)

Added October 25th:

Section Analog

UseLedLight True or False (default False) if the Led:s in the dial should follow the needle

ShowLedPeak True or False (default False) if the Peak indicator should be shown in Led also

If you like this analog and digital meter, please give comments and feedback on the code and the component. If anyone out there could give me some help in how to record to a MP3 file from C#, I'd be happy to get some help.

History

  • October 22th, 2006 - article submitted.
  • October 24th, 2006 - updated thanks to BruceN.
  • October 25th, 2006 - added extra features (Leds in Analog dialbar lights up).
  • February 21th, 2007 - added proporties-AssemblyInfo.cs to source code.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Kent Andersson



Location: Sweden Sweden

Other popular Miscellaneous articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 21 of 21 (Total in Forum: 21) (Refresh)FirstPrevNext
GeneralThank you!memberavarone11:25 14 Nov '08  
GeneralDo you have any info??memberejoee15:20 21 Aug '08  
Generalinput value less than LevelMax scalemembermartinsvicente11:17 21 Jul '08  
GeneralLicense of ussagememberchuchuk12:02 28 Mar '08  
GeneralMissing filesmembershark15466:41 5 Dec '07  
QuestionMissing VU-Meter.wmfmemberallengoodwin9:59 12 Mar '07  
AnswerRe: Missing VU-Meter.wmfmemberKent Andersson11:15 12 Mar '07  
AnswerRe: Missing VU-Meter.wmfmemberKent Andersson3:07 1 Dec '07  
Generalmissing AssemblyInfo.csmemberMr.X9:38 21 Feb '07  
GeneralRe: missing AssemblyInfo.csmemberKent Andersson10:05 21 Feb '07  
GeneralRe: missing AssemblyInfo.csmembervaibhav_patel2:04 5 Mar '07  
GeneralRe: missing AssemblyInfo.csmemberKent Andersson3:08 1 Dec '07  
Questionvu metermembergumigyuri22:31 30 Oct '06  
AnswerRe: vu metermemberKent Andersson22:39 30 Oct '06  
GeneralRe: vu metermemberSeve6513:45 21 Feb '07  
GeneralRe: vu metermemberKent Andersson21:52 21 Feb '07  
GeneralRemoving PropertiesmemberBruceN14:35 23 Oct '06  
GeneralRe: Removing PropertiesmemberKent Andersson20:47 23 Oct '06  
GeneralRe: Removing PropertiesmemberKent Andersson7:15 24 Oct '06  
GeneralRe: Removing PropertiesmemberBruceN11:13 24 Oct '06  
GeneralRe: Removing PropertiesmemberGreg Cadmes13:09 30 Oct '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 1 Dec 2007
Editor:
Copyright 2006 by Kent Andersson
Everything else Copyright © CodeProject, 1999-2008
Web16 | Advertise on the Code Project