Advertisement
Guest User

Arduino 10 LED Progression Bar

a guest
Sep 12th, 2010
997
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.50 KB | None | 0 0
  1. /*
  2.  * Serial volume control with 10x LED array as volume indicator
  3.  * to show the current state of the volume progressivley.
  4.  *
  5.  * Circuit:
  6.  *         parts: 10x 5MM LED's
  7.  *                10x 220k Ohm resistors
  8.  *                 1x potentiometer
  9.  *
  10.  *  Simply wire each LED to its own digital pin with a resistor between the
  11.  *  arduino board and the LED. You can use any digital pins you want
  12.  *  (I had to end up using odd ordered pins due to a weird dimming
  13.  *  issue with some LEDs).
  14.  *
  15.  *  The potentiometer just requires a 5V, GND, and analog pin.
  16.  *  Run the 5v into one of the outer legs of the potentiometer,
  17.  *  and the GND to the opposite outer leg. Now plug an analog pin from the
  18.  *  arduino into the center pin of the potentiometer. Pretty simple, that
  19.  *  makes up the 2 circuits used.
  20.  *
  21.  *
  22.  *  Version 1.1
  23.  *  Name: Tomm Smith
  24.  *  Contact: thims (@irc.allshells.net), root DOT packet AT gmail DOT com
  25.  *  Date: 20090514
  26.  */
  27.  
  28. int leds[] = {11, 10, 9, 8, 7, 6, 5, 12, 3, 2}; // LED array
  29. int num_leds = 10; // number of LEDs
  30. int pot = 4; // pin of the potentiometer
  31. int value;
  32. int cycles[11][10] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  33.                       {1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  34.                       {1, 1, 0, 0, 0, 0, 0, 0, 0, 0},
  35.                       {1, 1, 1, 0, 0, 0, 0, 0, 0, 0},
  36.                       {1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  37.                       {1, 1, 1, 1, 1, 0, 0, 0, 0, 0},
  38.                       {1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
  39.                       {1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
  40.                       {1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
  41.                       {1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  42.                       {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}};
  43.  
  44. void setup()
  45. {
  46.   int i;
  47.  
  48.   for (i=0; i < num_leds; i++) {
  49.     pinMode(leds[i], OUTPUT);
  50.   }
  51.   pinMode(pot, INPUT);
  52.   Serial.begin(9600);
  53. }
  54.  
  55. void loop()
  56. {
  57.   value = analogRead(pot);
  58.   Serial.println(value);
  59.  
  60.   int cycle_on = 0;
  61.  
  62.  
  63.   if (value > 0) {
  64.     cycle_on = 1;
  65.   }
  66.   if (value > 100) {
  67.     cycle_on = 2;
  68.   }
  69.   if (value > 200) {
  70.     cycle_on = 3;
  71.   }
  72.   if (value > 300) {
  73.     cycle_on = 4;
  74.   }
  75.   if (value > 400) {
  76.     cycle_on = 5;
  77.   }
  78.   if (value > 500) {
  79.     cycle_on = 6;
  80.   }
  81.   if (value > 600) {
  82.     cycle_on = 7;
  83.   }
  84.   if (value > 700) {
  85.     cycle_on = 8;
  86.   }
  87.   if (value > 800) {
  88.     cycle_on = 9;
  89.   }
  90.   if (value > 900) {
  91.     cycle_on = 10;
  92.   }
  93.  
  94.  
  95.   int i;
  96.  
  97.   for (i=0; i < 10; i++) {
  98.     digitalWrite(leds[i], cycles[cycle_on][i]);
  99.   }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement