Last active
August 29, 2015 14:18
-
-
Save andfoy/380a4695cfb3d7aa5ec9 to your computer and use it in GitHub Desktop.
This file contains 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
#include<math.h> | |
#define G 9.8 // m/s^2 | |
int analogPin = 0; | |
void setup() | |
{ | |
Serial.begin(9600); | |
} | |
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max) | |
{ | |
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; | |
} | |
void loop() | |
{ | |
int r = analogRead(analogPin); | |
Serial.println(r); | |
float pressure = mapfloat(r, 0, 1024, 0, 6); //KPa (Kg/s^2*m)e3 | |
float height = (pressure/G)*pow(10.0, 2.0); // cm | |
Serial.print("Altura actual de la sustancia (cm): "); | |
Serial.println(height); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment