jhughes1010 / weather

31 stars 18 forks source link

Explain pls :) #17

Closed L0cutus closed 2 years ago

L0cutus commented 2 years ago

Hello!

 //Average samples
  if (msTotal > 0 && samples > 0)
  {
    windSpeed = 1.49 * 1000 / (msTotal / samples);
  }

Can you explain the expression: 1.49 * 1000 / (msTotal / samples) ?

#ifdef METRIC
  windSpeed =  windSpeed * 1.60934;
#endif
  MonPrintf("WindSpeed: %f\n", windSpeed);
  windSpeed = int((windSpeed + .05) * 10) / 10;

and also: int((windSpeed + .05) * 10) / 10;

Thanks!

jhughes1010 commented 2 years ago

Let's start with the second question first as that calculation is more easy to explain. I'm rounding to the nearest 10th on windSpeed. Adding 5/100ths to the number takes care of the possible round up. Multiply by by 10, retrieve the truncated integer, then divide by 10 to get back to the original number.

I'll break down the other with attachment on UOM analysis. I need to refresh on this.

jhughes1010 commented 2 years ago

F7ACFD9C-E547-4210-8FEE-43FA55FD6CF4_1_102_o Here's the UOM analysis after the average ms/samples is calculated.

L0cutus commented 2 years ago

1.49 was for miles per hour?

jhughes1010 commented 2 years ago

Yes, 1.49 , was derived. Datasheet gives 2.4kph, subsequent multiply my 1.609 (if metric) gets us back to the 2.4kph.

L0cutus commented 2 years ago

1.49 was for miles per hour?

Yes, 1.49 , was derived. Datasheet gives 2.4kph, subsequent multiply my 1.609 (if metric) gets us back to the 2.4kph.

many thanks for reply, I'm also trying to build/program my weather station using PlatformIO and i have tried to build a multifile project like your project but wasn't so simple since I'm not a C/C++ developer at all :-)

jhughes1010 commented 2 years ago

Good luck with your efforts!