Kionko
December 4, 2015, 8:17pm
1
Hi guys! New here in the forums and new with the arduino, so i got a question for you.
I have an Manometer program that i did for arduino, that converts analog to int type 10 bits, but now i want to reverse the function, how do i do that with this program?
#define INTERVAL 1000
int x;
int timestamp;
float TEN2FLOAT (int val) {
return (val*5.0)/1023.0;
}
void metodo2(){
}
void VOLTMETER() {
x = analogRead(A0); //Lê os valores analogicos
if (millis() - timestamp < INTERVAL)
return;
else {
timestamp = millis();
Serial.print(timestamp);
Serial.print(" , ");
Serial.println(TEN2FLOAT(x), 3);
};
}
void MANOMETER(){
x = analogRead(A0); //Lê os valores analogicos
if (millis() - timestamp < INTERVAL)
return;
else {
timestamp = millis();
Serial.print(timestamp);
Serial.print(" , ");
Serial.println(TEN2FLOAT(x));
}
}
void setup() {
Serial.begin(9600);
}
void loop() {
//VOLTMETER();
MANOMETER();
}
Please use the "</>" Button to encapsulate your Code.
Kionko
December 4, 2015, 11:46pm
3
Sorry. Here it is (it has some portuguese words)
#define INTERVAL 1000
int x;
int timestamp;
float TEN2FLOAT (int val) {
return (val*5.0)/1023.0;
}
void metodo2(){
}
void VOLTMETER() {
x = analogRead(A0); //Lê os valores analogicos
if (millis() - timestamp < INTERVAL)
return;
else {
timestamp = millis();
Serial.print(timestamp);
Serial.print(" , ");
Serial.println(TEN2FLOAT(x), 3);
};
}
void MANOMETER(){
x = analogRead(A0); //Lê os valores analogicos
if (millis() - timestamp < INTERVAL)
return;
else {
timestamp = millis();
Serial.print(timestamp);
Serial.print(" , ");
Serial.println(TEN2FLOAT(x));
}
}
void setup() {
Serial.begin(9600);
}
void loop() {
//VOLTMETER();
MANOMETER();
}
Kionko
December 5, 2015, 12:42am
5
I want to reconvert the digital value (int 10 bits) to float VOLTAGE between 0 and 5
float voltage = 5.0*digitalValue/1024;
Kionko
December 5, 2015, 2:33pm
7
Then i do a serial print VOLTAGE right? (BTW ignore void VOLTMETER, that is from other exercise of the project)
Kionko:
Then i do a serial print VOLTAGE right? (BTW ignore void VOLTMETER, that is from other exercise of the project)
Really, in the time it took you to post that, you could have tried it.
Kionko
December 5, 2015, 4:48pm
9