Davidelvig
Well-known member
I recall encountering this before, but can't find the thread.
...works as expected with this simple setup:
...until the adc and AudioInputAnalog declarations are swapped in the code.
Is there are order-of-declaration that I need to watch for in these two libraries, or am I missing something else?
Thanks
Dave
Latest Arduino (1.8.5) and Teensyduino (1.4.2)
Mac OSX
Teensy 3.2
1.2V output mic (Neutronned)
simple blue pot
external power in this case (USB power cut)
This code:Mac OSX
Teensy 3.2
1.2V output mic (Neutronned)
simple blue pot
external power in this case (USB power cut)
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <ADC.h>
// This app, as written compiles and runs
// - showing FFT bins from an analog mic (AudioInputAnalog)
// - and variable input from an analog POT using ADC (0-65530)
// After swapping the order of the following two lines
// - FFT persistently shows unavailable,
// - and ADC.read() returns 0-1023
ADC *adc = new ADC();
AudioInputAnalog Mic;
AudioAnalyzeFFT1024 FFT;
AudioConnection patchCord3(Mic, FFT);
#define MAXINT16 65530
#define ADC_PIN A3
void setup() {
AudioMemory(50);
pinMode(ADC_PIN, INPUT);
}
void loop() {
printFFT();
printADC();
delay(50);
}
void printFFT() {
if (FFT.available()) {
Serial.print("FFT: ");
for (int i = 0; i < 60; i++) {
float n = FFT.read(i);
if (n >= 0.02) { // arbitrary minimal value
Serial.print("^^");
} else {
Serial.print(" ");
}
}
Serial.println();
} else {
Serial.println("FFT not available");
}
}
void printADC()
{
int a = adc->analogRead(ADC_PIN, ADC_1);
int m = map(a, 0, MAXINT16, 0, 128);
Serial.printf("ADC: %i\t", a);
for (int x = 0; x < 128; x++) {
if (x <= m)
Serial.print("a");
else
Serial.print(" ");
}
Serial.println();
}
...works as expected with this simple setup:
...until the adc and AudioInputAnalog declarations are swapped in the code.
Is there are order-of-declaration that I need to watch for in these two libraries, or am I missing something else?
Thanks
Dave