![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
analog
main.cpp@3:d06153ae243d, 2017-03-20 (annotated)
- Committer:
- Tomsik
- Date:
- Mon Mar 20 18:49:30 2017 +0000
- Revision:
- 3:d06153ae243d
- Parent:
- 2:0f44305ad45c
analog
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 | 3:d06153ae243d | 4 | DigitalOut led1 (PA_5); |
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 | 3:d06153ae243d | 10 | { |
Tomsik | 3:d06153ae243d | 11 | uint16_t a0_val=0; |
Tomsik | 1:cf19fbe2bbef | 12 | float a0_volt=0; |
Tomsik | 1:cf19fbe2bbef | 13 | bool light=false; |
Tomsik | 1:cf19fbe2bbef | 14 | serial.baud(115200); |
Tomsik | 2:0f44305ad45c | 15 | while (1) { |
Tomsik | 1:cf19fbe2bbef | 16 | a0_val = analog.read_u16(); |
Tomsik | 3:d06153ae243d | 17 | a0_volt = ((float)a0_val/65535)*3.319; |
Tomsik | 3:d06153ae243d | 18 | |
Tomsik | 3:d06153ae243d | 19 | light=a0_volt<3; |
Tomsik | 1:cf19fbe2bbef | 20 | led1=light; |
Tomsik | 3:d06153ae243d | 21 | |
Tomsik | 2:0f44305ad45c | 22 | serial.printf("\033[3M"); |
Tomsik | 1:cf19fbe2bbef | 23 | serial.printf("Hodnota a0_val (16bit): %d\n\r", a0_val); |
Tomsik | 3:d06153ae243d | 24 | |
Tomsik | 3:d06153ae243d | 25 | if(a0_volt<3) { |
Tomsik | 3:d06153ae243d | 26 | serial.printf("Napeti na vstupu A0: %.3f V ERROR\n\r",a0_volt); |
Tomsik | 3:d06153ae243d | 27 | serial.printf("\033[2A"); |
Tomsik | 3:d06153ae243d | 28 | } else { |
Tomsik | 3:d06153ae243d | 29 | serial.printf("Napeti na vstupu A0: %.3f V OK\n\r",a0_volt); |
Tomsik | 3:d06153ae243d | 30 | serial.printf("\033[2A"); |
Tomsik | 2:0f44305ad45c | 31 | } |
Tomsik | 3:d06153ae243d | 32 | wait_ms(100); |
Tomsik | 0:9f88863531a6 | 33 | } |
Tomsik | 0:9f88863531a6 | 34 | } |