3rd Repo, trying to figure this out.
Fork of SOFT253_Template_Weather_OS_54 by
FakeSensor/FakeBarometer.cpp
- Committer:
- aburch1
- Date:
- 2017-05-11
- Revision:
- 83:0d3572a8a851
- Parent:
- 50:c07e968b9582
- Child:
- 85:422d0a1b95cf
File content as of revision 83:0d3572a8a851:
#include "FakeSensor.h" #include "mbed.h" /** Constructor Takes in minimum and maximum values for fake pressure readings @param pressMin : Minimum value for pressure. @param pressMax : Maximum value for pressure. */ FakeBarometer::FakeBarometer(float pressMin, float pressMax) { pressureMin = pressMin; pressureMax = pressMax; } /** 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 @return actual : The random number generated, simulating pressure. */ 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; }