Teensy Microphone Module

By the way, I'll be putting them up for sale on Tindie as soon as I get a batch made. When they're available, I'll post a shameless plug. For sure, in time for the holidays and they'll make a wonderful stocking stuffer for that special Teensy hacker on your list!

Thanks to all the Alpha and Beta version testers and special thanks to Davidelvig for his testing and encouragement! They will be the Beta unit size (0.6" wide by 1.0" tall) but with a new jumper pad added to defeat the Auto Gain Control function of the MAX9814. A quick solder blob will select the gain (default max at 60dB, but can be set to 50dB or 40dB) and another to defeat ACG, if desired.
 
Leon's mic will be biased to 0.6v.
That's perfect for the Teensy Audio Library's adc input object
My guess is that it will get a reasonable signal from mosquito wings within a meter in a very quiet room.
I'd test it, but I can't capture the mosquitos without making them permanently quiet.

So biasing voltage depends on the type of microphone what we are using right? In leon's board using 102-1721-ND. Is this 0.6V specific for Teensy,MAX9841 or Microphone?
 
I would suggest not filtering the mosquito buzzing sound until you've capture sufficient audio samples to confirm that you have all the interesting frequencies. Don't trust your ears - sample fast and then analyze the frequency content. I'll bet the Teensy 3.2 is fast enough that you can run the ACD input into a software filter to either filter out or in the interesting signals.
.

Here Leon,
I have contacts with Cornell University Entomology unit. They have send me some of the mosquito recordings from research laboratories. Actually there capturing wing beat sound by trapping mosquito's inside a cage. By using Doppler optical or ultrasonic measurements of reflections off of the wings. After there recording sounds as MP3 and then only analyze.
So i have analyzed the recordings from MATLAB using fft mechanisms. Then identified Fundamental and other prominent harmonics. According to that Fundamental + harmonics range is between 300Hz - 3000HZ.That's why i have decided the analog filtering part.
Since i'm making real time application to avoid other frequencies i though to use both Analog and Software DSP's.
So leon is that ok to sample from 44.1KHz of teensy 3.2??? because Aliasing can be occur right?

Also another thing if im using software filters i though to use IIR filters. I have read somewhere IIR require Floating point unit which has compatibility with Teensy 3.6

Digikey's website is down right now so I can't look up pin-compatible replacements for the CUI electret mic element. From the MAX9814 datasheet: "An internal microphone bias voltage generator provides a 2V bias that is suitable for most electret condenser microphones."
.

I would really great full if you guys can help me on this since you people are professionals on this stuff.
 
By the way, I'll be putting them up for sale on Tindie as soon as I get a batch made. When they're available, I'll post a shameless plug. For sure, in time for the holidays and they'll make a wonderful stocking stuffer for that special Teensy hacker on your list!

Thanks to all the Alpha and Beta version testers and special thanks to Davidelvig for his testing and encouragement! They will be the Beta unit size (0.6" wide by 1.0" tall) but with a new jumper pad added to defeat the Auto Gain Control function of the MAX9814. A quick solder blob will select the gain (default max at 60dB, but can be set to 50dB or 40dB) and another to defeat ACG, if desired.

Try to release this board as soon as possible(Within this month). Waiting to use that board.
 
Boards on order! I'm using PCBway for the first time. Costs seem reasonable so now we'll see what their production and shipping times are like. I'll update again when I have some concrete dates.
 
Here Leon,
I have contacts with Cornell University Entomology unit. They have send me some of the mosquito recordings from research laboratories. Actually there capturing wing beat sound by trapping mosquito's inside a cage. By using Doppler optical or ultrasonic measurements of reflections off of the wings. After there recording sounds as MP3 and then only analyze.
So i have analyzed the recordings from MATLAB using fft mechanisms. Then identified Fundamental and other prominent harmonics. According to that Fundamental + harmonics range is between 300Hz - 3000HZ.That's why i have decided the analog filtering part.
Since i'm making real time application to avoid other frequencies i though to use both Analog and Software DSP's.
So leon is that ok to sample from 44.1KHz of teensy 3.2??? because Aliasing can be occur right?

Also another thing if im using software filters i though to use IIR filters. I have read somewhere IIR require Floating point unit which has compatibility with Teensy 3.6



I would really great full if you guys can help me on this since you people are professionals on this stuff.

I'm assuming that you're trying to create some type of portable analysis system using a Teensy and are keen on making it small, battery powered and need to make decisions based on what sounds you hear. Otherwise a good laptop plus a instrumentation microphone and Mathlab would work better for laboratory experiments. Putting that aside...

44.1KHz sample rate should be plenty fine for a 3KHz maximum frequency of interest. That's sampling 7X faster than the Nyquist frequency.

It sounds like you're confident in the 300-3000Hz frequency band so that's good. The microphone module already has a low pass filter around 12KHz (small filter on the output that I added), so I'm not sure I would add more analog filters.

Teensy 3.2 have a ton of horsepower for a signal audio stream. If you're ultimately going to be listening to three microphones and trying to triangulate the location of a mosquito in an enclosure, you probably should jump up to a 3.6. I haven't played with one myself but understand that they are the ticket for higher end processing applications.

I can suggest a path I would take:
a) Take the microphone and Teensy 3.2 and set-it up to stream audio to the USB port (un-filtered). Put a nice full-range speaker in an enclosure similar to what you might use for a live mosquito, with the microphone located where you would want it to be to listen to the sounds. Play the recorded mosquito sounds through that speaker and confirm using Audacity or Mathlab that the FFT you get through the mic+Teensy>USB is close to the original FFT from the source audio file. There will be differences due to your speaker+enclosure+microphone but should simulate having a live bug-in-a-box. The test setup should get you familiar with the Teensy, the microphone and any compromises in the system. By varying the speaker volume, you can see how the system responses as the mosquito sounds get smaller and smaller.

b) Add a high-pass software filter between the ADC object and the USB output in the Audio Library tool and set it around 200-300Hz and rerun a) above. Confirm via FFT analysis in Audacity or Mathlab that it has the impact you'd expect.

c) Remove the high-pass filter and then add a low-pass software filter to the Teensy around 3000-4000Hz and rerun a) above. Confirm that it has the impact you'd expect.

d) Add in both the low-pass and high-pass (or bandpass depending on the filter component you're using) and again confirm it's not impacting the pass band.

e) Play with various volume levels on the speaker playing the mosquito sounds to confirm that the microphone+teensy is working fine.

Now you can put in a real mosquito and feel confident that your audio capture system is working fine.

If you really are trying to triangulate the position of a mosquito in a box with three microphones, you'll need to calibrate each microphone and also measure any phase delays that the software filters are creating and then calibrate your positioning algorithm and then probably deal with dozens of other problems.
 
Teensy 3.2 have a ton of horsepower for a signal audio stream. If you're ultimately going to be listening to three microphones and trying to triangulate the location of a mosquito in an enclosure, you probably should jump up to a 3.6. I haven't played with one myself but understand that they are the ticket for higher end processing applications.
.

The main reason i thought to use Teensy 3.6 is, When doing IIR filtering i saw somewhere IIR is much better on Floating point dsp's. But Teensy 3.2 has no floating point unit. Can you make sure whether what sort of arithmetic unit it has??(32 point fixed point or 16-bit fixed point?)
 
The main reason i thought to use Teensy 3.6 is, When doing IIR filtering i saw somewhere IIR is much better on Floating point dsp's. But Teensy 3.2 has no floating point unit. Can you make sure whether what sort of arithmetic unit it has??(32 point fixed point or 16-bit fixed point?)

I'm not sure - that's probably buried in the MK20DX256VLH7 datasheet somewhere. Otherwise, Wikipedia says: Conceptually the Cortex-M4 is a Cortex-M3 plus DSP instructions, and optional floating-point unit (FPU). If a core contains an FPU, it is known as a Cortex-M4F, otherwise it is a Cortex-M4.

Key features of the Cortex-M4 core are:...
32-bit hardware integer multiply with 32-bit or 64-bit result, signed or unsigned, add or subtract after the multiply.
32-bit hardware integer divide (2-12 cycles).
 
Hi
Seems very nice to me. Are there tests done with longer cable length's from the module to the teensy (aka 1 or 2 meters)

Any compare's done with the https://forum.pjrc.com/threads/40115-Teensy-Hearing-Aid or the mic's on the last page for example the EK-23024 ?
There's off course a huge price differential.

BTW. Anybody experience ordering from the Eu considering customs and shiping?
 
Hi
Seems very nice to me. Are there tests done with longer cable length's from the module to the teensy (aka 1 or 2 meters)

Any compare's done with the https://forum.pjrc.com/threads/40115-Teensy-Hearing-Aid or the mic's on the last page for example the EK-23024 ?
There's off course a huge price differential.

BTW. Anybody experience ordering from the Eu considering customs and shiping?

1) Longer cables - I haven't tested with any longer than 20cm (9") but seems like a good thing to try! I'll use a chunk of shielded headphone cable; shield = GND, Red = 3.3V and White = mic signal. This won't be ideal because noise from the 3.3V will get onto the mic signal, but it'll still be a good test.

2) Knowles EK-23024 - I have not tested using this electrec microphone but the specs look compatible with the MAX9814 amplifier so it should work fine.

3) Shipping to EU - no, I don't have any experience yet but hopefully soon ;)
 
1) Longer cables - I haven't tested with any longer than 20cm (9") but seems like a good thing to try! I'll use a chunk of shielded headphone cable; shield = GND, Red = 3.3V and White = mic signal. This won't be ideal because noise from the 3.3V will get onto the mic signal, but it'll still be a good test.

2) Knowles EK-23024 - I have not tested using this electrec microphone but the specs look compatible with the MAX9814 amplifier so it should work fine.

3) Shipping to EU - no, I don't have any experience yet but hopefully soon ;)

Hi

1) Maybe it's better noise wise to add a cable between the mic and the board if there's no other elec. cabling or known interference. Or is that wishful thinking (the signals will be weaker and added noise will be amplified.)?
This gives also better possibilities to place the mic.

Alain
 
Hi

1) Maybe it's better noise wise to add a cable between the mic and the board if there's no other elec. cabling or known interference. Or is that wishful thinking (the signals will be weaker and added noise will be amplified.)?
This gives also better possibilities to place the mic.

Alain

IMO,the board is exactly what you wanted to separate mic+'preamp' from teensy/ teensy audioboard
 
I agree, WMXZ.

The mic-->amp signal is minuscule, so noise could easily drown out the signal (low s/n ratio). After the board amplifies the signal, it has a fighting chance to traverse a long wire without noticeable noise.

It would be a nice to be able to stick a mic in a physically-small place.
Your design should take into account having amplification very close to a passive mic.
The Neutronned mic board is comparable in size to SparkFun and Adafruit mic boards (but with the correct bias).
 
Last edited:
Wicky21 was asking about sample code using a 240x320 LCD with the 9341 driver. Here is my first pass. The rectangle fill method I use seems slow, so I'll be playing with options to speed it up. If you know of the fastest method to draw filled rectangles, please let me know!!

Code:
//***************************************************
// Spectrum Analyzer using a Teensy 3.2, TJCTM24028-SPI TFT module w/ 9341 driver chip
//  Test microphone is connected to A2
//****************************************************

#define MIC_GAIN  2  // multiplier for the specific mic

#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>


// For the TFT module, these are the default.
#define TFT_DC 9
#define TFT_CS 10

// create the LCD object
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);


// GUItool: begin automatically generated code
AudioInputAnalog         adc1;           //xy=187,227 (default is A2)
AudioAnalyzeFFT1024      fft1024_1;      //xy=401,231
AudioConnection          patchCord1(adc1, fft1024_1);
// GUItool: end automatically generated code



// An array to hold the 16 frequency bands
float level[16];

void setup() {
 
  tft.begin();
  tft.setRotation(3);
  tft.fillScreen(ILI9341_BLACK);
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_WHITE);  tft.setTextSize(2);
  tft.println("Teensy Spectrum Analyzer");
  
  // Audio connections require memory to work.
  AudioMemory(12);

  // Configure the window algorithm to use
  fft1024_1.windowFunction(AudioWindowHanning1024);

}


//*********************************************************************************** LOOP
void loop() {

//****************************************************************************** INPUT
  if (fft1024_1.available()) {
    // each time new FFT data is available, bin it into 16 channels
    // Note- response doesn't seem flat so each is normalized <experimenting!
    // Note- these calculations go very fast!!

    level[0] =  fft1024_1.read(0) * 1.21 * MIC_GAIN;
    level[1] =  fft1024_1.read(1) * 1.18 * MIC_GAIN;
    level[2] =  fft1024_1.read(2, 3) * 1.15 * MIC_GAIN;
    level[3] =  fft1024_1.read(4, 6) * 1.12 * MIC_GAIN;
    level[4] =  fft1024_1.read(7, 10) * 1.09 * MIC_GAIN;
    level[5] =  fft1024_1.read(11, 15) * 1.06 * MIC_GAIN;
    level[6] =  fft1024_1.read(16, 22) * 1.03 * MIC_GAIN;
    level[7] =  fft1024_1.read(23, 32) * 1.00 * MIC_GAIN;
    level[8] =  fft1024_1.read(33, 46) * 0.96 * MIC_GAIN;
    level[9] =  fft1024_1.read(47, 66) * 0.93 * MIC_GAIN;
    level[10] = fft1024_1.read(67, 93) * 0.90 * MIC_GAIN;
    level[11] = fft1024_1.read(94, 131) * 0.87 * MIC_GAIN;
    level[12] = fft1024_1.read(132, 184) * 0.84 * MIC_GAIN;
    level[13] = fft1024_1.read(185, 257) * 0.81 * MIC_GAIN;
    level[14] = fft1024_1.read(258, 359) * 0.78 * MIC_GAIN;
    level[15] = fft1024_1.read(360, 511) * 0.75 * MIC_GAIN;


//****************************************************************************** LCD OUTPUT
    for (byte i = 0; i < 16; i++){   // cycle through the 16 channels

      // response is too slow - if you know of a faster method to draw filled rectangles,
      // please let me know!

      int line1 = level[i] * 200;
      if (line1 > 200){
        line1 = 200;
      }

      tft.fillRect( i*20, 16, 20, 240-line1, ILI9341_BLACK);    //erase old information
      //tft.drawRect( i*20, 240-line1, 20, line1, ILI9341_WHITE);     //paint new bar 

      for (byte j = 1; j < 19; j++){  // draw muliple lines to create the bar
        tft.drawFastVLine( i*20 + j, 240-line1, line1, Wheel565(i * 15 + 60));
      }

    }
  }
}


//*******************************************************************************************/
// Wheel565: standard color look-up routine - Input a value 0 to 255 to get an RGB color value. 
//  NOTE: The colors are a transition Green (0) to Red (85) to Blue (170) back to Green
//  RGB565 format!!
//  R4-R3-R2-R1-R0-G5-G4-G3-G2-G1-G0-B4-B3-B2-B1-B0   Bits
// |-----------|-----------|-----------|-----------|  Bytes
//*******************************************************************************************/
long Wheel565(byte WheelPos) {
  if(WheelPos < 85) {
   return ((((WheelPos * 3) / 8) * 0x0800) + ((63 - ((WheelPos * 3) / 4)) * 0x0020));
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return (((31 - ((WheelPos * 3) / 8)) * 0x0800) + (0 * 0x0020) + (WheelPos * 3 / 8));
  } else {
   WheelPos -= 170;
   return ((((WheelPos * 3) / 4) * 0x0020) + (31 - ((WheelPos * 3) / 8)));
  }
}
 
Last edited:
This code is not working with me. maybe Adafruit ILI9341 configurations were different.

But i have tried with Workshop TFT code which perfectly work(With workshop example). If you can edit you'r code according to attached code. It will work fine

Code:
// Advanced Microcontroller-based Audio Workshop
//
// http://www.pjrc.com/store/audio_tutorial_kit.html
// https://hackaday.io/project/8292-microcontroller-audio-workshop-had-supercon-2015
// 
// Part 3-3: Add a TFT Display

#include <ILI9341_t3.h>
#include <font_Arial.h> // from ILI9341_t3


///////////////////////////////////
// copy the Design Tool code here
///////////////////////////////////
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav1;     //xy=83,216
AudioAnalyzePeak         peak1;          //xy=329,244
AudioAnalyzePeak         peak2;          //xy=331,302
AudioOutputI2S           i2s1;           //xy=337,151
AudioConnection          patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection          patchCord2(playSdWav1, 0, peak1, 0);
AudioConnection          patchCord3(playSdWav1, 1, i2s1, 1);
AudioConnection          patchCord4(playSdWav1, 1, peak2, 0);
AudioControlSGTL5000     sgtl5000_1;     //xy=201,390
// GUItool: end automatically generated code





#define TFT_DC      20
#define TFT_CS      21
#define TFT_RST    255  // 255 = unused, connect to 3.3V
#define TFT_MOSI     7
#define TFT_SCLK    14
#define TFT_MISO    12
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);


// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14

// Use these with the Teensy 3.5 & 3.6 SD card
//#define SDCARD_CS_PIN    BUILTIN_SDCARD
//#define SDCARD_MOSI_PIN  11  // not actually used
//#define SDCARD_SCK_PIN   13  // not actually used

// Use these for the SD+Wiz820 or other adaptors
//#define SDCARD_CS_PIN    4
//#define SDCARD_MOSI_PIN  11
//#define SDCARD_SCK_PIN   13

void setup() {
  Serial.begin(9600);
  delay(500);
  tft.begin();
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_YELLOW);
  tft.setFont(Arial_24);
  //tft.setTextSize(3);
  tft.setCursor(40, 8);
  tft.println("Peak Meter");
  
  AudioMemory(10);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);
  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  delay(1000);
}

elapsedMillis msecs;

void loop() {
  if (playSdWav1.isPlaying() == false) {
    Serial.println("Start playing");
    //playSdWav1.play("SDTEST1.WAV");
    //playSdWav1.play("SDTEST2.WAV");
    playSdWav1.play("SDTEST3.WAV");
    //playSdWav1.play("SDTEST4.WAV");
    delay(10); // wait for library to parse WAV info
  }
  
  if (msecs > 15) {
    if (peak1.available() && peak2.available()) {
      msecs = 0;
      float leftNumber = peak1.read();
      float rightNumber = peak2.read();
      Serial.print(leftNumber);
      Serial.print(", ");
      Serial.print(rightNumber);
      Serial.println();

      // draw the verticle bars
      int height = leftNumber * 240;
      tft.fillRect(60, 280 - height, 40, height, ILI9341_GREEN);
      tft.fillRect(60, 280 - 240, 40, 240 - height, ILI9341_BLACK);
      height = rightNumber * 240;
      tft.fillRect(140, 280 - height, 40, height, ILI9341_GREEN);
      tft.fillRect(140, 280 - 240, 40, 240 - height, ILI9341_BLACK);
      // a smarter approach would redraw only the changed portion...

      // draw numbers underneath each bar
      tft.setFont(Arial_14);
      tft.fillRect(60, 284, 40, 16, ILI9341_BLACK);
      tft.setCursor(60, 284);
      tft.print(leftNumber);
      tft.fillRect(140, 284, 40, 16, ILI9341_BLACK);
      tft.setCursor(140, 284);
      tft.print(rightNumber);
    }
  }
}
 
Wicky21 was asking about sample code using a 240x320 LCD with the 9341 driver. Here is my first pass. The rectangle fill method I use seems slow, so I'll be playing with options to speed it up. If you know of the fastest method to draw filled rectangles, please let me know!!
If you use ILI9341_t3.h, draw time improves from 161 ms to 48 ms with T3.5@120mhz. I believe the SPI clock is set at max (30mhz). there may be other speed options for that T3 library.
https://github.com/PaulStoffregen/ILI9341_t3

for your original 128x160 TFT adafruit display, i was seeing 28 ms draw times on T3.5@120mhz with default SPI clock (15 mhz). if you add tft.setBitrate(30000000); after tft.initR(), draw time is only 14 ms. Caveat: i don't actually have such a display, so I don't know if display will run with SPI clock at 30mhz, but that is the speed measured in the sketch with unconnected SPI.

EDIT: acquired the adafruit 128x160 TFT LCD and confirmed display does work with SPI clock @30mhz
 
Last edited:
If you use ILI9341_t3.h, draw time improves from 161 ms to 48 ms with T3.5@120mhz. I believe the SPI clock is set at max (30mhz). there may be other speed options for that T3 library.

Wow! That is much faster! Thanks for the tip!!
Code:
//***************************************************
// Spectrum Analyzer using a Teensy 3.2, TJCTM24028-SPI TFT module w/ 9341 driver chip
//  Test microphone is connected to A2
//****************************************************

#define MIC_GAIN  2  // multiplier for the specific mic

#include "SPI.h"
#include "ILI9341_t3.h"
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>


// For the TFT module, these are the default.
#define TFT_DC 9
#define TFT_CS 10

// create the LCD object
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);


// GUItool: begin automatically generated code
AudioInputAnalog         adc1;           //xy=187,227 (default is A2)
AudioAnalyzeFFT1024      fft1024_1;      //xy=401,231
AudioConnection          patchCord1(adc1, fft1024_1);
// GUItool: end automatically generated code



// An array to hold the 16 frequency bands
float level[16];

void setup() {
 
  tft.begin();
  tft.setRotation(3);
  tft.fillScreen(ILI9341_BLACK);
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_WHITE);  tft.setTextSize(2);
  tft.println("Teensy Spectrum Analyzer");
  
  // Audio connections require memory to work.
  AudioMemory(12);

  // Configure the window algorithm to use
  fft1024_1.windowFunction(AudioWindowHanning1024);

}


//*********************************************************************************** LOOP
void loop() {

//****************************************************************************** INPUT
  if (fft1024_1.available()) {
    // each time new FFT data is available, bin it into 16 channels
    // Note- response doesn't seem flat so each is normalized <experimenting!
    // Note- these calculations go very fast!!

    level[0] =  fft1024_1.read(0) * 1.21 * MIC_GAIN;
    level[1] =  fft1024_1.read(1) * 1.18 * MIC_GAIN;
    level[2] =  fft1024_1.read(2, 3) * 1.15 * MIC_GAIN;
    level[3] =  fft1024_1.read(4, 6) * 1.12 * MIC_GAIN;
    level[4] =  fft1024_1.read(7, 10) * 1.09 * MIC_GAIN;
    level[5] =  fft1024_1.read(11, 15) * 1.06 * MIC_GAIN;
    level[6] =  fft1024_1.read(16, 22) * 1.03 * MIC_GAIN;
    level[7] =  fft1024_1.read(23, 32) * 1.00 * MIC_GAIN;
    level[8] =  fft1024_1.read(33, 46) * 0.96 * MIC_GAIN;
    level[9] =  fft1024_1.read(47, 66) * 0.93 * MIC_GAIN;
    level[10] = fft1024_1.read(67, 93) * 0.90 * MIC_GAIN;
    level[11] = fft1024_1.read(94, 131) * 0.87 * MIC_GAIN;
    level[12] = fft1024_1.read(132, 184) * 0.84 * MIC_GAIN;
    level[13] = fft1024_1.read(185, 257) * 0.81 * MIC_GAIN;
    level[14] = fft1024_1.read(258, 359) * 0.78 * MIC_GAIN;
    level[15] = fft1024_1.read(360, 511) * 0.75 * MIC_GAIN;


//****************************************************************************** LCD OUTPUT
    for (byte i = 0; i < 16; i++){   // cycle through the 16 channels

      // response is too slow - if you know of a faster method to draw filled rectangles,
      // please let me know!

      int line1 = level[i] * 200;
      if (line1 > 200){
        line1 = 200;
      }

      tft.fillRect( i*20, 16, 20, 240-line1, ILI9341_BLACK);    //erase old information
      //tft.drawRect( i*20, 240-line1, 20, line1, ILI9341_WHITE);     //paint new bar 

      for (byte j = 1; j < 19; j++){  // draw muliple lines to create the bar
        tft.drawFastVLine( i*20 + j, 240-line1, line1, Wheel565(i * 15 + 60));
      }

    }
  }
}


//*******************************************************************************************/
// Wheel565: standard color look-up routine - Input a value 0 to 255 to get an RGB color value. 
//  NOTE: The colors are a transition Green (0) to Red (85) to Blue (170) back to Green
//  RGB565 format!!
//  R4-R3-R2-R1-R0-G5-G4-G3-G2-G1-G0-B4-B3-B2-B1-B0   Bits
// |-----------|-----------|-----------|-----------|  Bytes
//*******************************************************************************************/
long Wheel565(byte WheelPos) {
  if(WheelPos < 85) {
   return ((((WheelPos * 3) / 8) * 0x0800) + ((63 - ((WheelPos * 3) / 4)) * 0x0020));
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return (((31 - ((WheelPos * 3) / 8)) * 0x0800) + (0 * 0x0020) + (WheelPos * 3 / 8));
  } else {
   WheelPos -= 170;
   return ((((WheelPos * 3) / 4) * 0x0020) + (31 - ((WheelPos * 3) / 8)));
  }
}
 
Back
Top