Created
June 2, 2012 06:07
-
-
Save a-r-d/2856920 to your computer and use it in GitHub Desktop.
10 LED bar graph code for 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
/* | |
Little code for my 10 LED bar graph. | |
This is just a basic outline for making all the segments light up at diff. intervals. | |
looks OK but not super organized. | |
*/ | |
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}; | |
void setup() { | |
// set the digital pin as output: | |
int i = 0; | |
for(i=0; i < numPins; i++) { | |
pinMode(ledPins[i], OUTPUT); | |
} | |
} | |
long last[] = {0,0,0,0,0,0,0,0,0,0}; | |
long interval[] = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000}; | |
void loop(){ | |
/*** Get current time in milliseconds ***************/ | |
unsigned long currentMils = millis(); | |
/** Blink the first on every 100 ms **/ | |
int i = 0; | |
for( i = 0; i < numPins; i++) { | |
if(currentMils - last[i] > interval[i]) { | |
// if the LED is off turn it on and vice-versa: | |
if (ledStates[i] == LOW) | |
ledStates[i]= HIGH; | |
else | |
ledStates[i] = LOW; | |
// set the LED with the ledState of the variable: | |
digitalWrite(ledPins[i], ledStates[i]); | |
last[i] = currentMils; | |
} | |
}// end pin state for-loop | |
} // End main loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment