Hlep me request Serial Monitor "inf"

#include <Wire.h>
float a, b, Output, Pressure,x;
const long OutMax = 14745, OutMin = 1638;
const long PressureMax = 15, PressureMin = -15; 
int i,vta,vt,mv,mvt;
void setup() {
  Wire.begin(0x28);
  Serial.begin(9600);
}
void loop() {
  Wire.requestFrom(0x28,2);
   a = Wire.read();
   b = Wire.read();
  Output = BitShiftCombine(a , b);
  for (i=0;i<40;i=i+1){
    vta=analogRead(Output);
    vt=(vta*5)/(pow(2,10)-1);
    mv=max(abs(vt-2.5),mvt);
    mvt=abs(mv-2.5);
  }
Pressure = (((Output - OutMin) * (PressureMax - PressureMin)) / (OutMax - OutMin)) + PressureMin;
x=-1*(Pressure*-1)*51.8-3.16/mvt;
  Serial.println(x); 
  delay(50);
}
long BitShiftCombine( unsigned char x_high, unsigned char x_low)
{
  long combined;
  combined = x_high;              //send x_high to rightmost 8 bits
  combined = combined << 8;       //shift x_high over to leftmost 8 bits
  combined |= x_low;              //logical OR keeps x_high intact in combined and fills in rightmost 8 bits
  return combined;
}

Do you have a question?

Please remember to use code tags when posting code

Your improperly posted code will not compile. Did you not see a warning when you posted the code?

Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

You can go back and fix your original post by highlighting the code and clicking the </> in the menu bar.
code tags new

Thank you for posting the code in code tags. It makes it easier to help you.

Now the code compiles, that's good, too.

If you are getting inf as an answer to your math, I suggest that you insert some serial prints in the code to monitor intermediate values during the calculations. You may find where it is going wrong.

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