Stuntmunky
Active member
I recently had a problem where I couldn't get the serial monitor to connect. As I hadn't updated for a long time I thought it could be this. I did a complete reinstall of Arduino and Teensyduino.
All worked fine, I can now connect to serial monitor but all my audio sketches with IRremote.h in them no longer compile. If I remove all the IR code, no probs. If I make a sketch with just the IR code on its own, no probs.
The following is the complete code that used to compile and is actually running on a teensy now but will no longer compile since I updated.
All worked fine, I can now connect to serial monitor but all my audio sketches with IRremote.h in them no longer compile. If I remove all the IR code, no probs. If I make a sketch with just the IR code on its own, no probs.
The following is the complete code that used to compile and is actually running on a teensy now but will no longer compile since I updated.
Code:
#include <IRremote.h>
#include <Encoder.h>
#include <Bounce.h>
#include <EEPROM.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioInputI2SQuad i2s_quad1; //xy=62,121
AudioPlaySdWav playSdWav2; //xy=71,305
AudioPlaySdWav playSdWav1; //xy=73,236
AudioMixer4 mixer2; //xy=218,249
AudioMixer4 mixer1; //xy=219,85
AudioMixer4 mixer3; //xy=219,317
AudioMixer4 mixer4; //xy=224,165
AudioMixer4 mixer5; //xy=348,122
AudioMixer4 mixer6; //xy=373,255
AudioMixer4 mixer7; //xy=490,181
AudioFilterStateVariable filter1; //xy=594,38
AudioFilterStateVariable filter3; //xy=609,113
AudioFilterStateVariable filter5; //xy=611,226
AudioFilterStateVariable filter2; //xy=722,35
AudioFilterStateVariable filter4; //xy=732,114
AudioFilterStateVariable filter6; //xy=738,223
AudioMixer4 mixer8; //xy=841,43
AudioMixer4 mixer9; //xy=861,131
AudioMixer4 mixer10; //xy=865,220
AudioOutputI2SQuad i2s_quad2; //xy=1004,52
AudioConnection patchCord1(i2s_quad1, 0, mixer4, 0);
AudioConnection patchCord2(i2s_quad1, 1, mixer1, 0);
AudioConnection patchCord3(i2s_quad1, 2, mixer1, 1);
AudioConnection patchCord4(playSdWav2, 0, mixer3, 0);
AudioConnection patchCord5(playSdWav2, 1, mixer3, 1);
AudioConnection patchCord6(playSdWav1, 0, mixer2, 0);
AudioConnection patchCord7(playSdWav1, 1, mixer2, 1);
AudioConnection patchCord8(mixer2, 0, mixer4, 1);
AudioConnection patchCord9(mixer1, 0, mixer5, 0);
AudioConnection patchCord10(mixer3, 0, mixer6, 1);
AudioConnection patchCord11(mixer4, 0, mixer5, 1);
AudioConnection patchCord12(mixer5, 0, mixer6, 0);
AudioConnection patchCord13(mixer6, 0, mixer7, 0);
AudioConnection patchCord14(mixer7, 0, filter1, 0);
AudioConnection patchCord15(mixer7, 0, filter3, 0);
AudioConnection patchCord16(mixer7, 0, filter5, 0);
AudioConnection patchCord17(filter1, 0, filter2, 0);
AudioConnection patchCord18(filter3, 0, filter4, 0);
AudioConnection patchCord19(filter5, 0, filter6, 0);
AudioConnection patchCord20(filter2, 2, mixer8, 0);
AudioConnection patchCord21(filter4, 2, mixer9, 0);
AudioConnection patchCord22(filter6, 2, mixer10, 0);
AudioConnection patchCord23(mixer8, 0, i2s_quad2, 1);
AudioConnection patchCord24(mixer9, 0, i2s_quad2, 0);
AudioConnection patchCord25(mixer10, 0, i2s_quad2, 3);
AudioControlSGTL5000 sgtl5000_1; //xy=67,20
AudioControlSGTL5000 sgtl5000_2; //xy=195,20
// GUItool: end automatically generated code
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14
const int ledPin1 = 3;
const int ledPin2 = 4;
const int ledPin3 = 5;
#define RECV_PIN 2
uint16_t lastCode = 0;
const uint16_t BUTTON_volup = 0xFFA857; //ir remote codes
const uint16_t BUTTON_voldown = 0xFFE01F;
const uint16_t BUTTON_back = 0xFF22DD;
const uint16_t BUTTON_stop = 0xFFC23D;
const uint16_t BUTTON_fwd = 0xFF02FD;
const uint16_t BUTTON_1 = 0xFF30CF;
const uint16_t BUTTON_2 = 0xFF18E7;
IRrecv irrecv(RECV_PIN);
decode_results results;
int volstore ;
float vol = 0.0 ;
Bounce button1 = Bounce(8, 15); // 15 = 15 ms debounce time
Encoder myEnc(1, 0);
float oldPosition1 = 0.0;
void setup() {
irrecv.enableIRIn();
pinMode (RECV_PIN, INPUT);
AudioMemory(60);
Serial.begin(9600);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(8, INPUT_PULLUP);
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);
}
}
sgtl5000_1.setAddress(LOW);
sgtl5000_1.enable();
sgtl5000_1.lineOutLevel(13);
sgtl5000_1.lineInLevel(0);
sgtl5000_1.muteHeadphone();
sgtl5000_2.setAddress(HIGH);
sgtl5000_2.enable();
sgtl5000_2.lineOutLevel(13);
sgtl5000_2.lineInLevel(0);
sgtl5000_2.muteHeadphone();
// bass filter set
filter1.frequency(200);
filter2.frequency(40);
// mid filter set
filter3.frequency(8000);
filter4.frequency(200);
// high filter set
filter5.frequency(18000);
filter6.frequency(8000);
// SD1 to mono
mixer2.gain(0, 0.5);
mixer2.gain(1, 0.5);
// SD2 to mono
mixer3.gain(0, 0.5);
mixer3.gain(1, 0.5);
// set sd2 to 0
mixer6.gain(0, 1.0 );
mixer6.gain(1, 0.0 );
// set main vol to 0
mixer7.gain(0, 0.0);
// set bass vol to 0
mixer8.gain(0, 0.0);
// set mid vol to 0
mixer9.gain(0, 0.0);
// set high vol to 0
mixer10.gain(0, 0.0);
EEPROM.get(20,volstore);
delay(5);
Serial.println(volstore);
float vol = (float)volstore / 100;
mixer7.gain(0, vol);
Serial.println( vol);
}
void loop() {
digitalWrite(ledPin3, HIGH);
// saves current volume in eeprom when pressed
button1.update();
if (button1.fallingEdge()) {
EEPROM.update(20,volstore);
delay (5);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin2, HIGH);
delay(100);
digitalWrite(ledPin2, LOW);
}
float newPosition = myEnc.read();
if (newPosition != oldPosition1) {
oldPosition1 = newPosition;
// Serial.println(newPosition);
vol = (float)volstore / 100;
vol = vol + (newPosition / 20);
if (vol>3){
vol = 3;}
if (vol<0.00){
vol = 0.00;}
Serial.println("vol");
Serial.println(vol);
mixer7.gain(0,vol);
volstore = vol * 100;
Serial.println(volstore);
// EEPROM.put(10,volstore);
// delay (10);
// Serial.println(EEPROM.read(10));
myEnc.write(0);
}
// Pan between line1 and line2
int line = analogRead(A6);
float line1 = (float)line / 1023.0;
float line2 = 1.0 - line1;
mixer1.gain(0, line1 );
mixer1.gain(1, line2 );
// Serial.println("mic1");
// Serial.println(line1);
// Pan between bluetooth and sd1
int mic = analogRead(A3);
float mic1 = (float)mic / 1023.0;
float mic2 = 1.0 - mic1;
mixer4.gain(0, mic1 );
mixer4.gain(1, mic2 );
// Serial.println("music1");
// Serial.println(mic1);
// Pan between mic and music mixes
int mix = analogRead(A2);
float mix1 = (float)mix / 1023.0;
float mix2 = 1.0 - mic1;
mixer5.gain(0, mix1 );
mixer5.gain(1, mix2 );
// Serial.println("mix1");
// Serial.println(mix1);
// Bass volume
int knob = analogRead(A17);
float bass = (float)knob / 1023.0;
mixer8.gain(0,bass);
// Mid volume
int knob1 = analogRead(A16);
float mid = (float)knob1 / 1023.0;
mixer9.gain(0,mid);
// High volume
int knob2 = analogRead(A7);
float high = (float)knob2 / 1023.0;
mixer10.gain(0,high);
//set level between sd1/line1/line2/blue and sd2 while sd2 is playing
if (playSdWav2.isPlaying() == true) {
mixer6.gain(0, 0.5 );
mixer6.gain(1, 0.5 );
}
else {
mixer6.gain(0, 1.0 );
mixer6.gain(1, 0.0 );
}
// ir buttons and decoder
{
if (irrecv.decode(&results)) {
uint16_t resultCode = (results.value & 0xFFFF);
if (resultCode == 0xFFFF)
resultCode = lastCode;
else
lastCode = resultCode;
switch (resultCode)
{
case BUTTON_volup:
vol = (float)volstore / 100;
vol = vol + 0.1;
if (vol>3){
vol = 3;}
if (vol<0){
vol = 0;}
Serial.println(vol);
mixer7.gain(0,vol);
volstore = vol * 100;
Serial.println(volstore);
break;
case BUTTON_voldown:
vol = (float)volstore / 100;
vol = vol - 0.1;
if (vol>3){
vol = 3;}
if (vol<0){
vol = 0;}
Serial.println(vol);
mixer7.gain(0,vol);
volstore = vol * 100;
Serial.println(volstore);
break;
case BUTTON_back:
// digitalWrite(backbutton, HIGH);
delay(500 );
// digitalWrite(backbutton, LOW);
// Serial.println("back");
break;
case BUTTON_stop:
playSdWav1.stop();
playSdWav2.stop();
break;
case BUTTON_fwd:
// digitalWrite(fwdbutton, HIGH);
delay(500);
// digitalWrite(fwdbutton, LOW);
// Serial.println("forward");
break;
case BUTTON_1:
playSdWav1.stop();
Serial.println("wav1");
playSdWav1.play("1.WAV");
delay(10); // wait for library to parse WAV info
break;
case BUTTON_2:
playSdWav1.stop();
Serial.println("wav2");
playSdWav1.play("2.WAV");
delay(10); // wait for library to parse WAV info
break;
default:
Serial.print("Unrecognized code received: 0x");
Serial.println(results.value, HEX);
break;
}
irrecv.resume();
}
}
}