Advertisement
Guest User

Untitled

a guest
May 16th, 2015
120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <openGLCD.h>
  2.  
  3. int vuMeterBar[] = {8, 15, 22, 29, 36, 43, 50, 57, 64, 71, 78, 85, 92, 99, 106, 113, 120};
  4. float dBAudio;
  5. float newZero = 512;
  6. int dbPerBar = 3;
  7. float currADC;
  8.  
  9. void setup()
  10. {
  11.   GLCD.Init();
  12.  
  13.   GLCD.SelectFont(Wendy3x5);
  14.  
  15.   //GLCD.DrawLine(0, 11, 128, 11);
  16.   //GLCD.DrawLine(7, 12, 7, 30);
  17.   //GLCD.DrawLine(0, 31, 128, 31);
  18. }
  19.  
  20. void loop()
  21. {
  22.   GLCD.GotoXY(2, 13);
  23.   GLCD.print("L");
  24.   GLCD.GotoXY(2, 27);
  25.   GLCD.print("R");
  26.  
  27.   getPPMsample();
  28.  
  29.   for (int bar = 0; bar < 17; bar++)
  30.   {
  31.     if (abs(dBAudio) >= (bar * dbPerBar) + 0.1)
  32.     {
  33.       GLCD.FillRect(vuMeterBar[bar], 14, 6, 3);   // left
  34.       //GLCD.FillRect(vuMeterBar[bar], 28, 6, 3); // right
  35.     }
  36.   }
  37.  
  38.   for (int i = 1; i <= 17; i ++)
  39.   {
  40.     if (currADC >= 60 * i)
  41.     {
  42.       GLCD.FillRect(vuMeterBar[i - 1], 28, 6, 3); // right
  43.     }
  44.   }
  45.  
  46.   GLCD.GotoXY(2, 45);
  47.   GLCD.print(dBAudio);
  48.   GLCD.GotoXY(2, 52);
  49.   GLCD.print(currADC);  
  50.  
  51.   delay(100);
  52.   GLCD.ClearScreen();
  53. }
  54.  
  55.  
  56. void getPPMsample()
  57. {
  58.   float maxAudio = 0;
  59.   float rawAudio;
  60.   for (int sample = 0; sample < 48; sample++)
  61.   {
  62.     rawAudio = analogRead(A1);  
  63.     if (rawAudio > maxAudio)
  64.       maxAudio = rawAudio;
  65.   }
  66.   currADC = maxAudio;
  67.   dBAudio = 20 * log10 (abs(maxAudio - newZero) / newZero);
  68. }
Advertisement
RAW Paste Data Copied
Advertisement