Advertisement
Guest User

Untitled

a guest
Oct 31st, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 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. delay(1);
  24. digitalWrite(resetPin, LOW);
  25. delay(60);
  26.  
  27. for (int i = 0; i < 7; i++)
  28. {
  29. digitalWrite(strobePin, LOW);
  30. delayMicroseconds(300); // to allow the output to settle
  31. spectrumValue[i] = analogRead(analogPin);
  32.  
  33. // comment out/remove the serial stuff to go faster
  34. // - its just here for show
  35. if (spectrumValue[i] < 10)
  36. {
  37. Serial.print(" ");
  38. Serial.print(spectrumValue[i]);
  39. }
  40. else if (spectrumValue[i] < 100 )
  41. {
  42. Serial.print(" ");
  43. Serial.print(spectrumValue[i]);
  44. }
  45. else
  46. {
  47. Serial.print(" ");
  48. Serial.print(spectrumValue[i]);
  49. }
  50.  
  51. digitalWrite(strobePin, HIGH);
  52. }
  53. Serial.println();
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement