unicornpower
Well-known member
I've just soldered up my Teensy 3.6 and have moved my current audio project over to it. I'm loving having 256k but my code was crashing as soon I was trying to read values from my pots. I've managed to recreate this issue in a small test program, and isolated the problem to only happening if I have an AudioInputAnalog defined and call analogRead(). I'm not actually using the analog input at the moment, as I'm playing audio from an SD card instead, so it's not patched to anything, I wouldn't expect this to cause a crash though?
Below is the code, if I comment out the AudioInputAnalog object, everything works fine, but I leave it in, it crashes immediately. Any ideas?
Below is the code, if I comment out the AudioInputAnalog object, everything works fine, but I leave it in, it crashes immediately. Any ideas?
Code:
#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
#include <SerialFlash.h>
#include <Bounce.h>
// Use these with the audio adaptor board
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14
AudioPlaySdRaw raw_player;
AudioInputAnalog audio_input; // PROGRAM CRASHES IMMEDIATELY UNLESS I COMMENT THIS OUT (or I comment out the analogRead)
AudioOutputAnalog audio_output;
AudioConnection patch_cord( raw_player, 0, audio_output, 0 );
int count = 0;
void setup()
{
AudioMemory(10);
Serial.begin(115200);
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
if (!(SD.begin(BUILTIN_SDCARD)))
{
// stop here, but print a message repetitively
while (1)
{
Serial.println("Unable to access the SD card");
delay(500);
}
}
}
void loop()
{
if( !raw_player.isPlaying() )
{
Serial.println("START RAW");
raw_player.play( "GUITAR.RAW" );
}
int value = analogRead( 20);
if( ++count % 1000 == 0 )
{
Serial.print(value);
Serial.print("\n");
}
}