SHARE
TWEET

VU meter Arduino

arnarg Jan 17th, 2013 320 Never
  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. }
RAW Paste Data
Top