Guest User

MSGEQ7 blinking lights code

a guest
Apr 26th, 2014
177
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int analogPin = 0;
  2. int strobePin = 2;
  3. int resetPin = 4;
  4. int spectrumValue[7];
  5.  
  6. int filterValue = 170;
  7.  
  8. int ledPinR = 9;
  9. int ledPinG = 10;
  10. int ledPinB = 11;
  11.  
  12. void setup()
  13. {
  14. Serial.begin(9600);
  15. pinMode(analogPin, INPUT);
  16. pinMode(strobePin, OUTPUT);
  17. pinMode(resetPin, OUTPUT);
  18.  
  19. analogReference(DEFAULT);
  20.  
  21. digitalWrite(resetPin, LOW);
  22. digitalWrite(strobePin, HIGH);
  23. }
  24.  
  25. void loop()
  26. {
  27. digitalWrite(resetPin, HIGH);
  28. digitalWrite(resetPin, LOW);
  29.  
  30. for (int i = 0; i < 7; i++)
  31. {
  32. digitalWrite(strobePin, LOW);
  33. delayMicroseconds(45);
  34.  
  35. spectrumValue[i] = analogRead(analogPin);
  36.  
  37. spectrumValue[i] = constrain(spectrumValue[i], filterValue, 1023);
  38.  
  39. spectrumValue[i] = map(spectrumValue[i], filterValue, 1023, 0, 255);
  40.  
  41. Serial.print(spectrumValue[i]);
  42. Serial.print(" ");
  43. digitalWrite(strobePin, HIGH);
  44. }
  45.  
  46. Serial.println();
  47.  
  48. analogWrite(ledPinR, spectrumValue[1]);
  49. analogWrite(ledPinG, spectrumValue[4]);
  50. analogWrite(ledPinB, spectrumValue[6]);
  51. }
RAW Paste Data