Skip to content

Instantly share code, notes, and snippets.

@CelliesProjects
Last active October 24, 2019 11:12
Show Gist options
  • Select an option

  • Save CelliesProjects/93b2f6bc69faaf1d3c18f360a7a9af52 to your computer and use it in GitHub Desktop.

Select an option

Save CelliesProjects/93b2f6bc69faaf1d3c18f360a7a9af52 to your computer and use it in GitHub Desktop.
Super Simple Sampler for M5Stack-Fire board. Open in Arduino IDE.
/* A super simple sampler for the M5Stack-Fire board */
//#include <TFT_eSPI.h>
#include <M5Display.h> // This library is a lot faster! But also a lot larger.
#define speaker 25
#define microphone 34
#define numberOfBits 8
#define channel 0
#define graphWidth 320
#define graphHeight 120
#define backlight 32
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite img = TFT_eSprite(&tft);
void setup() {
pinMode( microphone, INPUT );
//set pwm on backlight
ledcAttachPin( backlight, 0);
ledcSetup( 0, 1300, 16 );
ledcWrite( 0, 0xFFFF / 16 ); //dimming the backlight will produce more base noise
dacWrite( speaker, 0);
tft.init();
tft.setRotation(1);
tft.fillScreen( TFT_BLACK );
tft.setTextSize( 2 );
img.setColorDepth(8);
img.createSprite( graphWidth, graphHeight );
}
uint32_t counter = 0;
int frameRate = 0;
time_t savedTime;
void loop() {
img.fillSprite(TFT_GREEN);
uint16_t previous = map( analogRead( microphone ), 0, 4096, 0, graphHeight );
counter++;
uint16_t amplitude;
for ( uint16_t sample = 1; sample < graphWidth; sample++) {
amplitude = map( analogRead( microphone ), 0, 4096, 0, graphHeight );
img.drawLine( sample - 1, previous, sample, amplitude, ILI9341_RED );
previous = amplitude;
counter++;
}
frameRate++;
if ( savedTime != time(NULL) ) {
savedTime = time(NULL);
tft.setCursor(20, 140);
tft.printf( "%6iHz %4i FPS", counter, frameRate );
counter = 0;
frameRate = 0;
}
img.pushSprite( 0, 0 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment