Enter MicroPython paste mode
In the following examples it is helpful to know that MicroPython supports paste mode, where you can copy a large block of code from this user guide and paste it instead of typing it character by character. To use paste mode:
- Copy the code you want to run. For this example, copy the following code that is the code from the previous LED (Example: turn on an LED) example:
from machine import Pin
led = Pin("D4", Pin.OUT, value=0)
Note You can easily copy and paste code from the online version of this guide. Use caution with the PDF version, as it may not maintain essential indentations.
- Paste the copied code. Press CTRL + Shift + V or right-click in the Terminal and select Paste.
- In the terminal, at the MicroPython >>> prompt type Ctrl+E to enter paste mode. The terminal displays paste mode; Ctrl-C to cancel, Ctrl-D to finish.
- The code appears in the terminal occupying multiple lines, where each line starts with its line number and three = symbols. For example line 1 starts with 1===.
- If the code is correct, press Ctrl+D to run the code and you should once again see the DS4 LED turn on. If you get a Line 1 SyntaxError: invalid syntax error, see Syntax error at line 1.
Additionally, if you want to exit paste mode without running the code, for example, or if the code did not copy correctly, press Ctrl+C to cancel and return to the normal MicroPython >>> prompt. - Next turn the LED off. Copy the code below:
from machine import Pin
led = Pin("D4", Pin.OUT, value=1)
print("DS4 LED now OFF!")
print("Paste Mode Successful!")
- Press Ctrl+E to enter paste mode.
- Press Ctrl + Shift + V or right-click in the Terminal and select Paste to paste the copied code.
- If the code is correct, press Ctrl+D to run it. The LED should turn off and you should see two confirmation messages print to the screen.
PDF
