4-2: LED VU metar
Dependencies: mbed
main.cpp@0:9df49e4b7c19, 2015-12-03 (annotated)
- Committer:
- miljkovic
- Date:
- Thu Dec 03 17:59:28 2015 +0000
- Revision:
- 0:9df49e4b7c19
Vjezba 4-2: LED VU metar
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
miljkovic | 0:9df49e4b7c19 | 1 | #include "mbed.h" |
miljkovic | 0:9df49e4b7c19 | 2 | Serial pc(USBTX, USBRX); |
miljkovic | 0:9df49e4b7c19 | 3 | AnalogIn Ain(p20); |
miljkovic | 0:9df49e4b7c19 | 4 | |
miljkovic | 0:9df49e4b7c19 | 5 | DigitalOut led1(LED1); |
miljkovic | 0:9df49e4b7c19 | 6 | DigitalOut led2(LED2); |
miljkovic | 0:9df49e4b7c19 | 7 | DigitalOut led3(LED3); |
miljkovic | 0:9df49e4b7c19 | 8 | DigitalOut led4(LED4); |
miljkovic | 0:9df49e4b7c19 | 9 | |
miljkovic | 0:9df49e4b7c19 | 10 | int main() { |
miljkovic | 0:9df49e4b7c19 | 11 | float ADCdata; |
miljkovic | 0:9df49e4b7c19 | 12 | |
miljkovic | 0:9df49e4b7c19 | 13 | while (1) { |
miljkovic | 0:9df49e4b7c19 | 14 | ADCdata=Ain; |
miljkovic | 0:9df49e4b7c19 | 15 | pc.printf("%f \n\r",ADCdata); |
miljkovic | 0:9df49e4b7c19 | 16 | |
miljkovic | 0:9df49e4b7c19 | 17 | |
miljkovic | 0:9df49e4b7c19 | 18 | if(ADCdata<0.2) |
miljkovic | 0:9df49e4b7c19 | 19 | { |
miljkovic | 0:9df49e4b7c19 | 20 | myled1=0; |
miljkovic | 0:9df49e4b7c19 | 21 | myled2=0; |
miljkovic | 0:9df49e4b7c19 | 22 | myled3=0; |
miljkovic | 0:9df49e4b7c19 | 23 | myled4=0; |
miljkovic | 0:9df49e4b7c19 | 24 | |
miljkovic | 0:9df49e4b7c19 | 25 | } |
miljkovic | 0:9df49e4b7c19 | 26 | if((ADCdata>0.2)&&(ADCdata<0.4)) |
miljkovic | 0:9df49e4b7c19 | 27 | { |
miljkovic | 0:9df49e4b7c19 | 28 | myled1=1; |
miljkovic | 0:9df49e4b7c19 | 29 | myled2=0; |
miljkovic | 0:9df49e4b7c19 | 30 | myled3=0; |
miljkovic | 0:9df49e4b7c19 | 31 | myled4=0; |
miljkovic | 0:9df49e4b7c19 | 32 | |
miljkovic | 0:9df49e4b7c19 | 33 | } |
miljkovic | 0:9df49e4b7c19 | 34 | if((ADCdata>0.4)&&(ADCdata<0.6)) |
miljkovic | 0:9df49e4b7c19 | 35 | { |
miljkovic | 0:9df49e4b7c19 | 36 | myled1=1; |
miljkovic | 0:9df49e4b7c19 | 37 | myled2=1; |
miljkovic | 0:9df49e4b7c19 | 38 | myled3=0; |
miljkovic | 0:9df49e4b7c19 | 39 | myled4=0; |
miljkovic | 0:9df49e4b7c19 | 40 | |
miljkovic | 0:9df49e4b7c19 | 41 | } |
miljkovic | 0:9df49e4b7c19 | 42 | if((ADCdata>0.6)&&(ADCdata<0.8)) |
miljkovic | 0:9df49e4b7c19 | 43 | { |
miljkovic | 0:9df49e4b7c19 | 44 | myled1=1; |
miljkovic | 0:9df49e4b7c19 | 45 | myled2=1; |
miljkovic | 0:9df49e4b7c19 | 46 | myled3=1; |
miljkovic | 0:9df49e4b7c19 | 47 | myled4=0; |
miljkovic | 0:9df49e4b7c19 | 48 | |
miljkovic | 0:9df49e4b7c19 | 49 | } |
miljkovic | 0:9df49e4b7c19 | 50 | if((ADCdata>0.8)&&(ADCdata<=1)) |
miljkovic | 0:9df49e4b7c19 | 51 | |
miljkovic | 0:9df49e4b7c19 | 52 | { |
miljkovic | 0:9df49e4b7c19 | 53 | myled1=1; |
miljkovic | 0:9df49e4b7c19 | 54 | myled2=1; |
miljkovic | 0:9df49e4b7c19 | 55 | myled3=1; |
miljkovic | 0:9df49e4b7c19 | 56 | myled4=1; |
miljkovic | 0:9df49e4b7c19 | 57 | |
miljkovic | 0:9df49e4b7c19 | 58 | } |
miljkovic | 0:9df49e4b7c19 | 59 | |
miljkovic | 0:9df49e4b7c19 | 60 | } |
miljkovic | 0:9df49e4b7c19 | 61 | } |