Laboratorijska vježba 4.2 Martin Braim

Dependencies:   mbed

main.cpp

Committer:
MBraim
Date:
2015-12-03
Revision:
0:dffdc25e510b

File content as of revision 0:dffdc25e510b:

//Reads input through the ADC, and transfers to PC terminal
#include "mbed.h"
Serial pc(USBTX, USBRX);
DigitalOut myled(LED1);
DigitalOut myled1(LED2);
DigitalOut myled2(LED3);
DigitalOut myled3(LED4);
AnalogIn Ain(p20);
float ADCdata;
int main() {
pc.printf("ADC Data Values... \n\r");
while (1) { 
ADCdata=Ain;  
if (ADCdata <= 0.2){ 
    myled = 0;
    myled1 = 0;
    myled2 = 0;
    myled3 = 0;
    wait(0.1);}   
else if ((ADCdata > 0.2) && (ADCdata <= 0.4)){
        myled = 1;
        myled1 = 0;
        myled2 = 0;
        myled3 = 0;
        wait(0.1);}
else if ((ADCdata > 0.4) && (ADCdata <= 0.6)){
        myled = 1;
        myled1 = 1;
        myled2 = 0;
        myled3 = 0;
        wait(0.1);}       
else if ((ADCdata > 0.6) && (ADCdata <= 0.8)){
        myled = 1;
        myled1 = 1;
        myled2 = 1;
        myled3 = 0;
        wait(0.1);}       
else if ((ADCdata > 0.8) && (ADCdata <= 1.0)){
        myled = 1;
        myled1 = 1;
        myled2 = 1;
        myled3 = 1;
        wait(0.1);}
pc.printf("%f \n\r",ADCdata);
//wait (0.5); 
}
}