Two sensor values only if there is a change

Hi:) I am using the metro microcontroller with the Adafruit STEMMA Soil Sensor. There are two values coming in and I want to send them only if there is a change.

My error is:

In function ‘void loop()’:
soilsensor_BOTH_CHANGESonly:23:13: error: expected ‘)’ before ‘!’ token
if (tempC ! = old_tempC);
^
soilsensor_BOTH_CHANGESonly:29:19: error: expected ‘)’ before ‘!’ token
if (capread ! = old_capread);
^
Multiple libraries were found for “Wire.h”
Used: /Users/bal/Library/Arduino15/packages/adafruit/hardware/avr/1.4.13/libraries/Wire
Not used: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/Wire
Using library Adafruit_seesaw_Library at version 1.3.1 in folder: /Users/bal/Documents/Arduino/libraries/Adafruit_seesaw_Library
Using library Wire at version 1.0 in folder: /Users/bal/Library/Arduino15/packages/adafruit/hardware/avr/1.4.13/libraries/Wire
exit status 1
expected ‘)’ before ‘!’ token

Any advice would be appreciated as I am a newbie. I read related posts but I am still not sure what is wrong. My code is:

 #include "Adafruit_seesaw.h"

Adafruit_seesaw ss;

void setup() {
  Serial.begin(9600); //initialize serial communication BAUDRATE 115200

  if (!ss.begin(0x36)) {
    Serial.println("ERROR! seesaw not found");
    while(1);
  } else {
    Serial.println();
    Serial.print("seesaw started! version: ");
    Serial.println(ss.getVersion(), HEX); 
  }
}

int old_tempC;
int old_capread;

void loop() {
  float tempC = ss.getTemp(); 
  if (tempC ! = old_tempC);
    Serial.print(tempC); 
    old_tempC = tempC;
    delay(1);
    
   uint16_t capread = ss.touchRead(0);
      if (capread ! = old_capread);
        Serial.println(capread);
        old_capread = capread;
        delay(1000); 
}

Read the how get the most out of this forum sticky to see how to properly post code and error messages. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code in code tags.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called “copy error message”. Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

tempC ! = old_tempC

capread ! = old_capread

Do not put a space between ! and =.

Thank you so much @groundFungus! It is working now.

Final code:

#include "Adafruit_seesaw.h"
Adafruit_seesaw ss;

void setup() {
  Serial.begin(9600);
  if (!ss.begin(0x36)) {
    Serial.println("ERROR! seesaw not found");
    while (1);
  } else {
    Serial.println();
    Serial.print("seesaw started! version: ");
    Serial.println(ss.getVersion(), HEX);
  }
}
int old_tempC;
int old_capread;

void loop() {
  float tempC = ss.getTemp();
  delay(1);
  uint16_t capread = ss.touchRead(0);
  if (tempC != old_tempC);
  Serial.print(tempC);
  old_tempC = tempC;
  if (capread != old_capread);
  Serial.print(",");
  Serial.println(capread);
  old_capread = capread;
  delay(1000);
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.