gugus

Dependencies:   mbed

Committer:
Brignall
Date:
Fri May 18 12:18:21 2018 +0000
Revision:
0:1a0321f1ffbc
lala;

Who changed what in which revision?

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