Last active
May 17, 2018 04:11
-
-
Save ksasao/dbfef5f154b4ad486db4dd194f895fcb to your computer and use it in GitHub Desktop.
[M5Stack] mic input test (speaker noise suppressed) refer to https://gist.github.com/ksasao/485ffbccbf3c47ea9cb814d3484e85e0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <driver/adc.h> | |
#include <M5Stack.h> | |
const int _bufSize = 128; | |
int _buf[_bufSize]; // adc buffer for suppress speaker noise | |
int _pos = 0; | |
int _old = 0; | |
int _count = 0; | |
int _offset = 0; | |
void setup() { | |
Serial.begin(115200); | |
M5.begin(); | |
M5.Lcd.setBrightness(200); | |
adc1_config_width(ADC_WIDTH_12Bit); | |
adc1_config_channel_atten(ADC1_CHANNEL_0,ADC_ATTEN_0db); | |
} | |
void loop() { | |
int v = adc1_get_raw(ADC1_CHANNEL_0); | |
dacWrite(25, 0); // for reduce hum noise | |
int p = _count % _bufSize; | |
_buf[p] = v; | |
// bulk draw to reduce speaker noise | |
if(p == _bufSize - 1){ | |
// calc offset | |
int buf = 0; | |
for(int i=0; i< _bufSize; i++){ | |
buf += _buf[i]; | |
} | |
int offset = buf / _bufSize; | |
// draw | |
for(int i=0; i< _bufSize; i++){ | |
int current = (_buf[i] - offset)/3 + 120; | |
M5.Lcd.drawLine(_pos, 0, _pos,240, BLACK); | |
M5.Lcd.drawLine(_pos - 1, _old, _pos, current, WHITE); | |
_old = current; | |
_pos = (_pos+1) % 320; | |
} | |
} | |
_count++; | |
M5.update(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment