Created
June 2, 2012 08:17
-
-
Save a-r-d/2857293 to your computer and use it in GitHub Desktop.
10 LED bar graph controlled by potentiometer- arduino uno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Reads input from a 10,000 ohm potentiometer. | |
Lights up an array of ten LEDs based on how much signal is going through. | |
*/ | |
int numPins = 10; | |
int ledPins[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | |
int ledStates[] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW}; | |
// Analog pin A0 is where you hook the potentiometer up. Or microphone. Or w/e. | |
int sensorPin = A0; | |
int sensorVal = 0; | |
void setup() { | |
// set the digital pin as output: | |
int i = 0; | |
for(i = 0; i < numPins; i++) { | |
pinMode(ledPins[i], OUTPUT); | |
} | |
} | |
void loop(){ | |
sensorVal = analogRead(sensorPin); | |
sensorVal /= 100; // want this to be btn 0-10 | |
// arduino has a 10bit A->D converter. So divide 1024 by 100 gives us ~ 0-10 scale. | |
int i = 0; | |
for(i = 0; i < numPins; i++) { | |
if(sensorVal > i) { | |
ledStates[i] = HIGH; | |
} | |
else { | |
ledStates[i] = LOW; | |
} | |
digitalWrite(ledPins[i], ledStates[i]); | |
} | |
} // End main loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment