First laboratory uses each of the five routines with your modifications. These routines illustrate digital output, PWM output, and Analog input and output.
main.cpp@67:9015fa015c73, 2018-08-23 (annotated)
- Committer:
- Tyari21
- Date:
- Thu Aug 23 13:49:20 2018 +0000
- Revision:
- 67:9015fa015c73
- Parent:
- 66:0a43d8aeeb76
- Child:
- 68:61bde79fc489
Operational with OS5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jonathan Austin |
0:2757d7abb7d9 | 1 | #include "mbed.h" |
Jonathan Austin |
0:2757d7abb7d9 | 2 | |
Tyari21 | 67:9015fa015c73 | 3 | Serial pc(USBTX, USBRX); |
Tyari21 | 67:9015fa015c73 | 4 | |
Tyari21 | 67:9015fa015c73 | 5 | // Initialize a pins to perform analog and digital output functions |
Tyari21 | 67:9015fa015c73 | 6 | AnalogOut aout(p18); |
Tyari21 | 67:9015fa015c73 | 7 | AnalogIn ain(p20); |
Jonathan Austin |
0:2757d7abb7d9 | 8 | |
Tyari21 | 67:9015fa015c73 | 9 | char text[128]; |
Tyari21 | 67:9015fa015c73 | 10 | float voltage; |
Tyari21 | 67:9015fa015c73 | 11 | // Adjust VCC to get best scaling |
Tyari21 | 67:9015fa015c73 | 12 | float VCC1=3.292; |
Tyari21 | 67:9015fa015c73 | 13 | float VCC2=3.292; |
Tyari21 | 67:9015fa015c73 | 14 | |
Tyari21 | 67:9015fa015c73 | 15 | int main(void){ |
Tyari21 | 67:9015fa015c73 | 16 | while (1) { |
Tyari21 | 67:9015fa015c73 | 17 | pc.printf("Please enter an output voltage\n\r"); |
Tyari21 | 67:9015fa015c73 | 18 | pc.scanf("%s", text); |
Tyari21 | 67:9015fa015c73 | 19 | voltage = atof(text); |
Tyari21 | 67:9015fa015c73 | 20 | pc.printf("Voltage output is %f\n\r", voltage); |
Tyari21 | 67:9015fa015c73 | 21 | // set the output value to be voltage/VCC |
Tyari21 | 67:9015fa015c73 | 22 | aout = voltage/VCC1; |
Tyari21 | 67:9015fa015c73 | 23 | // read the output voltage |
Tyari21 | 67:9015fa015c73 | 24 | pc.printf("Voltage read is %f\n\r", ain*VCC2); |
Jonathan Austin |
0:2757d7abb7d9 | 25 | } |
Jonathan Austin |
0:2757d7abb7d9 | 26 | } |
Jonathan Austin |
1:846c97078558 | 27 |