Advertisement
Guest User

Untitled

a guest
Sep 9th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.29 KB | None | 0 0
  1.  
  2. #define msg7RESET 11
  3. #define msg7Strobe 12
  4. #define msg7DCout 0
  5. const int LEDpins[7] = {3,5,5,6,9,9,10};    // there are 5 LEDs and 7 freq bands. So, repeat LEDs
  6.  
  7. #define pushButton 2
  8.  
  9. void setup() {
  10.   // initialize the digital pin as an output.
  11.   // Pin 13 has an LED connected on most Arduino boards:
  12.   for (int x=0; x<7; x++) {
  13.       pinMode(LEDpins[x], OUTPUT);
  14.   }
  15.   pinMode(msg7RESET, OUTPUT);
  16.   pinMode(msg7Strobe, OUTPUT);
  17.  
  18.   pinMode(pushButton, INPUT);       // never actually used in this example.
  19.   digitalWrite(pushButton, HIGH);  // Enable internal pull-up
  20. }
  21.  
  22. void loop() {
  23.     digitalWrite(msg7RESET, HIGH);          // reset the MSGEQ7's counter
  24.     delay(5);
  25.     digitalWrite(msg7RESET, LOW);
  26.  
  27.     for (int x = 0; x < 7; x++){
  28.         digitalWrite(msg7Strobe, LOW);      // output each DC value for each freq band
  29.         delayMicroseconds(35); // to allow the output to settle
  30.         int spectrumRead = analogRead(msg7DCout);
  31.  
  32.         int PWMvalue = map(spectrumRead, 0, 1024, 0, 255);  // scale analogRead's value to Write's 255 max
  33.         if (PWMvalue < 50)
  34.             PWMvalue = PWMvalue / 2;        // bit of a noise filter, so the LEDs turn off at low levels
  35.  
  36.         analogWrite(LEDpins[x], PWMvalue);
  37.         digitalWrite(msg7Strobe, HIGH);
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement