Currently doing a Project with the Arduino UNO where I'm making a multi effects guitar pedal, the menu works fine on its own as does the code (based off of Open Music Labs Clean pass through codehttp://wiki.openmusiclabs.com/wiki/PWMDAC). For some reason when I try to put it in the switch case structure, it keeps on giving me a "expected unqualified-id before string constant" error for the "ISR(TIMER1_CAPT_vect) " line. I've seen other people have similar problems and I've tried everything I can think off to fix it but still the same error, does anyone know how to fix this?
const int buttonPin_up = 7;
const int buttonPin_down = 8;
int selection = 0; // value used for selection
#define PWM_FREQ 0x00FF // pwm frequency
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // number of pwms
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(buttonPin_up, INPUT);
pinMode(buttonPin_down, INPUT);
// setup ADC
ADMUX = 0x60; // left adjust, adc0, internal vcc
ADCSRA = 0xe5; // turn on adc, ck/32, auto trigger
ADCSRB = 0x07; // t1 capture for trigger
DIDR0 = 0x01; // turn off digital inputs for adc0
// setup PWM
TCCR1A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
TCCR1B = ((PWM_MODE << 3) | 0x11); // ck/1
TIMSK1 = 0x20; // interrupt on capture interrupt
ICR1H = (PWM_FREQ >> 8);
ICR1L = (PWM_FREQ & 0xff);
DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
sei(); // turn on interrupts - not really necessary with arduino
}
void loop() {
if (digitalRead(buttonPin_up) == HIGH) {
selection += 1;
delay(750);
}
if (digitalRead(buttonPin_down) == HIGH) {
selection -= 1;
delay(750);
}
if (selection > 4) {
selection = 0;
}
if (selection < 0) {
selection = 4;
}
switch (selection) {
case 0:
digitalWrite(2, HIGH);
digitalWrite(6, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
ISR(TIMER1_CAPT_vect) {
// get ADC data
unsigned int temp1 = ADCL;
unsigned int temp2 = ADCH;
// output high byte on OC1A
OCR1AH = temp2 >> 8; // takes top 8 bits
OCR1AL = temp2; // takes bottom 8 bits
// output low byte on OC1B
OCR1BH = temp1 >> 8;
OCR1BL = temp1;
}
break;
case 1:
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
digitalWrite(6, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
break;
case 2:
digitalWrite(4, HIGH);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
break;
case 3:
digitalWrite(5, HIGH);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(6, LOW);
break;
case 4:
digitalWrite(6, HIGH);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
break;
}