Advertisement
Guest User

Untitled

a guest
Feb 4th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. /*------------------------------------------------------------
  2. Created by: AdverseDeviant
  3. Version 1.0
  4. ------------------------------------------------------------*/
  5.  
  6. /*------------------------------------------------------------
  7. Variables
  8. ------------------------------------------------------------*/
  9. int analogPin = 5; // pin for msgeq7 input
  10. int strobePin = 13; // msgeq7 strobe pin for cycling through channels
  11. int resetPin = 12; // reset pin of the msgeq7
  12. int spectrumValue = 0; // current spectrum value
  13. int highLowDelay = 0; // delay of resetting msgeq7
  14. int strobeDelay_USec = 15; // delay to settle input recording in microseconds
  15. int numberOfChannels = 7; // number of channels in
  16. int divider = 100;
  17. int multiplier = 1;
  18.  
  19. int multiBlack[4] = {2,3,4,5};
  20. int multiRed[4] = {6,7,8,9};
  21.  
  22. int muxChannel[9][4]={
  23. {0,0,0,0}, //channel 0
  24. {1,0,0,0}, //channel 1
  25. {0,1,0,0}, //channel 2
  26. {1,1,0,0}, //channel 3
  27. {0,0,1,0}, //channel 4
  28. {1,0,1,0}, //channel 5
  29. {0,1,1,0}, //channel 6
  30. {1,1,1,0}, //channel 7
  31. {0,0,0,1}, //channel 8
  32. };
  33.  
  34. /*------------------------------------------------------------
  35. Setup Method. Initializes all pins
  36. ------------------------------------------------------------*/
  37. void setup() {
  38. // open usb serial port
  39. Serial.begin(9600);
  40.  
  41. // turn on pins for msgeq7
  42. pinMode(analogPin, INPUT);
  43. pinMode(strobePin, OUTPUT);
  44. pinMode(resetPin, OUTPUT);
  45.  
  46. for(int i=0;i<8;i++) {
  47. pinMode(i+2,OUTPUT);
  48. }
  49.  
  50. analogReference(DEFAULT);
  51.  
  52. // reset msgeq7
  53. digitalWrite(resetPin, LOW);
  54. digitalWrite(strobePin, HIGH);
  55. } // void setup()
  56.  
  57.  
  58. /*------------------------------------------------------------
  59. Loop method. Resets msgeq7 and captures value of the
  60. 7 channels on the msgeq7.
  61. ------------------------------------------------------------*/
  62. void loop()
  63. {
  64. digitalWrite(resetPin, HIGH);
  65. delay(highLowDelay);
  66. digitalWrite(resetPin, LOW);
  67.  
  68. for (int i=0; i<numberOfChannels;i++) {
  69. // start reading channel by changing strobe to low
  70. digitalWrite(strobePin, LOW);
  71. // allows input to settle to get accurate reading
  72. delayMicroseconds(strobeDelay_USec);
  73. // read value of current pin from msgeq7
  74. spectrumValue = analogRead(analogPin);
  75.  
  76. // print out value to serial monitor
  77. Serial.print(spectrumValue);
  78. Serial.print(" ");
  79.  
  80. for(int j=0;j<4;j++) {
  81. digitalWrite(multiBlack[j], muxChannel[i][j]);
  82. } // for(int j=0;j<4;j++)
  83.  
  84. for(int n=1+multiplier;n<10+multiplier;n++) {
  85. for(int k=0;k<n-multiplier;k++) {
  86. if(spectrumValue > divider*n) {
  87. for(int m=0;m<4;m++) {
  88. digitalWrite(multiRed[m], muxChannel[k][m]);
  89. } // for(int m=0;m<4;m++)u
  90. } // if(spectrumValue[i] > 30*n)
  91. } // for(int k=0;k<n;k++)
  92. } // for(int n=1;n<10;n++)
  93.  
  94. // strobe pin high the low to go to next channel on msgeq7
  95. digitalWrite(strobePin, HIGH);
  96.  
  97. } // for (int i = 0; i < numberOfChannels; i++)
  98. Serial.println();
  99.  
  100. } // void loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement