Arduino Code??
here is the code:
const int analogPin = 0; // the pin that the potentiometer is attached to
const int ledCount = 7; // the number of LEDs in the bar graph
int ledPins[] = {
7,6,5,4,3,2,1 // Here we have the number of LEDs to use in the BarGraph
};
void setup() {
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}}
void loop() {
//This is the code to light up LED's
int sensorReading = analogRead(analogPin);
int ledLevel = map(sensorReading, 500, 1023, 0, ledCount);
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}
else {
digitalWrite(ledPins[thisLed], LOW);
} }}






























Visit Our Store »
Go Pro Today »




The code seems fine.
I would add serial debugging
(in void setup, add Serial.begin(9600); )
(in void loop, add
Serial.print("Analog:");
Serial.println("sensorReading"); //show the input value
Serial.print("value:");
Serial.println("ledLevel"); //show the intended level
delay(1000); //so it doesn't spam the serial too often
Serial.print("output:");
and in the if
Serial.print("o"); // led should light, put a circle
and in the else
Serial.print("x"); //led should be off, put an x
after the end of the else
Serial.println();
Lastly, double check your wiring is connected to the correct pins!
Any time a company is producing a new product or app they go through a testing phase. They bring in people from within and out of the company to try the product out report there findings. You can do the same thing by enlisting the help of your parents.