#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioPlaySdWav playSdWav3; //xy=74,367
AudioPlaySdWav playSdWav1; //xy=77,241
AudioPlaySdWav playSdWav7; //xy=78,597
AudioPlaySdWav playSdWav4; //xy=80,425
AudioPlaySdWav playSdWav2; //xy=81,303
AudioPlaySdWav playSdWav6; //xy=82,535
AudioPlaySdWav playSdWav5; //xy=86,476
AudioMixer4 mixer1; //xy=291,316
AudioMixer4 mixer2; //xy=449,424
AudioOutputI2S i2s1; //xy=626,430
AudioConnection patchCord1(playSdWav3, 0, mixer1, 2);
AudioConnection patchCord2(playSdWav1, 0, mixer1, 0);
AudioConnection patchCord3(playSdWav7, 0, mixer2, 3);
AudioConnection patchCord4(playSdWav4, 0, mixer1, 3);
AudioConnection patchCord5(playSdWav2, 0, mixer1, 1);
AudioConnection patchCord6(playSdWav6, 0, mixer2, 2);
AudioConnection patchCord7(playSdWav5, 0, mixer2, 1);
AudioConnection patchCord8(mixer1, 0, mixer2, 0);
AudioConnection patchCord9(mixer2, 0, i2s1, 0);
AudioConnection patchCord10(mixer2, 0, i2s1, 1);
// GUItool: end automatically generated code
AudioControlSGTL5000 sgtl5000_1;
// 오디오보드의 sd카드 슬롯을 이용
//#define SDCARD_CS_PIN 10
//#define SDCARD_MOSI_PIN 7
//#define SDCARD_SCK_PIN 14
// Teensy4.1보드의 sd카드 슬롯을 이용
#define SDCARD_CS_PIN BUILTIN_SDCARD
#define SDCARD_MOSI_PIN 11 // not actually used
#define SDCARD_SCK_PIN 13 // not actually used
//기타와 관련된 상수들
#define TOUCHED 1
#define UNTOUCHED 0
#define STRING1 24
#define STRING2 25
#define STRING3 26
#define STRING4 27
#define STRING5 28
#define STRING6 29
void setup() {
Serial.begin(115200);
delay(1000);
// put your setup code here, to run once:
AudioMemory(8);
sgtl5000_1.enable();
sgtl5000_1.volume(1.0);
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);
}
}
Serial.println("Ready.");
pinMode(STRING1,INPUT);
pinMode(STRING2,INPUT);
pinMode(STRING3,INPUT);
pinMode(STRING4,INPUT);
pinMode(STRING5,INPUT);
pinMode(STRING6,INPUT);
}
bool prevString1 = UNTOUCHED;
bool prevString2 = UNTOUCHED;
bool prevString3 = UNTOUCHED;
bool prevString4 = UNTOUCHED;
bool prevString5 = UNTOUCHED;
bool prevString6 = UNTOUCHED;
///*
#define TIME_WAIT_TO_PLAY 2
void forcePlay(AudioPlaySdWav *ptrPlaySdWav, const char *wav){
ptrPlaySdWav->stop();
do{
ptrPlaySdWav->play(wav);
delay(TIME_WAIT_TO_PLAY);
} while(!ptrPlaySdWav->isPlaying());
}
//*/
void loop() {
int tm=millis();
///*
bool str1 = digitalRead(STRING1);
if (prevString1==UNTOUCHED and str1==TOUCHED){
forcePlay(&playSdWav1, "g100E.wav");
}
bool str2 = digitalRead(STRING2);
if (prevString2==UNTOUCHED and str2==TOUCHED){
forcePlay(&playSdWav2, "g200B.wav");
}
bool str3 = digitalRead(STRING3);
if (prevString3==UNTOUCHED and str3==TOUCHED){
forcePlay(&playSdWav3, "g300G.wav");
}
bool str4 = digitalRead(STRING4);
if (prevString4==UNTOUCHED and str4==TOUCHED){
forcePlay(&playSdWav4, "g400D.wav");
}
bool str5 = digitalRead(STRING5);
if (prevString5==UNTOUCHED and str5==TOUCHED){
forcePlay(&playSdWav5, "g500A.wav");
}
bool str6 = digitalRead(STRING6);
if (prevString6==UNTOUCHED and str6==TOUCHED){
forcePlay(&playSdWav6, "g600E.wav");
}
prevString1=str1;
prevString2=str2;
prevString3=str3;
prevString4=str4;
prevString5=str5;
prevString6=str6;
//*/
/*
playSdWav1.stop();
do{
playSdWav1.play("g600E.wav");
delay(TIME_WAIT_TO_PLAY);
} while(!playSdWav1.isPlaying());
*/
Serial.print(millis()-tm);
Serial.print(", S1:");Serial.print(str1);
Serial.print(", S2:");Serial.print(str2);
Serial.print(", S3:");Serial.print(str3);
Serial.print(", S4:");Serial.print(str4);
Serial.print(", S5:");Serial.print(str5);
Serial.print(", S6:");Serial.print(str6);
Serial.println();
delay(10);
}
'하드웨어 > ESP32' 카테고리의 다른 글
Lolin32+ OLED display(I2c) example (0) | 2021.11.12 |
---|---|
esp32 lolin32 lite보드의 터치핀 이용하기 (0) | 2021.10.30 |
ESP32보드를 아두이노IDE로 코딩하기 (0) | 2021.01.28 |