If statement questions...

I've got a simple if statement inside my code that I keep getting the following error about,

bmp_lcd:87: error: expected primary-expression before '=' token

if (millis() - sampleClock >= sampleInt) {
    readBmp();
    storePress();
    sampleClock = millis();

I can't figure it out because it looks like it should be right. I thought maybe that I couldn't have an expression in the if statement so I tried it with the subtraction outside of the statement and stored a variable and got the same result. Any ideas?

I've posted the whole piece of code below, in case it's something else that's going on.

#include <Wire.h>
#include <BMP085.h>
#include <LiquidCrystal.h>

#define sampleInt = 5000
#define baroInt = 1800000

BMP085 bmp;
LiquidCrystal lcd(4,5,6,7,8,9);
byte mode = 0;
int sampleClock = 0;
long baroClock = 0L;
float temp, feet, press, oldPress = 0;
boolean baroDirection, tUnits = true;

void setup() {
  lcd.begin(16, 2);
  bmp.begin();
  lcd.clear();
  oldPress = bmp.readPressure() * .000296;
}

void readBmp() {
  temp = bmp.readTemperature();
  feet = bmp.readAltitude() * 3.28;
  press = bmp.readPressure() * .000296;
}

void displayPressure(boolean dir) {
  lcd.clear();
  lcd.setCursor(0,0);
    if (dir == true) {
      lcd.print("Falling");
      }
    else {
      lcd.print("Rising");
      }
  lcd.print(" Pressure");
  lcd.setCursor(0,1);
  lcd.print("of ");
  lcd.print(press, 2);
  lcd.print(" inches");
  }

void displayTemp(boolean format) {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Current Temp =");
  lcd.setCursor(0,1);
  if (format == true) {
    lcd.print(temp, 2);
  }
  else {
    lcd.print(((temp * 1.8) + 32), 2);
  }
  lcd.print(" degrees ");
  if (format == true) {
    lcd.print ("C");
  }
  else {
    lcd.print ("F");
  }
  }
	
void displayElevation() {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Elevation above");
  lcd.setCursor(0,1);
  lcd.print("MSL = ");
  lcd.print(feet, 0);
  lcd.print(" ft.");
  }
	
void storePress() {
  if (millis() - baroClock >= baroInt) {
    if (press < oldPress) {
      baroDirection = true;
    }
    else {
      baroDirection = false;
    }
    oldPress = press;
  }
}
	
void loop() {
  if (millis() - sampleClock >= sampleInt) {
    readBmp();
    storePress();
    sampleClock = millis();
    }
  switch (mode) {
    case 0:
      displayTemp(tUnits);
      break;
    case 1:
      displayPressure(baroDirection);
      break;
    case 2:
      displayElevation();
      break;
    default:
      mode = 0;
      }
}

Try defining all the time related variables as
unsigned long
so they are all the same type as millis()

Changed line to this;

unsigned long baroClock, sampleClock = 0;

Same problem.

-Ian

#define sampleInt = 5000

...

if (millis() - sampleClock >= sampleInt) {

The compiler substitutes the text for sampleInt in the expression. The text for sampleInt is "= 5000".

Thus you get:

if (millis() - sampleClock >= = 5000) {

Hence the error message.

Try:

#define sampleInt 5000

or:

const unsigned long sampleInt = 5000;

As 'baroInt' defines a number outside the range of an 'int' it probably should be specified as an 'unsigned long', as 'millis' is declared 'unsigned long millis(void)'.

I would also modify the define for 'sampleInt' to be an 'unsigned long' given its usage.

#define sampleInt 5000UL
#define baroInt 1800000UL

EDIT: Stupid me forgot the simple stuff, removed '='

But whatever you do to the #define, lose the = sign

Yep, as many noticed, the extra ='s in the #define were at fault.

-Ian