Pomicanjem potenciometra pale se LED-ice ovisno o definiranim parametrima koji su zadani u vježbi. Pripadajući kod je dobiven intelektualnim rješenjem if naredbe gdje se određenim granicama uvjetuje paljenje dioda.
Dependencies: mbed
Fork of Predavec by
Revision 0:ea4e3eefa035, committed 2015-12-03
- Comitter:
- dpredavec
- Date:
- Thu Dec 03 18:05:15 2015 +0000
- Commit message:
- Vje?ba 4-2: LED VU metar - Predavec
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r ea4e3eefa035 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Dec 03 18:05:15 2015 +0000 @@ -0,0 +1,49 @@ +#include "mbed.h" // Predavec - VU LED vjezba +Serial pc(USBTX, USBRX); +AnalogIn Ain(p20); + +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); + +float ADCdata; + +int main() { + pc.printf("ADC Data Values... \n\r"); + while (1) { + ADCdata=Ain; + pc.printf("%f \n\r",ADCdata); + if (Ain <= 0.2){ + led1 = 0; + led2 = 0; + led3 = 0; + led4 = 0; + } + if ((Ain>0.2)&&(Ain<=0.4)){ + led1 = 1; + led2 = 0; + led3 = 0; + led4 = 0; + } + if ((Ain>0.4)&&(Ain<=0.6)){ + led1 = 1; + led2 = 1; + led3 = 0; + led4 = 0; + } + if ((Ain>0.6)&&(Ain<=0.8)){ + led1 = 1; + led2 = 1; + led3 = 1; + led4 = 0; + } + if ((Ain>0.8)&&(Ain<=1.0)){ + led1 = 1; + led2 = 1; + led3 = 1; + led4 = 1; + } + wait (0.01); + } +}
diff -r 000000000000 -r ea4e3eefa035 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Dec 03 18:05:15 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/ba1f97679dad \ No newline at end of file