carterhickman
Member
I am new to the teensy so this may be a simple question. I am attempting to record from a DC power supply (just to make sure it is working) to get a test signal. I have the power supply connected to pin 17 of the teensy. I'm having a hard time figuring out if this is the right pin to connect to. I am fairly confused about the line: sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
I'm not sure what AUDIO_INPUT_LINEIN is referring to. Could anyone help me out with figuring out which pin I should hook the signal generator up to to record?
I'm not sure what AUDIO_INPUT_LINEIN is referring to. Could anyone help me out with figuring out which pin I should hook the signal generator up to to record?
Code:
/*
#include <buffer.h>
#include <color.h>
#include <gfxfont.h>
#include <ssd1351.h>
*/
// Record sound as raw data to a SD card, and play it back.
//
// Requires the audio shield:
// http://www.pjrc.com/store/teensy3_audio.html
//
// Three pushbuttons need to be connected:
// Record Button: pin 0 to GND
// Stop Button: pin 1 to GND
// Play Button: pin 2 to GND
//
// This example code is in the public domain.
#include <Bounce.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <XPT2046_Touchscreen.h>
#include <ILI9341_t3.h>
// GUItool: begin automatically generated code
AudioInputI2S i2s2; //xy=105,63
AudioAnalyzePeak peak1; //xy=278,108
AudioRecordQueue queue1; //xy=281,63
AudioPlaySdRaw playRaw1; //xy=302,157
AudioOutputI2S i2s1; //xy=470,120
AudioConnection patchCord1(i2s2, 0, queue1, 0);
AudioConnection patchCord2(i2s2, 0, peak1, 0);
AudioConnection patchCord3(playRaw1, 0, i2s1, 0);
AudioConnection patchCord4(playRaw1, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=265,212
#define TS_MINX 150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000
// The STMPE610 uses hardware SPI on the shield, and #8
#define STMPE_CS 8
// The display also uses hardware SPI, plus #9 & #10
#define TFT_RST 255
#define TFT_MOSI 7
#define TFT_SCLK 14
#define TFT_MISO 12
// For the Adafruit shield, these are the default.
#define TFT_DC 20
#define TFT_CS 21
// which input on the audio shield will be used?
const int myInput = AUDIO_INPUT_LINEIN;
//const int myInput = AUDIO_INPUT_MIC;
// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14
// Remember which mode we're doing
int mode = 0; // 0=stopped, 1=recording, 2=playing
// The file where data is recorded
File frec;
int x;
int y;
int counter;
ILI9341_t3 tft(TFT_CS, TFT_DC, 255, TFT_MOSI, TFT_SCLK, TFT_MISO);
XPT2046_Touchscreen ts(STMPE_CS);
void setup() {
Serial.begin(9600);
Serial.println(myInput);
while(!Serial); // Wait for the serial to work
tft.begin();
Serial.println("here");
if (!ts.begin()) {
Serial.print("TS not connected.");
while (1);
}
tft.fillScreen(ILI9341_BLUE);
tft.setRotation(3);
tft.setCursor(80,65);
tft.fillRoundRect(60, 55, 75, 30, 5, ILI9341_BLACK);
tft.println("RECORD");
tft.setCursor(190, 65);
tft.fillRoundRect(185, 55, 75, 30, 5, ILI9341_BLACK);
tft.println("PLAY");
// Configure the pushbutton pins
tft.setCursor(140,25);
tft.fillRoundRect(130,15, 60, 30, 5, ILI9341_BLACK);
tft.println("STOP");
// Audio connections require memory, and the record queue
// uses this memory to buffer incoming audio.
AudioMemory(60);
// Enable the audio shield, select input, and enable output
sgtl5000_1.enable();
sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
sgtl5000_1.volume(0.5);
// Initialize the SD card
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
if (!(SD.begin(SDCARD_CS_PIN))) {
// stop here if no SD card, but print a message
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
}
void loop() {
TS_Point p = ts.getPoint();
//Serial.println(p);
int given_x = 320 * (p.x - 130) / 3650;
int given_y = 240 * (p.y - 150) / 3870;
if (!ts.bufferEmpty() && ts.touched()) {
if (given_x - x > 15 || x - given_x > 15 || given_y - y > 15 || y - given_y > 15) {
y = given_y;
x = given_x;
}
}
if (counter > 10000) {
counter = -1;
} else if (counter == 0) {
if (y <= 85 && y >= 55) {
if (x <= 135 && x >= 60) {
Serial.println("Record Button Press");
if (mode == 2) stopPlaying();
if (mode == 0) startRecording();
}
if (x <= 260 && x >= 185) {
// Start playback
Serial.println("Play Button Press");
if (mode == 1) stopRecording();
if (mode == 0) startPlaying();
}
} else if (y >= 15 && x >= 150 && x <= 210) {
Serial.println("Stop Button Press");
if (mode == 1) stopRecording();
if (mode == 2) stopPlaying();
}
} else if (counter % 500 == 0) {
// Update the pot values
}
counter++;
// If we're playing or recording, carry on...
if (mode == 1) {
continueRecording();
}
if (mode == 2) {
continuePlaying();
}
// when using a microphone, continuously adjust gain
// if (myInput == AUDIO_INPUT_MIC) adjustMicLevel();
}
void startRecording() {
Serial.println("startRecording");
if (SD.exists("RECORD.RAW")) {
// The SD library writes new data to the end of the
// file, so to start a new recording, the old file
// must be deleted before new data is written.
SD.remove("RECORD.RAW");
}
frec = SD.open("RECORD.RAW", FILE_WRITE);
if (frec) {
queue1.begin();
mode = 1;
}
}
void continueRecording() {
if (queue1.available() >= 2) {
byte buffer[512];
// Fetch 2 blocks from the audio library and copy
// into a 512 byte buffer. The Arduino SD library
// is most efficient when full 512 byte sector size
// writes are used.
memcpy(buffer, queue1.readBuffer(), 256);
queue1.freeBuffer();
memcpy(buffer+256, queue1.readBuffer(), 256);
queue1.freeBuffer();
// write all 512 bytes to the SD card
elapsedMicros usec = 0;
frec.write(buffer, 512);
}
}
void stopRecording() {
Serial.println("stopRecording");
queue1.end();
if (mode == 1) {
while (queue1.available() > 0) {
frec.write((byte*)queue1.readBuffer(), 256);
queue1.freeBuffer();
}
frec.close();
}
mode = 0;
}
void startPlaying() {
Serial.println("startPlaying");
playRaw1.play("RECORD.RAW");
mode = 2;
}
void continuePlaying() {
if (!playRaw1.isPlaying()) {
playRaw1.stop();
mode = 0;
}
}
void stopPlaying() {
Serial.println("stopPlaying");
if (mode == 2) playRaw1.stop();
mode = 0;
}
//void adjustMicLevel() {
// TODO: read the peak1 object and adjust sgtl5000_1.micGain()
// if anyone gets this working, please submit a github pull request :-)
//}