Created
April 1, 2016 01:59
-
-
Save sixstringsg/7bf3e3f5b42b9f11b80286a08b827a26 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int sensorPin = A0; | |
| int model = 2245; | |
| double voltageLow = 1.05; | |
| double voltageHigh = 4.88; | |
| bool debugMode = true; | |
| inline double PSIToPascal(double v) { return v*6894; } | |
| void setup() { | |
| pinMode(sensorPin, INPUT); | |
| } | |
| void loop() { | |
| Serial.println(autoMeter(model, sensorPin, voltageLow, voltageHigh, debugMode)); | |
| } | |
| double autoMeter(int model, int sensorPin, double voltageLow, double voltageHigh, bool debugMode) { | |
| switch (model) { | |
| case 2245: | |
| { | |
| int maxPSI = 15; | |
| double adcLow = voltageLow * 1024 * .2; | |
| double adcHigh = voltageHigh * 1024 * .2; | |
| int psivADC = maxPSI / (adcHigh - adcLow); | |
| int sensorReading = analogRead(sensorPin); | |
| float pressurePSI = sensorReading > adcLow ? (sensorReading - adcLow) | |
| * psivADC : 0; | |
| return pressurePSI; | |
| break; | |
| } | |
| case 2246: | |
| { | |
| int maxPSI = 100; | |
| double adcLow = voltageLow * 1024 * .2; | |
| double adcHigh = voltageHigh * 1024 * .2; | |
| int psivADC = maxPSI / (adcHigh - adcLow); | |
| int sensorReading = analogRead(sensorPin); | |
| float pressurePSI = sensorReading > adcLow ? (sensorReading - adcLow) | |
| * psivADC : 0; | |
| return pressurePSI; | |
| break; | |
| } | |
| case 2239: | |
| { | |
| int maxPSI = 30; | |
| double adcLow = voltageLow * 1024 * .2; | |
| double adcHigh = voltageHigh * 1024 * .2; | |
| int psivADC = maxPSI / (adcHigh - adcLow); | |
| int sensorReading = analogRead(sensorPin); | |
| float pressurePSI = sensorReading > adcLow ? (sensorReading - adcLow) | |
| * psivADC : 0; | |
| return pressurePSI; | |
| break; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment