![](/media/cache/profiles/ba5be68d3d541f2ca043d77fc54fe702.jpg.50x50_q85.jpg)
3rd Repo, trying to figure this out.
Fork of SOFT253_Template_Weather_OS_54 by
FakeSensor/FakeBarometer.cpp
- Committer:
- Netaphous
- Date:
- 2017-04-06
- Branch:
- feature/fakeSensor
- Revision:
- 50:c07e968b9582
- Child:
- 83:0d3572a8a851
File content as of revision 50:c07e968b9582:
#include "FakeSensor.h" #include "mbed.h" /* Constructor Takes in minimum and maximum values for fake pressure readings */ FakeBarometer::FakeBarometer(float pressMin, float pressMax) { pressureMin = pressMin; pressureMax = pressMax; } /* Simply fakes a get call to the sensor by doing nothing */ void FakeBarometer::get() {} /* Generates a random number for pressure using the range given in the constructor Returns the random number generated */ float FakeBarometer::pressure() { int rangeMax = 1000; float targetRange = pressureMax - pressureMin; srand(time(NULL)); int randNum = (rand()%rangeMax); float perc = (float)randNum / rangeMax; float percRange = perc * targetRange; float actual = percRange + pressureMin; return actual; }