Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

VU meter Arduino

By: arnarg on Jan 17th, 2013  |  syntax: C  |  size: 0.59 KB  |  views: 184  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. int current;
  2. int highest = 350;
  3. int latchPin = 8;
  4. int clockPin = 12;
  5. int dataPin = 11;
  6. int volume[9] = {0b00000000, 0b00000001, 0b00000011, 0b00000111,
  7.                  0b00001111, 0b00011111, 0b00111111, 0b01111111,
  8.                  0b11111111};
  9.                  
  10. void setup() {
  11.   pinMode(latchPin, OUTPUT);
  12.   pinMode(clockPin, OUTPUT);
  13.   pinMode(dataPin, OUTPUT);
  14.   Serial.begin(9600);
  15. }
  16.  
  17. void loop() {
  18.   current = map(analogRead(A0), 0, highest, 0, 9);
  19.   digitalWrite(latchPin, LOW);
  20.   shiftOut(dataPin, clockPin, LSBFIRST, volume[current]);  
  21.   digitalWrite(latchPin, HIGH);
  22. }