Laboratorijska vježba 4.2 Martin Braim

Dependencies:   mbed

Committer:
MBraim
Date:
Thu Dec 03 18:03:04 2015 +0000
Revision:
0:dffdc25e510b
Laboratorijska vje?ba 4.2; Martin Braim; 03.12.2015.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MBraim 0:dffdc25e510b 1 //Reads input through the ADC, and transfers to PC terminal
MBraim 0:dffdc25e510b 2 #include "mbed.h"
MBraim 0:dffdc25e510b 3 Serial pc(USBTX, USBRX);
MBraim 0:dffdc25e510b 4 DigitalOut myled(LED1);
MBraim 0:dffdc25e510b 5 DigitalOut myled1(LED2);
MBraim 0:dffdc25e510b 6 DigitalOut myled2(LED3);
MBraim 0:dffdc25e510b 7 DigitalOut myled3(LED4);
MBraim 0:dffdc25e510b 8 AnalogIn Ain(p20);
MBraim 0:dffdc25e510b 9 float ADCdata;
MBraim 0:dffdc25e510b 10 int main() {
MBraim 0:dffdc25e510b 11 pc.printf("ADC Data Values... \n\r");
MBraim 0:dffdc25e510b 12 while (1) {
MBraim 0:dffdc25e510b 13 ADCdata=Ain;
MBraim 0:dffdc25e510b 14 if (ADCdata <= 0.2){
MBraim 0:dffdc25e510b 15 myled = 0;
MBraim 0:dffdc25e510b 16 myled1 = 0;
MBraim 0:dffdc25e510b 17 myled2 = 0;
MBraim 0:dffdc25e510b 18 myled3 = 0;
MBraim 0:dffdc25e510b 19 wait(0.1);}
MBraim 0:dffdc25e510b 20 else if ((ADCdata > 0.2) && (ADCdata <= 0.4)){
MBraim 0:dffdc25e510b 21 myled = 1;
MBraim 0:dffdc25e510b 22 myled1 = 0;
MBraim 0:dffdc25e510b 23 myled2 = 0;
MBraim 0:dffdc25e510b 24 myled3 = 0;
MBraim 0:dffdc25e510b 25 wait(0.1);}
MBraim 0:dffdc25e510b 26 else if ((ADCdata > 0.4) && (ADCdata <= 0.6)){
MBraim 0:dffdc25e510b 27 myled = 1;
MBraim 0:dffdc25e510b 28 myled1 = 1;
MBraim 0:dffdc25e510b 29 myled2 = 0;
MBraim 0:dffdc25e510b 30 myled3 = 0;
MBraim 0:dffdc25e510b 31 wait(0.1);}
MBraim 0:dffdc25e510b 32 else if ((ADCdata > 0.6) && (ADCdata <= 0.8)){
MBraim 0:dffdc25e510b 33 myled = 1;
MBraim 0:dffdc25e510b 34 myled1 = 1;
MBraim 0:dffdc25e510b 35 myled2 = 1;
MBraim 0:dffdc25e510b 36 myled3 = 0;
MBraim 0:dffdc25e510b 37 wait(0.1);}
MBraim 0:dffdc25e510b 38 else if ((ADCdata > 0.8) && (ADCdata <= 1.0)){
MBraim 0:dffdc25e510b 39 myled = 1;
MBraim 0:dffdc25e510b 40 myled1 = 1;
MBraim 0:dffdc25e510b 41 myled2 = 1;
MBraim 0:dffdc25e510b 42 myled3 = 1;
MBraim 0:dffdc25e510b 43 wait(0.1);}
MBraim 0:dffdc25e510b 44 pc.printf("%f \n\r",ADCdata);
MBraim 0:dffdc25e510b 45 //wait (0.5);
MBraim 0:dffdc25e510b 46 }
MBraim 0:dffdc25e510b 47 }