tedsat

Dependencies:   mbed

Fork of Nucleo_read_analog_value by FRA221_2015

main.cpp

Committer:
nutchanon_nutty
Date:
2015-10-13
Revision:
1:f8fedb15be2e
Parent:
0:b30041f75f46

File content as of revision 1:f8fedb15be2e:

#include "mbed.h"
 
AnalogIn analog_value(A0);
 
DigitalOut led1(D13);
DigitalOut led2(D12);
DigitalOut led3(D11);
DigitalOut led4(D10);
DigitalOut led5(D9);
DigitalOut led6(D8);
DigitalOut led7(D7);
DigitalOut led8(D6);

int main() {
    double meas;
    
    while(1) {
        meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
        meas = meas*3.3;
        if (meas >= 0 && meas < 0.17)
        {   led1 = 0;
            led2 = 0;
            led3 = 0;
            led4 = 0;
            led5 = 0;
            led6 = 0;
            led7 = 0;
            led8 = 0;
        }
        
         else if (meas > 0.17 && meas <= 0.23571429) 
        { // If the value is greater than 2V then switch the LED on
          led1 = 1;
          led2 = 0;
          led3 = 0;
          led4 = 0;
          led5 = 0;
          led6 = 0;
          led7 = 0;
          led8 = 0;
        }
        else if (meas > 0.23571429 && meas <= 0.70714286)
        {   led1 = 1;
            led2 = 1;
            led3 = 0;
            led4 = 0;
            led5 = 0;
            led6 = 0;
            led7 = 0;
            led8 = 0;
        }
        else if (meas > 0.70714286 && meas <= 1.17857143)
        {   led1 = 1;
            led2 = 1;
            led3 = 1;
            led4 = 0;
            led5 = 0;
            led6 = 0;
            led7 = 0;
            led8 = 0;
        }
        else if (meas > 1.17857143 && meas <= 1.65)
        {   led1 = 1;
            led2 = 1;
            led3 = 1;
            led4 = 1;
            led5 = 0;
            led6 = 0;
            led7 = 0;
            led8 = 0;
        }
        else if (meas > 1.65 && meas <= 2.12142857)
        {   led1 = 1;
            led2 = 1;
            led3 = 1;
            led4 = 1;
            led5 = 1;
            led6 = 0;
            led7 = 0;
            led8 = 0;
        }
        else if (meas > 2.12142857 && meas <= 2.59285714)
        {   led1 = 1;
            led2 = 1;
            led3 = 1;
            led4 = 1;
            led5 = 1;
            led6 = 1;
            led7 = 0;
            led8 = 0;
        } 
        else if (meas > 2.59285714 && meas <= 3.06428571)
        {   led1 = 1;
            led2 = 1;
            led3 = 1;
            led4 = 1;
            led5 = 1;
            led6 = 1;
            led7 = 1;
            led8 = 0;
            
         }
         else if (meas > 3.06428571 && meas <= 3.53571428)
         {  led1 = 1;
            led2 = 1;
            led3 = 1;
            led4 = 1;
            led5 = 1;
            led6 = 1;
            led7 = 1;
            led8 = 1;
         }
        
    }
}