DAC Test prog
Dependencies: mbed
main.cpp@0:9cf9c2bb9d64, 2018-01-26 (annotated)
- Committer:
- AbermetAlexander
- Date:
- Fri Jan 26 12:57:44 2018 +0000
- Revision:
- 0:9cf9c2bb9d64
DAC;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AbermetAlexander | 0:9cf9c2bb9d64 | 1 | #include "mbed.h" |
AbermetAlexander | 0:9cf9c2bb9d64 | 2 | |
AbermetAlexander | 0:9cf9c2bb9d64 | 3 | Serial pc(USBTX, USBRX); |
AbermetAlexander | 0:9cf9c2bb9d64 | 4 | AnalogOut aout(PA_4); //A3 Ersatz |
AbermetAlexander | 0:9cf9c2bb9d64 | 5 | AnalogOut aout2(PA_5); //A4 Motor 1 |
AbermetAlexander | 0:9cf9c2bb9d64 | 6 | AnalogOut aout3(PA_6); //A5 Motor 2 |
AbermetAlexander | 0:9cf9c2bb9d64 | 7 | |
AbermetAlexander | 0:9cf9c2bb9d64 | 8 | float aout_var = 0.0f; |
AbermetAlexander | 0:9cf9c2bb9d64 | 9 | |
AbermetAlexander | 0:9cf9c2bb9d64 | 10 | int main() |
AbermetAlexander | 0:9cf9c2bb9d64 | 11 | { |
AbermetAlexander | 0:9cf9c2bb9d64 | 12 | pc.printf("Press '+' to increase DAC, '-' to decrease DAC\n"); |
AbermetAlexander | 0:9cf9c2bb9d64 | 13 | |
AbermetAlexander | 0:9cf9c2bb9d64 | 14 | while(1) { |
AbermetAlexander | 0:9cf9c2bb9d64 | 15 | |
AbermetAlexander | 0:9cf9c2bb9d64 | 16 | char input = pc.getc(); |
AbermetAlexander | 0:9cf9c2bb9d64 | 17 | |
AbermetAlexander | 0:9cf9c2bb9d64 | 18 | if((input == '+')&&(aout_var < 1.0f)) { |
AbermetAlexander | 0:9cf9c2bb9d64 | 19 | aout_var += 0.1f; //+0,33 Volt |
AbermetAlexander | 0:9cf9c2bb9d64 | 20 | |
AbermetAlexander | 0:9cf9c2bb9d64 | 21 | aout=aout_var; |
AbermetAlexander | 0:9cf9c2bb9d64 | 22 | printf("aout = %1.2f volt\n", aout.read() * 3.3f); |
AbermetAlexander | 0:9cf9c2bb9d64 | 23 | |
AbermetAlexander | 0:9cf9c2bb9d64 | 24 | aout2=aout_var; |
AbermetAlexander | 0:9cf9c2bb9d64 | 25 | printf("aout2 = %1.2f volt\n", aout2.read() * 3.3f); |
AbermetAlexander | 0:9cf9c2bb9d64 | 26 | |
AbermetAlexander | 0:9cf9c2bb9d64 | 27 | aout3=aout_var; |
AbermetAlexander | 0:9cf9c2bb9d64 | 28 | printf("aout3 = %1.2f volt\n", aout3.read() * 3.3f); |
AbermetAlexander | 0:9cf9c2bb9d64 | 29 | |
AbermetAlexander | 0:9cf9c2bb9d64 | 30 | wait (0.5); |
AbermetAlexander | 0:9cf9c2bb9d64 | 31 | } |
AbermetAlexander | 0:9cf9c2bb9d64 | 32 | if((input == '-')&&(aout_var > 0.0f)) { |
AbermetAlexander | 0:9cf9c2bb9d64 | 33 | aout_var -= 0.1f; //+0,33 Volt |
AbermetAlexander | 0:9cf9c2bb9d64 | 34 | |
AbermetAlexander | 0:9cf9c2bb9d64 | 35 | aout=aout_var; |
AbermetAlexander | 0:9cf9c2bb9d64 | 36 | printf("aout = %1.2f volt\n", aout.read() * 3.3f); |
AbermetAlexander | 0:9cf9c2bb9d64 | 37 | |
AbermetAlexander | 0:9cf9c2bb9d64 | 38 | aout2=aout_var; |
AbermetAlexander | 0:9cf9c2bb9d64 | 39 | printf("aout2 = %1.2f volt\n", aout2.read() * 3.3f); |
AbermetAlexander | 0:9cf9c2bb9d64 | 40 | |
AbermetAlexander | 0:9cf9c2bb9d64 | 41 | aout3=aout_var; |
AbermetAlexander | 0:9cf9c2bb9d64 | 42 | printf("aout3 = %1.2f volt\n", aout3.read() * 3.3f); |
AbermetAlexander | 0:9cf9c2bb9d64 | 43 | |
AbermetAlexander | 0:9cf9c2bb9d64 | 44 | wait (0.5); |
AbermetAlexander | 0:9cf9c2bb9d64 | 45 | } |
AbermetAlexander | 0:9cf9c2bb9d64 | 46 | pc.printf("Press '+' to increase DAC, '-' to decrease DAC\n"); |
AbermetAlexander | 0:9cf9c2bb9d64 | 47 | } |
AbermetAlexander | 0:9cf9c2bb9d64 | 48 | } |