Go Down

Topic: Help reading PWM on analog input (Read 1 time) previous topic - next topic

SXRguyinMA

Hi guys! I have a friend who asked me to make him an LED HDD meter for his PC. It consists of 6 bi-color LED's. Right now I modified the bar graph code example to work how I want. At the start, all the green LED's are lit. As the pot gets turned, it turns off a green LED and turns on a red one at the same time.

What I want to to is make it so it will read the input from the motherboard header for the HDD LED and scale the LED's accordingly. I.E. - the more HDD activity the more green LED's will go out and red ones go on, kinda like a VU meter.

Here's the code I have now, I'm just not sure where to go from here.

Code: [Select]
const int sensePin = A0;
const int redledCount = 6;
const int grnledCount = 6;
int redledPins[] = {
  1, 2, 3, 4, 5, 6 };
int grnledPins[] = {
  7, 8, 9, 10, 11, 12 };

void setup() {
  for (int thisredLed = 0; thisredLed < redledCount; thisredLed++) {
    pinMode(redledPins[thisredLed], OUTPUT); }
  for (int thisgrnLed = 0; thisgrnLed < grnledCount; thisgrnLed++) {
    pinMode(grnledPins[thisgrnLed], OUTPUT); }
}

void loop() {
  int sensorReading = analogRead(sensePin);
  int redledLevel = map(sensorReading, 0, 1023, 0, redledCount);
  for (int thisredLed = 0; thisredLed < redledCount; thisredLed++) {
    if (thisredLed < redledLevel) {
      digitalWrite(redledPins[thisredLed], LOW);
    }
    else {
      digitalWrite(redledPins[thisredLed], HIGH);
    }
  }
  int grnledLevel = map(sensorReading, 0, 1023, 0, grnledCount);
  for (int thisgrnLed = 0; thisgrnLed < grnledCount; thisgrnLed++) {
    if (thisgrnLed < grnledLevel) {
      digitalWrite(grnledPins[thisgrnLed], LOW);
    }
    else {
      digitalWrite(grnledPins[thisgrnLed], HIGH);
    }
  }
}


Thanks in advance!

James C4S

Don't use an analog input, because the signal you are looking at is a digital signal.  You'd have to build a small filter circuit to create an analog signal.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

PeterH

I think you need to poll the LED state (on or off) repeatedly. Then you need to derive a number from the current and recent states of the LED. The number would represent the instantaneous 'activity level' of the LED at the current instant which would tell you which red and green LEDs to illuminate.

There are lots of different ways to derive the activity level. For example you could increment a number each time you saw the LED was on and decrement it each time you saw was off. I think you will have to do some trial and error to see what level of activity you wanted to make each LED go red. For example, you may want to use a logarithmic display so that you get some indication of very low levels of activity but can see show the activity reaching very high levels.
I only provide help via the forum - please do not contact me for private consultancy.

DuaneB

Just use and LM3916 ( or 4 or 5, all similar) , you can use this with a low pass filter - which is simply a resistor and capacitor, no need to an Arduino, just a two dollar chip and some LEDs.

Lots of examples on your favorite video site - this being one of them -

http://www.youtube.com/watch?v=WdodJHrG8EQ&feature=related

it even has a link to the circuit.

Duane.

rcarduino.blogspot.com

SXRguyinMA


Don't use an analog input, because the signal you are looking at is a digital signal.  You'd have to build a small filter circuit to create an analog signal.


So I'll use digital input then.



I think you need to poll the LED state (on or off) repeatedly. Then you need to derive a number from the current and recent states of the LED. The number would represent the instantaneous 'activity level' of the LED at the current instant which would tell you which red and green LEDs to illuminate.

There are lots of different ways to derive the activity level. For example you could increment a number each time you saw the LED was on and decrement it each time you saw was off. I think you will have to do some trial and error to see what level of activity you wanted to make each LED go red. For example, you may want to use a logarithmic display so that you get some indication of very low levels of activity but can see show the activity reaching very high levels.



Any idea how to go about this? I'm decent with beginner programming but this is a tad beyond my skill level.



Just use and LM3916 ( or 4 or 5, all similar) , you can use this with a low pass filter - which is simply a resistor and capacitor, no need to an Arduino, just a two dollar chip and some LEDs.

Lots of examples on your favorite video site - this being one of them -

http://www.youtube.com/watch?v=WdodJHrG8EQ&feature=related

it even has a link to the circuit.

Duane.

rcarduino.blogspot.com


Neat idea but it needs to turn LED's off while others turn on at the same time. Thanks though.

Go Up