Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Serial volume control with 10x LED array as volume indicator
- * to show the current state of the volume progressivley.
- *
- * Circuit:
- * parts: 10x 5MM LED's
- * 10x 220k Ohm resistors
- * 1x potentiometer
- *
- * Simply wire each LED to its own digital pin with a resistor between the
- * arduino board and the LED. You can use any digital pins you want
- * (I had to end up using odd ordered pins due to a weird dimming
- * issue with some LEDs).
- *
- * The potentiometer just requires a 5V, GND, and analog pin.
- * Run the 5v into one of the outer legs of the potentiometer,
- * and the GND to the opposite outer leg. Now plug an analog pin from the
- * arduino into the center pin of the potentiometer. Pretty simple, that
- * makes up the 2 circuits used.
- *
- *
- * Version 1.1
- * Name: Tomm Smith
- * Contact: thims (@irc.allshells.net), root DOT packet AT gmail DOT com
- * Date: 20090514
- */
- int leds[] = {11, 10, 9, 8, 7, 6, 5, 12, 3, 2}; // LED array
- int num_leds = 10; // number of LEDs
- int pot = 4; // pin of the potentiometer
- int value;
- int cycles[11][10] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
- {1, 1, 0, 0, 0, 0, 0, 0, 0, 0},
- {1, 1, 1, 0, 0, 0, 0, 0, 0, 0},
- {1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
- {1, 1, 1, 1, 1, 0, 0, 0, 0, 0},
- {1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
- {1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
- {1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
- {1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
- {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}};
- void setup()
- {
- int i;
- for (i=0; i < num_leds; i++) {
- pinMode(leds[i], OUTPUT);
- }
- pinMode(pot, INPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- value = analogRead(pot);
- Serial.println(value);
- int cycle_on = 0;
- if (value > 0) {
- cycle_on = 1;
- }
- if (value > 100) {
- cycle_on = 2;
- }
- if (value > 200) {
- cycle_on = 3;
- }
- if (value > 300) {
- cycle_on = 4;
- }
- if (value > 400) {
- cycle_on = 5;
- }
- if (value > 500) {
- cycle_on = 6;
- }
- if (value > 600) {
- cycle_on = 7;
- }
- if (value > 700) {
- cycle_on = 8;
- }
- if (value > 800) {
- cycle_on = 9;
- }
- if (value > 900) {
- cycle_on = 10;
- }
- int i;
- for (i=0; i < 10; i++) {
- digitalWrite(leds[i], cycles[cycle_on][i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement