From: Alex Tereschenko Date: Wed, 4 Feb 2015 19:09:56 +0000 (+0100) Subject: examples/aio: Added examples for mraa_aio_read_float()/readFloat() X-Git-Tag: v0.6.1~34 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e7c3c17eb36437973884aace492bd5bd30f18914;p=contrib%2Fmraa.git examples/aio: Added examples for mraa_aio_read_float()/readFloat() Signed-off-by: Alex Tereschenko Signed-off-by: Brendan Le Foll --- diff --git a/examples/analogin_a0.c b/examples/analogin_a0.c index ab39311..5afce8b 100644 --- a/examples/analogin_a0.c +++ b/examples/analogin_a0.c @@ -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); diff --git a/examples/c++/AioA0.cpp b/examples/c++/AioA0.cpp index 44a9dc1..f0dcf02 100644 --- a/examples/c++/AioA0.cpp +++ b/examples/c++/AioA0.cpp @@ -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; diff --git a/examples/javascript/AioA0.js b/examples/javascript/AioA0.js index de280f7..7e35311 100644 --- a/examples/javascript/AioA0.js +++ b/examples/javascript/AioA0.js @@ -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 diff --git a/examples/python/aio.py b/examples/python/aio.py index 9be21f3..7478e1b 100644 --- a/examples/python/aio.py +++ b/examples/python/aio.py @@ -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?")