//0x38 (RA8875,FT6206,MAX98390)
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <RA8875.h>
#include <Adafruit_FT6206.h>
Adafruit_FT6206 ts = Adafruit_FT6206();
#define RA8875_CS 36
#define RA8875_RESET 40
#define RA8875_INT 41
RA8875 tft = RA8875(RA8875_CS, RA8875_RESET);
// GUItool: begin automatically generated code
AudioInputTDMB tdmB1; //xy=120,2290
AudioInputTDM tdm1; //xy=158,1989
AudioPlaySdWav playSdWav1; //xy=171,1750
AudioAmplifier amp3; //xy=301,1910
AudioAmplifier amp2; //xy=303,1847
AudioAmplifier amp4; //xy=303,1951
AudioAmplifier amp11; //xy=303,2230
AudioAmplifier amp1; //xy=305,1807
AudioAmplifier amp5; //xy=306,2003
AudioAmplifier amp10; //xy=306,2195
AudioAmplifier amp12; //xy=307,2273
AudioAmplifier amp13; //xy=308,2312
AudioAmplifier amp15; //xy=308,2391
AudioAmplifier amp14; //xy=311,2353
AudioAmplifier amp6; //xy=313,2052
AudioAmplifier amp8; //xy=347,1737
AudioAmplifier amp9; //xy=348,1770
AudioSynthWaveformSine sine1; //xy=458,2043
AudioSynthWaveformSine sine2; //xy=487,2403
AudioMixer4 mixer5; //xy=523,2193
AudioMixer4 mixer6; //xy=525,2265
AudioMixer4 mixer1; //xy=530,1785
AudioMixer4 mixer2; //xy=531,1866
AudioAmplifier amp7; //xy=531,1951
AudioAmplifier amp16; //xy=561,2348
AudioMixer4 mixer7; //xy=675,2199
AudioMixer4 mixer8; //xy=680,2262
AudioMixer4 mixer3; //xy=688,1856
AudioMixer4 mixer4; //xy=692,1925
AudioOutputTDM tdm2; //xy=825,1991
AudioOutputTDMB tdmB2; //xy=862,2285
AudioConnection patchCord1(tdmB1, 0, amp10, 0);
AudioConnection patchCord2(tdmB1, 2, amp11, 0);
AudioConnection patchCord3(tdmB1, 4, amp12, 0);
AudioConnection patchCord4(tdmB1, 6, amp13, 0);
AudioConnection patchCord5(tdmB1, 8, amp14, 0);
AudioConnection patchCord6(tdmB1, 10, amp15, 0);
AudioConnection patchCord7(tdm1, 0, amp1, 0);
AudioConnection patchCord8(tdm1, 2, amp2, 0);
AudioConnection patchCord9(tdm1, 4, amp3, 0);
AudioConnection patchCord10(tdm1, 6, amp4, 0);
AudioConnection patchCord11(tdm1, 8, amp5, 0);
AudioConnection patchCord12(tdm1, 10, amp6, 0);
AudioConnection patchCord13(playSdWav1, 0, amp8, 0);
AudioConnection patchCord14(playSdWav1, 1, amp9, 0);
AudioConnection patchCord15(amp3, 0, mixer1, 1);
AudioConnection patchCord16(amp2, 0, mixer2, 0);
AudioConnection patchCord17(amp4, 0, mixer2, 1);
AudioConnection patchCord18(amp11, 0, mixer6, 0);
AudioConnection patchCord19(amp1, 0, mixer1, 0);
AudioConnection patchCord20(amp5, 0, mixer1, 2);
AudioConnection patchCord21(amp10, 0, mixer5, 0);
AudioConnection patchCord22(amp12, 0, mixer5, 1);
AudioConnection patchCord23(amp13, 0, mixer6, 1);
AudioConnection patchCord24(amp15, 0, mixer6, 2);
AudioConnection patchCord25(amp14, 0, mixer5, 2);
AudioConnection patchCord26(amp6, 0, mixer2, 2);
AudioConnection patchCord27(amp8, 0, mixer1, 3);
AudioConnection patchCord28(amp9, 0, mixer2, 3);
AudioConnection patchCord29(sine1, amp7);
AudioConnection patchCord30(sine2, amp16);
AudioConnection patchCord31(mixer5, 0, mixer7, 0);
AudioConnection patchCord32(mixer6, 0, mixer8, 0);
AudioConnection patchCord33(mixer1, 0, mixer3, 0);
AudioConnection patchCord34(mixer2, 0, mixer4, 0);
AudioConnection patchCord35(amp7, 0, mixer3, 1);
AudioConnection patchCord36(amp7, 0, mixer4, 1);
AudioConnection patchCord37(amp16, 0, mixer7, 1);
AudioConnection patchCord38(amp16, 0, mixer8, 1);
AudioConnection patchCord39(mixer7, 0, tdmB2, 0);
AudioConnection patchCord40(mixer8, 0, tdmB2, 2);
AudioConnection patchCord41(mixer3, 0, tdm2, 0);
AudioConnection patchCord42(mixer4, 0, tdm2, 2);
AudioControlCS42448 cs42448_2; //xy=512,2481
AudioControlCS42448 cs42448_1; //xy=533,2091
// GUItool: end automatically generated code
bool sinetouch = 0;
float vol_sine = 3.0;
float vol_sd = 1.0;
float vol_line1 = 1.0;
void setup() {
Serial.begin(38400);
Wire.begin();
cs42448_1.setAddress(0x48);
cs42448_1.enable();
cs42448_2.setAddress(0x4A);
cs42448_2.enable();
// begin display: Choose from: RA8875_480x272, RA8875_800x480, RA8875_800x480ALT, Adafruit_480x272, Adafruit_800x480
tft.begin(RA8875_800x480);
if (!ts.begin(40)) {
Serial.println("Unable to start touchscreen.");
}
else {
Serial.println("Touchscreen started.");
}
tft.setRotation(0);
tft.fillWindow(RA8875_BLUE);//fill window black
tft.setFontScale(1);
AudioMemory(1000);
if (cs42448_1.enable() && cs42448_1.volume(0.8)) {
Serial.println("configured CS42448_1");
} else {
Serial.println("failed to config CS42448_1");
}
//TCA9548A(0);
if (cs42448_2.enable() && cs42448_2.volume(0.8)) {
Serial.println("configured CS42448_2");
} else {
Serial.println("failed to config CS42448_2");
}
cs42448_1.inputLevel(1.0);//very sensible !!
cs42448_2.inputLevel(1.0);
sine1.frequency(1200);
sine1.amplitude(0.3);
sine2.frequency(1200);
sine2.amplitude(0.3);
//--------AMPS TDM1-----------
amp1.gain(0);
amp2.gain(0);
amp3.gain(0);
amp4.gain(0);
amp5.gain(0);
amp6.gain(0);
amp7.gain(0);
amp8.gain(0);
amp9.gain(0);
//--------AMPS TDM2-----------
amp10.gain(0);
amp11.gain(0);
amp12.gain(0);
amp13.gain(0);
amp14.gain(0);
amp15.gain(0);
amp16.gain(0);
//---------MIXERS TDM1-----------
mixer1.gain(0,3.0);
mixer1.gain(1,3.0);
mixer1.gain(2,3.0);
mixer1.gain(3,vol_sd);
mixer2.gain(0,3.0);
mixer2.gain(1,3.0);
mixer2.gain(2,3.0);
mixer2.gain(3,vol_sd);
mixer3.gain(0,3.0);
mixer3.gain(1,vol_sine);
mixer3.gain(2,0.0);
mixer3.gain(3,0.0);
mixer4.gain(0,3.0);
mixer4.gain(1,vol_sine);
mixer4.gain(2,0.0);
mixer4.gain(3,0.0);
//----------MIXERS TDM2-----------
mixer5.gain(0,3.0);
mixer5.gain(1,3.0);
mixer5.gain(2,3.0);
mixer5.gain(3,0.0);
mixer6.gain(0,3.0);
mixer6.gain(0,3.0);
mixer6.gain(2,3.0);
mixer6.gain(3,0.0);
mixer7.gain(0,3.0);
mixer7.gain(1,vol_sine);
mixer7.gain(2,0.0);
mixer7.gain(3,0.0);
mixer8.gain(0,3.0);
mixer8.gain(1,vol_sine);
mixer8.gain(2,0.0);
mixer8.gain(3,0.0);
Serial.print("Initializing SD card...");
bool ok;
const int chipSelect = 38;
SPI1.setMISO(39);
SPI1.begin();
/
ok = SD.sdfs.begin(SdSpiConfig(chipSelect, SHARED_SPI, SD_SCK_MHZ(16), &SPI1));
if (!ok) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
}
boolean wastouched = true;
elapsedMillis msecs;
void loop() {
boolean istouched = ts.touched();
if (istouched) {
TS_Point p = ts.getPoint();
// rotate coordinate system
// flip it around to match the screen.
p.x = map(p.x, 0, 800,0,800);
p.y = map(p.y, 0, 480, 480,0);
int y = tft.height() - p.y;
int x = p.x;
if (!wastouched) {
tft.fillWindow(RA8875_BLACK);//fill window black
tft.setTextColor(RA8875_YELLOW);
tft.setCursor(700, 360);
tft.print("Touch");
}
tft.fillRect(680, 390, 140, 60, RA8875_BLACK);
tft.setTextColor(RA8875_GREEN);
//tft.setFont(Arial_24);
tft.setCursor(680, 390);
tft.print("X = ");
tft.print(p.x);
tft.setCursor(680, 420);
tft.print("Y = ");
tft.print(p.y);
Serial.print(", x = ");
Serial.print(", y = ");
//-------------INPUT: LINE 1--------------
if(p.x>=0 && p.x<=110 && p.y>=370 && p.y<=480)
{Serial.print("LINE1");
playSdWav1.stop();
amp1.gain(1);amp2.gain(1);
amp10.gain(1);amp11.gain(1);
amp3.gain(0);amp4.gain(0);
amp5.gain(0);amp6.gain(0);
amp7.gain(0);
amp8.gain(0);amp9.gain(0);
amp12.gain(0);amp13.gain(0);
amp14.gain(0);amp15.gain(0);
amp16.gain(0);
}
//-----------VOL LINE 1----------------
if(p.x>=0 && p.x<=110 && p.y>=270 && p.y<=380)
{
Serial.print("LINE1 VOL+");
vol_line1 += 0.2;
amp1.gain(vol_line1);amp2.gain(vol_line1);
amp10.gain(vol_line1);amp11.gain(vol_line1);
}
if(p.x>=0 && p.x<=110 && p.y>=170 && p.y<=280 && vol_line1 >= 0.1)
{
Serial.print("LINE1 VOL-");
vol_line1 -= 0.2;
amp1.gain(vol_line1);amp2.gain(vol_line1);
amp10.gain(vol_line1);amp11.gain(vol_line1);
//mixer1.gain(3,vol_line1);mixer2.gain(3,vol_line1);
}
//--------------INPUT: LINE 2---------------
if(p.x>=110 && p.x<=210 && p.y>=370 && p.y<=480)
{Serial.print("LINE2");
playSdWav1.stop();
amp3.gain(1);amp4.gain(1);
amp12.gain(1);amp13.gain(1);
amp1.gain(0);amp2.gain(0);
amp5.gain(0);amp6.gain(0);
amp7.gain(0);
amp8.gain(0);amp9.gain(0);
amp10.gain(0);amp11.gain(0);
amp14.gain(0);amp15.gain(0);
amp16.gain(0);
}
//--------------INPUT: LINE 3---------------
if(p.x>=210 && p.x<=310 && p.y>=370 && p.y<=480)
{Serial.print("LINE3");
playSdWav1.stop();
amp5.gain(1);amp6.gain(1);
amp14.gain(1);amp15.gain(1);
amp1.gain(0);amp2.gain(0);
amp3.gain(0);amp4.gain(0);
amp7.gain(0);
amp8.gain(0);amp9.gain(0);
amp10.gain(0);amp11.gain(0);
amp12.gain(0);amp13.gain(0);
amp16.gain(0);
}
//------------TEST SINE-----------
if(p.x>=310 && p.x<=410 && p.y>=370 && p.y<=480 && sinetouch == 0 )
{Serial.print("SINE");
amp8.gain(1);amp9.gain(1);
amp1.gain(0);amp2.gain(0);
amp3.gain(0);amp4.gain(0);
amp5.gain(0);amp6.gain(0);
amp10.gain(0);amp11.gain(0);
amp12.gain(0);amp13.gain(0);
amp14.gain(0);amp15.gain(0);
sinetouch = 1;
amp7.gain(1);
amp16.gain(1);
}
else{
sinetouch = 0;
amp7.gain(0);
amp16.gain(0);
}
//------------VOL TEST SINE-------------
if(p.x>=310 && p.x<=410 && p.y>=270 && p.y<=380)
{
Serial.print("SINE VOL+");
amp7.gain(1);amp16.gain(1);
vol_sine += 0.2;
mixer3.gain(1,vol_sine);mixer4.gain(1,vol_sine);
mixer7.gain(1,vol_sine);mixer8.gain(1,vol_sine);
}
if(p.x>=310 && p.x<=410 && p.y>=170 && p.y<=280 && vol_sine >= 0.5)
{
Serial.print("SINE VOL-");
amp7.gain(1);amp10.gain(1);
vol_sine -= 0.2;
mixer3.gain(1,vol_sine);mixer4.gain(1,vol_sine);
mixer7.gain(1,vol_sine);mixer8.gain(1,vol_sine);
}
//-------------PLAYER SD CARD------------
if(p.x>=410 && p.x<=510 && p.y>=370 && p.y<=480)
{Serial.print("SD1");
amp8.gain(1);amp9.gain(1);
amp1.gain(0);amp2.gain(0);
amp3.gain(0);amp4.gain(0);
amp5.gain(0);amp6.gain(0);
amp7.gain(0);
amp10.gain(0);amp11.gain(0);
amp12.gain(0);amp13.gain(0);
amp14.gain(0);amp15.gain(0);
amp16.gain(0);
playSdWav1.play("sdtest1.wav");
}
if(p.x>=510 && p.x<=610 && p.y>=370 && p.y<=480)
{Serial.print("SD2");
amp8.gain(1);amp9.gain(1);
amp1.gain(0);amp2.gain(0);
amp3.gain(0);amp4.gain(0);
amp5.gain(0);amp6.gain(0);
amp7.gain(0);
amp10.gain(0);amp11.gain(0);
amp12.gain(0);amp13.gain(0);
amp14.gain(0);amp15.gain(0);
amp16.gain(0);
playSdWav1.play("sdtest2.wav");
}
if(p.x>=610 && p.x<=710 && p.y>=370 && p.y<=480)
{Serial.print("STOP");
playSdWav1.stop();
}
//-------------VOL PLAYER SD CARD------------
if(p.x>=610 && p.x<=710 && p.y>=270 && p.y<=380)
{
Serial.print("SD VOL+");
vol_sd += 0.2;
mixer1.gain(3,vol_sd);mixer2.gain(3,vol_sd);
}
if(p.x>=610 && p.x<=710 && p.y>=170 && p.y<=280 && vol_sd >= 0.1)
{
Serial.print("SD VOL-");
//amp8.gain(1);amp9.gain(1);
vol_sd -= 0.2;
mixer1.gain(3,vol_sd);mixer2.gain(3,vol_sd);
}
}
else {
if (wastouched) {
tft.fillWindow(RA8875_BLACK);//fill window black
//-------------"INPUTS" BUTTONS--------------
tft.fillRect(0,0,100,100,RA8875_BLUE);//
tft.fillRect(100,0,100,100,RA8875_BLUE);//
tft.fillRect(200,0,100,100,RA8875_BLUE);//
tft.fillRect(300,0,100,100,RA8875_GREEN);//
tft.fillRect(400,0,100,100,RA8875_LIGHT_ORANGE );//
tft.fillRect(500,0,100,100,RA8875_LIGHT_ORANGE);//
tft.fillRect(600,0,100,100,RA8875_RED);//
//------------------"VOLUME +" BUTTONS----------------
tft.fillRect(0,100,100,100,RA8875_BLUE);//
tft.fillRect(100,100,100,100,RA8875_BLUE);//
tft.fillRect(200,100,100,100,RA8875_BLUE);//
tft.fillRect(300,100,100,100,RA8875_GREEN);//
tft.fillRect(400,100,100,100,RA8875_LIGHT_ORANGE );//
tft.fillRect(500,100,100,100,RA8875_LIGHT_ORANGE);//
tft.fillRect(600,100,100,100,RA8875_RED);//
//---------------"VOLUME -" BUTTONS
tft.fillRect(0,200,100,100,RA8875_BLUE);//
tft.fillRect(100,200,100,100,RA8875_BLUE);//
tft.fillRect(200,200,100,100,RA8875_BLUE);//
tft.fillRect(300,200,100,100,RA8875_GREEN);//
tft.fillRect(400,200,100,100,RA8875_LIGHT_ORANGE );//
tft.fillRect(500,200,100,100,RA8875_LIGHT_ORANGE);//
tft.fillRect(600,200,100,100,RA8875_RED);//
tft.setTextColor(RA8875_WHITE);
//tft.setFont(Arial_18);
tft.setCursor(10, 35);tft.print("LINE1");
tft.setCursor(10, 135);tft.print("VOL+");
tft.setCursor(10, 235);tft.print("VOL-");
tft.setCursor(110, 35);tft.print("LINE2");
tft.setCursor(110, 135);tft.print("VOL+");
tft.setCursor(110, 235);tft.print("VOL-");
tft.setCursor(210, 35);tft.print("LINE3");
tft.setCursor(210, 135);tft.print("VOL+");
tft.setCursor(210, 235);tft.print("VOL-");
tft.setCursor(310, 35);tft.print("SINE");
tft.setCursor(310, 135);tft.print("VOL+");
tft.setCursor(310, 235);tft.print("VOL-");
tft.setCursor(425, 35);tft.print("SD1");
tft.setCursor(525, 35);tft.print("SD2");
tft.setCursor(615, 35);tft.print("STOP");
tft.setCursor(610, 135);tft.print("VOL+");
tft.setCursor(610, 235);tft.print("VOL-");
}
Serial.println("no touch");
}
wastouched = istouched;
delay(100);
}