tedsat

Dependencies:   mbed

Fork of Nucleo_read_analog_value by FRA221_2015

Committer:
nutchanon_nutty
Date:
Tue Oct 13 07:56:51 2015 +0000
Revision:
1:f8fedb15be2e
Parent:
0:b30041f75f46
??????

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
nutchanon_nutty 1:f8fedb15be2e 5 DigitalOut led1(D13);
nutchanon_nutty 1:f8fedb15be2e 6 DigitalOut led2(D12);
nutchanon_nutty 1:f8fedb15be2e 7 DigitalOut led3(D11);
nutchanon_nutty 1:f8fedb15be2e 8 DigitalOut led4(D10);
nutchanon_nutty 1:f8fedb15be2e 9 DigitalOut led5(D9);
nutchanon_nutty 1:f8fedb15be2e 10 DigitalOut led6(D8);
nutchanon_nutty 1:f8fedb15be2e 11 DigitalOut led7(D7);
nutchanon_nutty 1:f8fedb15be2e 12 DigitalOut led8(D6);
soulx 0:b30041f75f46 13
soulx 0:b30041f75f46 14 int main() {
nutchanon_nutty 1:f8fedb15be2e 15 double meas;
soulx 0:b30041f75f46 16
soulx 0:b30041f75f46 17 while(1) {
soulx 0:b30041f75f46 18 meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
nutchanon_nutty 1:f8fedb15be2e 19 meas = meas*3.3;
nutchanon_nutty 1:f8fedb15be2e 20 if (meas >= 0 && meas < 0.17)
nutchanon_nutty 1:f8fedb15be2e 21 { led1 = 0;
nutchanon_nutty 1:f8fedb15be2e 22 led2 = 0;
nutchanon_nutty 1:f8fedb15be2e 23 led3 = 0;
nutchanon_nutty 1:f8fedb15be2e 24 led4 = 0;
nutchanon_nutty 1:f8fedb15be2e 25 led5 = 0;
nutchanon_nutty 1:f8fedb15be2e 26 led6 = 0;
nutchanon_nutty 1:f8fedb15be2e 27 led7 = 0;
nutchanon_nutty 1:f8fedb15be2e 28 led8 = 0;
nutchanon_nutty 1:f8fedb15be2e 29 }
nutchanon_nutty 1:f8fedb15be2e 30
nutchanon_nutty 1:f8fedb15be2e 31 else if (meas > 0.17 && meas <= 0.23571429)
nutchanon_nutty 1:f8fedb15be2e 32 { // If the value is greater than 2V then switch the LED on
nutchanon_nutty 1:f8fedb15be2e 33 led1 = 1;
nutchanon_nutty 1:f8fedb15be2e 34 led2 = 0;
nutchanon_nutty 1:f8fedb15be2e 35 led3 = 0;
nutchanon_nutty 1:f8fedb15be2e 36 led4 = 0;
nutchanon_nutty 1:f8fedb15be2e 37 led5 = 0;
nutchanon_nutty 1:f8fedb15be2e 38 led6 = 0;
nutchanon_nutty 1:f8fedb15be2e 39 led7 = 0;
nutchanon_nutty 1:f8fedb15be2e 40 led8 = 0;
nutchanon_nutty 1:f8fedb15be2e 41 }
nutchanon_nutty 1:f8fedb15be2e 42 else if (meas > 0.23571429 && meas <= 0.70714286)
nutchanon_nutty 1:f8fedb15be2e 43 { led1 = 1;
nutchanon_nutty 1:f8fedb15be2e 44 led2 = 1;
nutchanon_nutty 1:f8fedb15be2e 45 led3 = 0;
nutchanon_nutty 1:f8fedb15be2e 46 led4 = 0;
nutchanon_nutty 1:f8fedb15be2e 47 led5 = 0;
nutchanon_nutty 1:f8fedb15be2e 48 led6 = 0;
nutchanon_nutty 1:f8fedb15be2e 49 led7 = 0;
nutchanon_nutty 1:f8fedb15be2e 50 led8 = 0;
nutchanon_nutty 1:f8fedb15be2e 51 }
nutchanon_nutty 1:f8fedb15be2e 52 else if (meas > 0.70714286 && meas <= 1.17857143)
nutchanon_nutty 1:f8fedb15be2e 53 { led1 = 1;
nutchanon_nutty 1:f8fedb15be2e 54 led2 = 1;
nutchanon_nutty 1:f8fedb15be2e 55 led3 = 1;
nutchanon_nutty 1:f8fedb15be2e 56 led4 = 0;
nutchanon_nutty 1:f8fedb15be2e 57 led5 = 0;
nutchanon_nutty 1:f8fedb15be2e 58 led6 = 0;
nutchanon_nutty 1:f8fedb15be2e 59 led7 = 0;
nutchanon_nutty 1:f8fedb15be2e 60 led8 = 0;
soulx 0:b30041f75f46 61 }
nutchanon_nutty 1:f8fedb15be2e 62 else if (meas > 1.17857143 && meas <= 1.65)
nutchanon_nutty 1:f8fedb15be2e 63 { led1 = 1;
nutchanon_nutty 1:f8fedb15be2e 64 led2 = 1;
nutchanon_nutty 1:f8fedb15be2e 65 led3 = 1;
nutchanon_nutty 1:f8fedb15be2e 66 led4 = 1;
nutchanon_nutty 1:f8fedb15be2e 67 led5 = 0;
nutchanon_nutty 1:f8fedb15be2e 68 led6 = 0;
nutchanon_nutty 1:f8fedb15be2e 69 led7 = 0;
nutchanon_nutty 1:f8fedb15be2e 70 led8 = 0;
nutchanon_nutty 1:f8fedb15be2e 71 }
nutchanon_nutty 1:f8fedb15be2e 72 else if (meas > 1.65 && meas <= 2.12142857)
nutchanon_nutty 1:f8fedb15be2e 73 { led1 = 1;
nutchanon_nutty 1:f8fedb15be2e 74 led2 = 1;
nutchanon_nutty 1:f8fedb15be2e 75 led3 = 1;
nutchanon_nutty 1:f8fedb15be2e 76 led4 = 1;
nutchanon_nutty 1:f8fedb15be2e 77 led5 = 1;
nutchanon_nutty 1:f8fedb15be2e 78 led6 = 0;
nutchanon_nutty 1:f8fedb15be2e 79 led7 = 0;
nutchanon_nutty 1:f8fedb15be2e 80 led8 = 0;
soulx 0:b30041f75f46 81 }
nutchanon_nutty 1:f8fedb15be2e 82 else if (meas > 2.12142857 && meas <= 2.59285714)
nutchanon_nutty 1:f8fedb15be2e 83 { led1 = 1;
nutchanon_nutty 1:f8fedb15be2e 84 led2 = 1;
nutchanon_nutty 1:f8fedb15be2e 85 led3 = 1;
nutchanon_nutty 1:f8fedb15be2e 86 led4 = 1;
nutchanon_nutty 1:f8fedb15be2e 87 led5 = 1;
nutchanon_nutty 1:f8fedb15be2e 88 led6 = 1;
nutchanon_nutty 1:f8fedb15be2e 89 led7 = 0;
nutchanon_nutty 1:f8fedb15be2e 90 led8 = 0;
nutchanon_nutty 1:f8fedb15be2e 91 }
nutchanon_nutty 1:f8fedb15be2e 92 else if (meas > 2.59285714 && meas <= 3.06428571)
nutchanon_nutty 1:f8fedb15be2e 93 { led1 = 1;
nutchanon_nutty 1:f8fedb15be2e 94 led2 = 1;
nutchanon_nutty 1:f8fedb15be2e 95 led3 = 1;
nutchanon_nutty 1:f8fedb15be2e 96 led4 = 1;
nutchanon_nutty 1:f8fedb15be2e 97 led5 = 1;
nutchanon_nutty 1:f8fedb15be2e 98 led6 = 1;
nutchanon_nutty 1:f8fedb15be2e 99 led7 = 1;
nutchanon_nutty 1:f8fedb15be2e 100 led8 = 0;
nutchanon_nutty 1:f8fedb15be2e 101
nutchanon_nutty 1:f8fedb15be2e 102 }
nutchanon_nutty 1:f8fedb15be2e 103 else if (meas > 3.06428571 && meas <= 3.53571428)
nutchanon_nutty 1:f8fedb15be2e 104 { led1 = 1;
nutchanon_nutty 1:f8fedb15be2e 105 led2 = 1;
nutchanon_nutty 1:f8fedb15be2e 106 led3 = 1;
nutchanon_nutty 1:f8fedb15be2e 107 led4 = 1;
nutchanon_nutty 1:f8fedb15be2e 108 led5 = 1;
nutchanon_nutty 1:f8fedb15be2e 109 led6 = 1;
nutchanon_nutty 1:f8fedb15be2e 110 led7 = 1;
nutchanon_nutty 1:f8fedb15be2e 111 led8 = 1;
nutchanon_nutty 1:f8fedb15be2e 112 }
nutchanon_nutty 1:f8fedb15be2e 113
soulx 0:b30041f75f46 114 }
soulx 0:b30041f75f46 115 }