easytronic / Mbed 2 deprecated Nucleo_read_analog_value

Dependencies:   testmotor mbed

Committer:
mijimy
Date:
Mon Jan 18 05:14:42 2016 +0000
Revision:
3:999285691154
Parent:
1:0490a15c76e4
Child:
4:cad5a10b7007
i2clcd added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:c2d1ad5059da 1 #include "mbed.h"
mijimy 3:999285691154 2 #include "TextLCD.h"
mijimy 3:999285691154 3
mijimy 3:999285691154 4 TextLCD lcd(p9,p10);
mijimy 3:999285691154 5 AnalogIn analog_value(p20);
mijimy 3:999285691154 6 Serial pc ( USBTX , USBRX ) ;
bcostm 1:0490a15c76e4 7 DigitalOut led(LED1);
bcostm 1:0490a15c76e4 8
bcostm 0:c2d1ad5059da 9 int main() {
bcostm 1:0490a15c76e4 10 float meas;
bcostm 1:0490a15c76e4 11
bcostm 1:0490a15c76e4 12 printf("\nAnalogIn example\n");
bcostm 1:0490a15c76e4 13
bcostm 1:0490a15c76e4 14 while(1) {
mijimy 3:999285691154 15 meas = analog_value; // Converts and read the analog input value (value from 0.0 to 1.0)
mijimy 3:999285691154 16 meas = meas * 3.3; // Change the value to be in the 0 to 3300 range
mijimy 3:999285691154 17 printf("measure = %.3f V\n", meas);
mijimy 3:999285691154 18 lcd.locate(4,2);
mijimy 3:999285691154 19 lcd.printf("measure = %.3f V", meas);
mijimy 3:999285691154 20 if (meas > 2) { // If the value is greater than 2V then switch the LED on
bcostm 1:0490a15c76e4 21 led = 1;
bcostm 1:0490a15c76e4 22 }
bcostm 1:0490a15c76e4 23 else {
bcostm 1:0490a15c76e4 24 led = 0;
bcostm 0:c2d1ad5059da 25 }
mijimy 3:999285691154 26 wait(0.5); // 200 ms
bcostm 0:c2d1ad5059da 27 }
bcostm 0:c2d1ad5059da 28 }