This commit is contained in:
Sergio Pernas 2022-04-06 18:48:19 -03:00
parent b3617f831a
commit c3de7cecb2

View file

@ -7,25 +7,25 @@ int inQuery;
double getData() { int getData() {
int sensorValue = analogRead(A2); int sensorValue = analogRead(A2);
return (sensorValue * (5.0 / 1024.0)); return (map(sensorValue, 0, 700, 100, 0));
} }
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
} }
void loop() { void loop() {
Serial.write("\n");
delay(1000);
if ( Serial.available() > 0) { if ( Serial.available() > 0) {
inQuery = Serial.read(); inQuery = Serial.read();
if ( inQuery == devID) { if ( inQuery == devID) {
Serial.write(itoa(devID, devIDstr, 10)); Serial.write(itoa(devID, devIDstr, 10));
@ -33,9 +33,10 @@ void loop() {
Serial.write("Tur"); Serial.write("Tur");
Serial.write(" "); Serial.write(" ");
//char lecturaStr[6]; // Buffer big enough for 7-character float
char lecturaStr[6]; // Buffer big enough for 7-character float //dtostrf(getData(), 2, 4, lecturaStr); // Leave room for too large numbers!
dtostrf(getData(), 2, 4, lecturaStr); // Leave room for too large numbers! char lecturaStr[5]; // Buffer big enough for 7-character float
dtostrf(getData(), 3, 2, lecturaStr); // Leave room for too large numbers!
Serial.write(lecturaStr); Serial.write(lecturaStr);
Serial.write(" "); Serial.write(" ");
@ -43,7 +44,6 @@ void loop() {
Serial.write(" "); Serial.write(" ");
Serial.write("99"); Serial.write("99");
} }
} }