A problem in getting values

I was trying to build a thermometer that changed the color of an RGB Led based on the value taken from a standard (starter kit) TMP sensor. Tghe value never got below "130" and never over "160". I found a smooth formula to change the value of red and blue based on the temp.

const int redPin = 6;
const int greenPin = 3;
const int bluePin = 5;
const int tempReadPin = A0;

int redValue = 0;
int greenValue = 0;
int blueValue = 0;
int tempRead = 0;

void setup() {
  Serial.begin(9600);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(3, OUTPUT);
  
}

void loop() {
  tempRead = analogRead(tempReadPin);
  Serial.print(tempRead);
  greenValue = tempRead;
  blueValue = 255/1+(2.71828)pow(-0.1(tempRead-145));
  redValue =-(255/(1+(2.71828)pow(-0.1(tempRead-145))+255);
  Serial.print(",   red: ");
  Serial.print(redValue);
  Serial.print(",   blue: ");
  Serial.println(blueValue);
  delay(500);
  if (redValue>0) {
    if (blueValue>0) {
      analogWrite(bluePin, blueValue);
      analogWrite(redPin, redValue);
      }
    }
  }

The :
"
blueValue = 255/1+(2.71828)pow(-0.1(tempRead-145));
redValue =-(255/(1+(2.71828)pow(-0.1(tempRead-145))+255);
"
Keeps giving me the error:
"
In function 'void loop()':
23:30: error: expected ';' before 'pow'
24:31: error: expected ')' before 'pow'
24:59: error: expected ')' before ';' token
"
What have I done wrong?

You are multiplying, so insert a *
the two lines are also not structured the same. It is more obvious if you apply the default formatter by pressing ctrl-t:

  blueValue = 255 / 1 + (2.71828) * pow(-0.1 * (tempRead - 145));
  redValue = -(255 / (1 + (2.71828) * pow(-0.1 * (tempRead - 145)) + 255);

It keeps giving the same error :confused:

For clarity purpose, the function should've been (written outside of code):
blueValue=255/(1+e^(tempRead-145)

Tried this here:

void setup() {
  float tempRead = 150;
  float blueValue = 255 / 1 + (2.71828) * pow(-0.1 * (tempRead - 145), 1);
  float redValue = -(255 / (1 + (2.71828)) * pow(-0.1 * (tempRead - 145), 1) + 255 );
}

void loop() {
}

compiles here. DO note, I added the second mandatory parameter for pow(), with an arbitrary value.

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