Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * originál původně pro knihovnu adafruit, přepsáno na dispL pro Attila Csergo
- * bitmapa generovana nově pomocí online nástroje BMP to XBM
- */
- #include <U8g2lib.h>
- #include <SPI.h>
- U8G2_SH1106_128X64_NONAME_F_4W_HW_SPI dispL(U8G2_R0,/*cs=*/ 10, /*dc=*/ 9, /* reset=*/ 8);
- // propojeni je: clock=13, data=11, cs=10, dc=9, reset=8);
- U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI dispR(U8G2_R0, /* D0 clock=*/ 3, /* D1 data=*/ 4, /* cs=*/ 7, /* dc=*/ 6, /* reset=*/ 5);
- int analogInputL = A0; // analog input for outside audio source Left channel
- int analogInputR = A1; // analog input for outside audio source Right channel
- int hMeter = 65; // horizontal center for needle animation
- int vMeter = 85; // vertical center for needle animation (outside of dislay limits)
- int rMeter = 80; // length of needle animation or arch of needle travel
- const int sampleWindow = 20; // sample window width in mS (50 mS = 20Hz)
- unsigned int sampleL, sampleR;
- static const unsigned char PROGMEM VUMeter[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x60, 0xC0, 0x00, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x90, 0x20, 0x01, 0x84, 0x04, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x19, 0x10, 0x60, 0xC0,
- 0x01, 0x84, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x25, 0x08, 0x90, 0x00, 0x01, 0x84, 0x04, 0xE0, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x25, 0x08, 0x60, 0xC0, 0x00, 0x04, 0x03, 0x00,
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8E, 0x01, 0x25, 0x08, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x02,
- 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3C, 0x00, 0x00,
- 0x00, 0x00, 0x5C, 0x02, 0x00, 0x00, 0x40, 0x80, 0x00, 0x02, 0x01, 0xE0,
- 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x42, 0x02, 0x00, 0x10, 0x40, 0x80,
- 0x10, 0x02, 0x01, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x9E, 0x01,
- 0x20, 0x10, 0x40, 0x80, 0x10, 0x81, 0x08, 0x00, 0x00, 0x20, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x40, 0x80, 0x10, 0x81, 0x88, 0x20,
- 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x20, 0x40, 0x80,
- 0x10, 0x81, 0x84, 0x20, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x21,
- 0x40, 0x20, 0xF0, 0xFF, 0xFF, 0xC3, 0x47, 0x20, 0x00, 0x00, 0x10, 0x00,
- 0x00, 0x00, 0x00, 0x43, 0x80, 0xE0, 0x0F, 0x00, 0x00, 0xDC, 0x7F, 0x10,
- 0x02, 0x02, 0x10, 0x00, 0x00, 0x7F, 0x00, 0x46, 0x80, 0x1F, 0x00, 0x00,
- 0x00, 0xC0, 0xFF, 0x17, 0x02, 0x01, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x84,
- 0x78, 0x00, 0x20, 0x00, 0x01, 0x00, 0xFE, 0x7F, 0x01, 0x01, 0x10, 0x00,
- 0x00, 0x00, 0xC0, 0x8C, 0x07, 0x00, 0x20, 0x00, 0x01, 0x20, 0x80, 0xFF,
- 0x83, 0x00, 0x10, 0x00, 0x00, 0x00, 0xE0, 0x78, 0x00, 0x02, 0x00, 0x00,
- 0x00, 0x20, 0x00, 0xF8, 0x5F, 0x00, 0x10, 0x00, 0x00, 0x00, 0xE0, 0x0F,
- 0x00, 0x02, 0xDC, 0xE0, 0x06, 0x00, 0x00, 0x80, 0xFF, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x2C, 0x81, 0x09, 0x33, 0x03, 0x00,
- 0xFC, 0x03, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0xC0, 0x0C, 0x30, 0x41,
- 0x09, 0xCA, 0x04, 0x00, 0xE0, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x02,
- 0x00, 0x13, 0xDC, 0x40, 0x06, 0xCA, 0x04, 0x00, 0x00, 0x7F, 0x00, 0x00,
- 0x00, 0x80, 0x01, 0x04, 0x80, 0x13, 0x00, 0x00, 0x00, 0x32, 0x03, 0x00,
- 0x00, 0xFC, 0x01, 0x00, 0x00, 0x60, 0x00, 0x00, 0xC0, 0x0C, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x10, 0x00, 0x30,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x00,
- 0x00, 0x0C, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x02, 0x48, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x05, 0x30,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x40, 0x40, 0x0C, 0x03, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xC0, 0x60,
- 0x0C, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
- 0x00, 0x00, 0x80, 0x31, 0x0C, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x1B, 0x0C, 0x03, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x0E,
- 0x98, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
- 0x00, 0x00, 0x00, 0x04, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, };
- void setup(void) {
- Serial.begin(9600);
- pinMode(analogInputL, INPUT);
- pinMode(analogInputR, INPUT);
- dispL.begin();
- dispR.begin();
- dispL.setBitmapMode(0);
- dispR.setBitmapMode(0);
- }
- void loop(void) {
- unsigned long startMillis = millis(); // start of sample window
- unsigned int SignalMaxL = 0;
- unsigned int SignalMaxR = 0;
- while ( millis() - startMillis < sampleWindow ){
- sampleL = analogRead(analogInputL);
- sampleR = analogRead(analogInputR);
- if (sampleL > SignalMaxL) SignalMaxL = sampleL; // saves just the max L levels
- if (sampleR > SignalMaxR) SignalMaxR = sampleR; // saves just the max R levels
- }
- // Linear mapping of input Max levels
- int MeterValueL = map(SignalMaxL,190,900,-34,40);
- int MeterValueR = map(SignalMaxR,190,900,-34,40);
- // Logar mapping of input Max levels
- MeterValueL = 25.7856*log10(MeterValueL+35)-34;
- MeterValueR = 25.7856*log10(MeterValueR+35)-34;
- // testing different input values indication (-34 ~ 0%; 0 ~ 70%; +12 ~ 100%; +34 ~ +5)
- // MeterValueR = -5;
- int a1 = (hMeter + (sin(MeterValueL / 57.296) * rMeter));
- int a2 = (vMeter - (cos(MeterValueL / 57.296) * rMeter));
- int a3 = (hMeter + (sin(MeterValueR / 57.296) * rMeter));
- int a4 = (vMeter - (cos(MeterValueR / 57.296) * rMeter));
- dispL.clearBuffer();
- dispL.drawXBMP(0,0, 128, 64, VUMeter);
- dispL.drawLine(a1, a2, hMeter, vMeter);
- // dispL.setFont(u8g2_font_ncenB08_tr);
- dispL.sendBuffer();
- dispR.clearBuffer();
- dispR.drawXBMP(0,0, 128, 64, VUMeter);
- dispR.drawLine(a3, a4, hMeter, vMeter);
- // dispR.drawLine(a3, a4, hMeter, vMeter);
- // dispR.setFont(u8g2_font_ncenB08_tr);
- dispR.sendBuffer();
- // testprint key values
- Serial.print("sampleL: "); Serial.print(sampleL); Serial.print(" ");
- // Serial.print("sampleR: "); Serial.print(sampleR); Serial.print(" ");
- Serial.print("SignalMaxL: "); Serial.print(SignalMaxL); Serial.print(" ");
- Serial.print("SignalMaxR: "); Serial.print(SignalMaxR); Serial.print(" ");
- // Serial.print("midstepL: "); Serial.print(midstepL); Serial.print(" ");
- // Serial.print("PeaktoPeakL: "); Serial.print(PeaktoPeakL); Serial.print(" ");
- Serial.print("MeterValueL: "); Serial.print(MeterValueL); Serial.println(" ");
- // Serial.print("a3: "); Serial.print(a3); Serial.print(" ");
- // Serial.print("a4: "); Serial.println(a4);
- // delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement