Lab2

Dependencies:   mbed

Committer:
Pitiwut
Date:
Tue Oct 13 08:20:27 2015 +0000
Revision:
2:3ff3ecfd9c70
Parent:
1:f8fedb15be2e
Recommit

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
Pitiwut 2:3ff3ecfd9c70 5 DigitalOut led(LED1);
Pitiwut 2:3ff3ecfd9c70 6
soulx 0:b30041f75f46 7 int main() {
Pitiwut 2:3ff3ecfd9c70 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)
Pitiwut 2:3ff3ecfd9c70 12 meas = meas * 3300; // Change the value to be in the 0 to 3300 range
Pitiwut 2:3ff3ecfd9c70 13 if (meas > 2000) { // If the value is greater than 2V then switch the LED on
Pitiwut 2:3ff3ecfd9c70 14 led = 1;
soulx 0:b30041f75f46 15 }
Pitiwut 2:3ff3ecfd9c70 16 else {
Pitiwut 2:3ff3ecfd9c70 17 led = 0;
soulx 0:b30041f75f46 18 }
Pitiwut 2:3ff3ecfd9c70 19 wait(0.2); // 200 ms
soulx 0:b30041f75f46 20 }
Pitiwut 2:3ff3ecfd9c70 21 }