Basic ADC program

Dependencies:   mbed

Fork of Nucleo_read_analog_value by FRA221_2015

Committer:
soulx
Date:
Sun Aug 23 13:04:42 2015 +0000
Revision:
0:b30041f75f46
Child:
1:f8fedb15be2e
Lab2 analog read

Who changed what in which revision?

UserRevisionLine numberNew contents of line
soulx 0:b30041f75f46 1 #include "mbed.h"
soulx 0:b30041f75f46 2
soulx 0:b30041f75f46 3 AnalogIn analog_value(A0);
soulx 0:b30041f75f46 4
soulx 0:b30041f75f46 5 DigitalOut led(LED1);
soulx 0:b30041f75f46 6
soulx 0:b30041f75f46 7 int main() {
soulx 0:b30041f75f46 8 float meas;
soulx 0:b30041f75f46 9
soulx 0:b30041f75f46 10 while(1) {
soulx 0:b30041f75f46 11 meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
soulx 0:b30041f75f46 12 meas = meas * 3300; // Change the value to be in the 0 to 3300 range
soulx 0:b30041f75f46 13 if (meas > 2000) { // If the value is greater than 2V then switch the LED on
soulx 0:b30041f75f46 14 led = 1;
soulx 0:b30041f75f46 15 }
soulx 0:b30041f75f46 16 else {
soulx 0:b30041f75f46 17 led = 0;
soulx 0:b30041f75f46 18 }
soulx 0:b30041f75f46 19 wait(0.2); // 200 ms
soulx 0:b30041f75f46 20 }
soulx 0:b30041f75f46 21 }