Private
Public Access
2
0

examples/aio: Added examples for mraa_aio_read_float()/readFloat()

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Alex Tereschenko
2015-02-04 20:09:56 +01:00
committed by Brendan Le Foll
parent cd6701d604
commit e7c3c17eb3
4 changed files with 9 additions and 0 deletions

View File

@@ -30,6 +30,7 @@ int main ()
{
mraa_aio_context adc_a0;
uint16_t adc_value = 0;
float adc_value_float = 0.0;
adc_a0 = mraa_aio_init(0);
if (adc_a0 == NULL) {
@@ -38,7 +39,9 @@ int main ()
for(;;) {
adc_value = mraa_aio_read(adc_a0);
adc_value_float = mraa_aio_read_float(adc_a0);
fprintf(stdout, "ADC A0 read %X - %d\n", adc_value, adc_value);
fprintf(stdout, "ADC A0 read float - %.5f\n", adc_value_float);
}
mraa_aio_close(adc_a0);

View File

@@ -28,6 +28,7 @@
int main ()
{
uint16_t adc_value;
float adc_value_float;
mraa::Aio* a0;
a0 = new mraa::Aio(0);
@@ -37,7 +38,9 @@ int main ()
for(;;) {
adc_value = a0->read();
adc_value_float = a0->readFloat();
fprintf(stdout, "ADC A0 read %X - %d\n", adc_value, adc_value);
fprintf(stdout, "ADC A0 read float - %.5f\n", adc_value_float);
}
return MRAA_SUCCESS;

View File

@@ -27,4 +27,6 @@ console.log('MRAA Version: ' + m.getVersion()); //write the mraa version to the
var analogPin0 = new m.Aio(0); //setup access analog inpuput pin 0
var analogValue = analogPin0.read(); //read the value of the analog pin
var analogValueFloat = analogPin0.readFloat(); //read the pin value as a float
console.log(analogValue); //write the value of the analog pin to the console
console.log(analogValueFloat.toFixed(5)); //write the value in the float format

View File

@@ -29,5 +29,6 @@ print (mraa.getVersion())
try:
x = mraa.Aio(0)
print (x.read())
print ("%.5f" % x.readFloat())
except:
print ("Are you sure you have an ADC?")