@@ -64,76 +64,21 @@ If you're not sure how to build these examples and run them on your board, pleas
64
64
65
65
### Echo back characters you type
66
66
67
- ``` cpp
68
- #include " mbed.h"
69
-
70
- Serial pc (USBTX, USBRX);
71
-
72
- int main() {
73
- pc.printf("Echoes back to the screen anything you type\n");
74
- while(1) {
75
- pc.putc(pc.getc());
76
- }
77
- }
78
- ```
67
+ [ ![ View code] ( https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/Tutorials_SerialComm/Serial_EchoBack/ )] ( https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/Tutorials_SerialComm/Serial_EchoBack/main.cpp )
79
68
80
69
### Use the U and D keys to make LED1 brighter or dimmer
81
70
82
71
<span class =" tips " >** Note:** This example only works if LED1 is on the Pwm pin of the board you are using, such as the NUCLEO-F401RE. </span >
83
72
84
73
<span class =" images " >![ ] ( ../../images/NUCLEOF401RE.png ) <span >The pin map of the NUCLEO-F401RE shows LED1 on the Pwm pin.</span ></span >
85
74
86
- ```cpp
87
- #include "mbed.h"
88
-
89
- Serial pc(USBTX, USBRX); // tx, rx
90
- PwmOut led(LED1);
91
-
92
- float brightness = 0.0;
93
-
94
- int main() {
95
- pc.printf("Press U to turn LED1 brightness up, D to turn it down\n");
96
-
97
- while(1) {
98
- char c = pc.getc();
99
- if((c == 'u') && (brightness < 0.5)) {
100
- brightness += 0.01;
101
- led = brightness;
102
- }
103
- if((c == 'd') && (brightness > 0.0)) {
104
- brightness -= 0.01;
105
- led = brightness;
106
- }
107
- }
108
- }
109
- ```
75
+ [ ![ View code] ( https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/Tutorials_SerialComm/Serial_LEDControl/ )] ( https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/Tutorials_SerialComm/Serial_LEDControl/main.cpp )
110
76
111
77
### Pass characters in both directions
112
78
113
79
Tie pins together to see characters echoed back.
114
80
115
- ``` cpp
116
- #include " mbed.h"
117
-
118
- Serial pc (USBTX, USBRX);
119
- Serial uart(D1, D0);
120
-
121
- DigitalOut pc_activity(LED1);
122
- DigitalOut uart_activity(LED2);
123
-
124
- int main() {
125
- while(1) {
126
- if(pc.readable()) {
127
- uart.putc(pc.getc());
128
- pc_activity = !pc_activity;
129
- }
130
- if(uart.readable()) {
131
- pc.putc(uart.getc());
132
- uart_activity = !uart_activity;
133
- }
134
- }
135
- }
136
- ```
81
+ [ ![ View code] ( https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/Tutorials_SerialComm/Serial_PassCharacters/ )] ( https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/Tutorials_SerialComm/Serial_PassCharacters/main.cpp )
137
82
138
83
### Using stdin, stdout and stderr
139
84
@@ -150,18 +95,4 @@ int main() {
150
95
151
96
### Read to a buffer
152
97
153
- ``` cpp
154
- #include " mbed.h"
155
-
156
- DigitalOut myled (LED1);
157
- Serial pc(USBTX, USBRX);
158
-
159
- int main() {
160
- char c;
161
- char buffer[ 128] ;
162
-
163
- pc.gets(buffer, 4);
164
- pc.printf("I got '%s'\n", buffer);
165
- while(1);
166
- }
167
- ```
98
+ [ ![ View code] ( https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/Tutorials_SerialComm/Serial_STDOUT/ )] ( https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/Tutorials_SerialComm/Serial_STDOUT/main.cpp )
0 commit comments