Go Down

Topic: an error "expected unqualified-id before string constant" when compiling (Read 4 times) previous topic - next topic

blizzard_ke

my project is:
a force is applied on a peizo sensor, a voltage will be produced. Now my code can judge what's a real hit (quick touch and then release). When a hit is applied on the sensor, the Pin 13 will produce a high level. at the same time I want to call the SineWave generator function. Actually the SineWave generator code is from Richard Cappels. It can work alone. But once it is put in my code, an error "expected unqualified-id before string constant" will happen.
my Code is:
Code: [Select]

#include <avr/interrupt.h>
#include <stdlib.h>

int led =13;
const int N=100;
float voltageValue[N];
float voltage[N];
int PressStatus;//Pressing flag;

//define Sinewave
char sinetable [32];
int  j ;

void ioinit (void)
{
   //Initialize output ports
   PORTD = B11111111;
   DDRD  = B11111111;

}

void timer_setup(){
   TCCR2A = 0;
   TCNT2=455;    //455 outputs 1.007khz
   TCCR2B = B00000010;
   //Timer2 Overflow Interrupt Enable
   TIMSK2 = 1<<TOIE2;
}


void setup(){
   ioinit();
   arraysetup();
   cli();
   timer_setup();
   j = 0;
   sei();

  //initialize serial communication at 4800bit per second;
Serial.begin(4800);
pinMode (led,OUTPUT);
}



void arraysetup(void){
   sinetable[0]=127;  // Put 32 step 8 bit sine table into array.
   sinetable[1]=152;
   sinetable[2]=176;
   sinetable[3]=198;
   sinetable[4]=217;
   sinetable[5]=233;
   sinetable[6]=245;
   sinetable[7]=252;
   sinetable[8]=254;
   sinetable[9]=252;
   sinetable[10]=245;
   sinetable[11]=233;
   sinetable[12]=217;
   sinetable[13]=198;
   sinetable[14]=176;
   sinetable[15]=152;
   sinetable[16]=128;
   sinetable[17]=103;
   sinetable[18]=79;
   sinetable[19]=57;
   sinetable[20]=38;
   sinetable[21]=22;
   sinetable[22]=10;
   sinetable[23]=3;
   sinetable[24]=0;
   sinetable[25]=3;
   sinetable[26]=10;
   sinetable[27]=22;
   sinetable[28]=38;
   sinetable[29]=57;
   sinetable[30]=79;
   sinetable[31]=103;
}

void loop(){
 
int i;
for(i=0;i<N;i++){
  //read the input on analog pin A0;
voltageValue[i] = analogRead(A0);
voltage[i] = voltageValue[i] * (5.0 / 1023.0);

if (i>0&&voltage[i]-voltage[i-1]>=0.1){
// Serial.println("voltage = ");
PressStatus=1;
digitalWrite(led,HIGH);
//call SineWave generator function
ISR(TIMER2_OVF_vect) {

   PORTD=(sinetable[j++]);
   TCNT2=455;
   if(j==32){
     j=0;
   }

}
}
else {
PressStatus=0;
digitalWrite(led,LOW);
}

Serial.println(voltage[i]);
//Serial.println(Press);
}

}




AWOL

Consistent indentation will help you spot your problem.
Serial i/o in an interrupt service routine is never a good idea.
The compiler will initialise your sine table for you when you declare it.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.


AWOL

Check your indentation.
This flavour of C++ doesn't allow function declarations inside other functions.

Here someone else suggested you concentrate on indentation.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

blizzard_ke

I am so sorry, I really don't know what is the indentation. Pls help me out or give me more hints.
Thanks a lot.

Go Up