Skip to content

Commit d7e93a7

Browse files
author
Amanda Butler
authored
Update examples in serial_communication.md
Replace hardcoded examples by applying changes from PR #1283 to fix failures.
1 parent f145562 commit d7e93a7

File tree

1 file changed

+4
-73
lines changed

1 file changed

+4
-73
lines changed

docs/tutorials/serial/serial_communication.md

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -64,76 +64,21 @@ If you're not sure how to build these examples and run them on your board, pleas
6464

6565
### Echo back characters you type
6666

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)
7968

8069
### Use the U and D keys to make LED1 brighter or dimmer
8170

8271
<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>
8372

8473
<span class="images">![](../../images/NUCLEOF401RE.png)<span>The pin map of the NUCLEO-F401RE shows LED1 on the Pwm pin.</span></span>
8574

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)
11076

11177
### Pass characters in both directions
11278

11379
Tie pins together to see characters echoed back.
11480

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)
13782

13883
### Using stdin, stdout and stderr
13984

@@ -150,18 +95,4 @@ int main() {
15095

15196
### Read to a buffer
15297

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

Comments
 (0)