Laboratorijska vježba 4.2 Martin Braim
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:dffdc25e510b
diff -r 000000000000 -r dffdc25e510b main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Dec 03 18:03:04 2015 +0000 @@ -0,0 +1,47 @@ +//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); +} +} \ No newline at end of file