I was practicing and trying my Analog to Digital Converter (MCP3008) and trying this simple test. And here is my code :
#include <Adafruit_MCP3008.h>
Adafruit_MCP3008 adc;
float voltage(int raw){
return raw / 1023 * 4.9;
}
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("MCP3008 simple test.");
adc.begin();
}
void loop() {
int raw = adc.readADC(0);
Serial.print(raw);
Serial.print("\t");
Serial.println(voltage(raw));
delay(1000);
}
and when I opened my serial monitor it only showing the changes of "raw", but my "voltage" function seems not get included, here is what I got, as you can see it only shows the result for raw (on left), but not showing the voltage (on right)
I'm trying to make sure I got the "voltage" function affected also inside the void loop. can anybody explain me the rule of program in this case ?
float voltage(int raw){
// it is important to have the "1.0" DOT-ZERO
// to make the compiler handle it explicit as float
float myFLoat = raw * 1.0;
myFLoat = myFLoat / 1023 * 4.9;
return myFLoat;
}
or simply
float voltage(float raw){
return raw / 1023 * 4.9;
}