It shows by an example how to read an Analog input signal

Dependencies:   mbed

Il Circuito

/media/uploads/StefanoArrigoni/circuitopotenziometro.jpg

Committer:
StefanoArrigoni
Date:
Tue Nov 20 10:40:11 2018 +0000
Revision:
1:45c3cb7f4e8e
Parent:
0:4a795cf05594
It shows by an example how to read an Analog input signal

Who changed what in which revision?

UserRevisionLine numberNew contents of line
perlatecnica 0:4a795cf05594 1 /****************************************************
perlatecnica 0:4a795cf05594 2 * FAST PROTOTYPING WITH NUCLEO *
perlatecnica 0:4a795cf05594 3 * Example Code 06: Variable resistor *
perlatecnica 0:4a795cf05594 4 * Author: Mauro D'Angelo *
perlatecnica 0:4a795cf05594 5 *****************************************************/
perlatecnica 0:4a795cf05594 6
perlatecnica 0:4a795cf05594 7 #include "mbed.h"
perlatecnica 0:4a795cf05594 8
perlatecnica 0:4a795cf05594 9 // Instanzia un oggetto di tipo AnalogIn che chiamo analog_value, e lo assegna al pin A0
perlatecnica 0:4a795cf05594 10 AnalogIn analog_value(A0);
perlatecnica 0:4a795cf05594 11
perlatecnica 0:4a795cf05594 12 DigitalOut led(LED1);
perlatecnica 0:4a795cf05594 13
perlatecnica 0:4a795cf05594 14 int main() {
perlatecnica 0:4a795cf05594 15 float meas;
perlatecnica 0:4a795cf05594 16
perlatecnica 0:4a795cf05594 17 while(1) {
perlatecnica 0:4a795cf05594 18 meas = analog_value.read(); // It reads the analog input value (value from 0.0 to 1.0)
perlatecnica 0:4a795cf05594 19 meas = meas * 3300; // Change the value to be in the 0 to 3300 range
perlatecnica 0:4a795cf05594 20 printf("measure = %.2f mV\r\n", meas);
perlatecnica 0:4a795cf05594 21 if (meas > 2000) { // If the value is greater than 2V then switch the LED on
perlatecnica 0:4a795cf05594 22 led = 1;
perlatecnica 0:4a795cf05594 23 }
perlatecnica 0:4a795cf05594 24 else {
perlatecnica 0:4a795cf05594 25 led = 0;
perlatecnica 0:4a795cf05594 26 }
perlatecnica 0:4a795cf05594 27 wait(0.2); // 200 ms
perlatecnica 0:4a795cf05594 28 }
perlatecnica 0:4a795cf05594 29 }