Advertisement
Guest User

Untitled

a guest
Jan 10th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. int analogPin = 0; // read from multiplexer using analog input 0
  2. int strobePin = 2; // strobe is attached to digital pin 2
  3. int resetPin = 3; // reset is attached to digital pin 3
  4. int spectrumValue[7]; // to hold a2d values
  5.  
  6. void setup()
  7. {
  8.  Serial.begin(9600);
  9.  pinMode(analogPin, INPUT);
  10.  pinMode(strobePin, OUTPUT);
  11.  pinMode(resetPin, OUTPUT);
  12.  analogReference(DEFAULT);
  13.  
  14.  digitalWrite(resetPin, LOW);
  15.  digitalWrite(strobePin, HIGH);
  16.  
  17.  Serial.println("MSGEQ7 test by J Skoba");
  18. }
  19.  
  20. void loop()
  21. {
  22.  digitalWrite(resetPin, HIGH);
  23.  digitalWrite(resetPin, LOW);
  24.  
  25.  for (int i = 0; i < 7; i++)
  26.  {
  27.  digitalWrite(strobePin, LOW);
  28.  delayMicroseconds(30); // to allow the output to settle
  29.  spectrumValue[i] = analogRead(analogPin);
  30.  
  31.  // comment out/remove the serial stuff to go faster
  32.  // - its just here for show
  33.  if (spectrumValue[i] < 10)
  34.  {
  35.  Serial.print(" ");
  36.  Serial.print(spectrumValue[i]);
  37.  }
  38.  else if (spectrumValue[i] < 100 )
  39.  {
  40.  Serial.print(" ");
  41.  Serial.print(spectrumValue[i]);
  42.  }
  43.  else
  44.  {
  45.  Serial.print(" ");
  46.  Serial.print(spectrumValue[i]);
  47.  }
  48.  
  49.  digitalWrite(strobePin, HIGH);
  50.  }
  51.  Serial.println();
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement