![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
analog
main.cpp@2:0f44305ad45c, 2017-03-19 (annotated)
- Committer:
- Tomsik
- Date:
- Sun Mar 19 18:30:34 2017 +0000
- Revision:
- 2:0f44305ad45c
- Parent:
- 1:cf19fbe2bbef
- Child:
- 3:d06153ae243d
p?id?n? error hl??ky na uart, d?le ovl?d?n? termin?lu
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Tomsik | 0:9f88863531a6 | 1 | #include "mbed.h" |
Tomsik | 0:9f88863531a6 | 2 | |
Tomsik | 0:9f88863531a6 | 3 | |
Tomsik | 0:9f88863531a6 | 4 | DigitalOut led1 (LED1); |
Tomsik | 0:9f88863531a6 | 5 | AnalogIn analog (A0); |
Tomsik | 0:9f88863531a6 | 6 | |
Tomsik | 1:cf19fbe2bbef | 7 | Serial serial(PA_2,PA_3); |
Tomsik | 0:9f88863531a6 | 8 | |
Tomsik | 0:9f88863531a6 | 9 | int main() |
Tomsik | 2:0f44305ad45c | 10 | { uint16_t a0_val=0; |
Tomsik | 1:cf19fbe2bbef | 11 | float a0_volt=0; |
Tomsik | 1:cf19fbe2bbef | 12 | bool light=false; |
Tomsik | 1:cf19fbe2bbef | 13 | serial.baud(115200); |
Tomsik | 2:0f44305ad45c | 14 | while (1) { |
Tomsik | 1:cf19fbe2bbef | 15 | a0_val = analog.read_u16(); |
Tomsik | 1:cf19fbe2bbef | 16 | a0_volt = ((float)a0_val/65535)*3.3; |
Tomsik | 1:cf19fbe2bbef | 17 | |
Tomsik | 1:cf19fbe2bbef | 18 | light=a0_volt<1.5; |
Tomsik | 1:cf19fbe2bbef | 19 | led1=light; |
Tomsik | 2:0f44305ad45c | 20 | |
Tomsik | 2:0f44305ad45c | 21 | serial.printf("\033[3M"); |
Tomsik | 1:cf19fbe2bbef | 22 | serial.printf("Hodnota a0_val (16bit): %d\n\r", a0_val); |
Tomsik | 1:cf19fbe2bbef | 23 | |
Tomsik | 2:0f44305ad45c | 24 | if(a0_volt<1.5){ |
Tomsik | 2:0f44305ad45c | 25 | serial.printf("Napeti na vstupu A0: %.3f ERROR\n\r",a0_volt); |
Tomsik | 2:0f44305ad45c | 26 | serial.printf("\033[2A");} |
Tomsik | 2:0f44305ad45c | 27 | else{ |
Tomsik | 2:0f44305ad45c | 28 | serial.printf("Napeti na vstupu A0: %.3f OK\n\r",a0_volt); |
Tomsik | 2:0f44305ad45c | 29 | serial.printf("\033[2A"); |
Tomsik | 2:0f44305ad45c | 30 | } |
Tomsik | 1:cf19fbe2bbef | 31 | |
Tomsik | 2:0f44305ad45c | 32 | wait_ms(100); |
Tomsik | 0:9f88863531a6 | 33 | } |
Tomsik | 0:9f88863531a6 | 34 | } |