I have a fair amount of experience with entry level Arduino programming. However, I keep getting this error that is really confounding me.
This is the error I am getting:
acceleromVibration1.cpp: In function ‘void loop()’:
acceleromVibration1.cpp:96:37: error: expected unqualified-id before ‘(’ token
acceleromVibration1.cpp:96:37: error: expected primary-expression before ‘)’ token
acceleromVibration1.cpp:96:37: error: expected primary-expression before ‘)’ token
acceleromVibration1.cpp:96:37: error: expected primary-expression before ‘)’ token
I will post the entirety of my code below but the problem is specifically in one of my if statements. The line referenced by the error is a Serial.print("foo"). However, just commenting out that Serial print line does not get rid of the error. All of the offending code appears to be in the following if statement, because if I comment out all of this it compiles fine. However, this is a pretty important part of my code.
if(newArray){
//analyze the arrays
for(int i = 0; i < arraySize; i++){
int deltaAbs = accelValsX[i].abs();
if(deltaAbs <= 1){
lowDeltaX = lowDeltaX + 1;
}
}
vibratioX = ((arraySize - lowDeltaX) / arraySize);
Serial.print("VibratioX: ");
Serial.println(vibratioX);
newArray = false;
}
Here is the entirety of my code if that is also helpful:
////////SETUP VALUES//////////
unsigned long readTime = 100;
int arraySize = 100;
/////////////////////////////
int first;
int x0 = 0;
int z0 = 0;
int y0 = 0;
int xMax = 0;
int yMax = 0;
int zMax = 0;
int xMin = 1024;
int yMin = 1024;
int zMin = 1024;
int xLast = 0;
int yLast = 0;
int zLast = 0;
int xDelta = 0;
int yDelta = 0;
int zDelta = 0;
unsigned long lastTime = millis();
int index = 0;
int i = 0;
int lowDeltaX = 0;
int lowDeltaY = 0;
int lowDeltaZ = 0;
int accelValsX[100];
int accelValsY[100];
int accelValsZ[100];
double vibratioX = 0;
double vibratioY = 0;
double vibratioZ = 0;
boolean newArray = false;
void setup() {
Serial.begin(9600);
//first = 1;
}
void loop () {
//time = millis();
if((millis() - lastTime) > readTime){
//read sensor
x0 = analogRead(0);
y0 = analogRead(1);
z0 = analogRead(2);
lastTime = millis();
}
preMaths();
if(index < arraySize){
accelValsX[index] = xDelta;
accelValsY[index] = yDelta;
accelValsZ[index] = zDelta;
}else{
index = 0;
newArray = true;
}
if(newArray){
//analyze the arrays
for(int i = 0; i < arraySize; i++){
int deltaAbs = accelValsX[i].abs();
if(deltaAbs <= 1){
lowDeltaX = lowDeltaX + 1;
}
}
vibratioX = ((arraySize - lowDeltaX) / arraySize);
Serial.print("VibratioX: ");
Serial.println(vibratioX);
newArray = false;
}
printing();
// delay(100);
}
void preMaths(){
//delta
xDelta = xLast - x0;
yDelta = yLast - y0;
zDelta = zLast - z0;
//reset last
xLast = x0;
yLast = y0;
zLast = z0;
}
void printing(){
//tab seperated
Serial.print("DX:");
Serial.print(xDelta);
Serial.print("\tDY:");
Serial.print(yDelta);
Serial.print("\tDZ:");
Serial.println(zDelta);
}
Thanks for any help, I have googled around a lot and lots of people get this error, but I have not be able to adapt any of the answers to my problem and I am about to pull my hair out. I hope it is something stupid that I have over looked, but I am just at a loss for what to do. THANKS!