Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <openGLCD.h>
- int vuMeterBar[] = {8, 15, 22, 29, 36, 43, 50, 57, 64, 71, 78, 85, 92, 99, 106, 113, 120};
- float dBAudio;
- float newZero = 512;
- int dbPerBar = 3;
- float currADC;
- void setup()
- {
- GLCD.Init();
- GLCD.SelectFont(Wendy3x5);
- //GLCD.DrawLine(0, 11, 128, 11);
- //GLCD.DrawLine(7, 12, 7, 30);
- //GLCD.DrawLine(0, 31, 128, 31);
- }
- void loop()
- {
- GLCD.GotoXY(2, 13);
- GLCD.print("L");
- GLCD.GotoXY(2, 27);
- GLCD.print("R");
- getPPMsample();
- for (int bar = 0; bar < 17; bar++)
- {
- if (abs(dBAudio) >= (bar * dbPerBar) + 0.1)
- {
- GLCD.FillRect(vuMeterBar[bar], 14, 6, 3); // left
- //GLCD.FillRect(vuMeterBar[bar], 28, 6, 3); // right
- }
- }
- for (int i = 1; i <= 17; i ++)
- {
- if (currADC >= 60 * i)
- {
- GLCD.FillRect(vuMeterBar[i - 1], 28, 6, 3); // right
- }
- }
- GLCD.GotoXY(2, 45);
- GLCD.print(dBAudio);
- GLCD.GotoXY(2, 52);
- GLCD.print(currADC);
- delay(100);
- GLCD.ClearScreen();
- }
- void getPPMsample()
- {
- float maxAudio = 0;
- float rawAudio;
- for (int sample = 0; sample < 48; sample++)
- {
- rawAudio = analogRead(A1);
- if (rawAudio > maxAudio)
- maxAudio = rawAudio;
- }
- currADC = maxAudio;
- dBAudio = 20 * log10 (abs(maxAudio - newZero) / newZero);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement