Today we take a look at the circuitry of an LED bar graph: 2 different products from Kingbright are used - the DC-7G3HWA (2-color) and the DC-10GWA (1-color).
As an alternative you can use DFRobot FIT0188.
Please follow the circuit of DFRobot and add your 1KOhm resistors to PINs 1-10 from the bar graph to the Arduino and on the opposite side all PINs of the bar graph to ground.
I decided to use a potentiometer (on A0) to see the bars on the graph in the deflection.
The DC-7G3HWA offers 3 green bars and rest of the red bars; the DC-10GWA are purely green bars. My impression is that the green color looks more like yellow.
The sketch reads the values at A0 and increases / decreases the displayed bars.
void loop() {
// read the potentiometer:
int sensorReading = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
// loop over the LED array:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
// if the array element's index is less than ledLevel,
// turn the pin for this element on:
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}else { // turn off all pins higher than the ledLevel:
digitalWrite(ledPins[thisLed], LOW);
}
}
}
I used this source and adapted the code for a 10 segment bar graph.
Comments