Table of Contents
MPINO STUDIO 2 Phase 5 · Editing Arduino Code
This page explains how to create and manage Arduino Code files, write code, use completion and Go to Definition, find and replace text, and locate code errors.
1. Arduino Code Editor
Select a file under Code in Explorer to open it in the Arduino Code editor. The markers correspond to the descriptions below.
- 1 Code group: Lists the Arduino Code files in the project.
- 2 Line numbers and folding: Shows code locations and folds or expands functions and blocks.
- 3 Editing area: Used to write and edit Arduino C/C++ code.
- 4 Minimap: Shows the file structure and the currently visible area.
Selecting a file displays its contents and updates the selected item in Explorer.
2. Create and Manage Code Files
Primary Code File
The first code file in a new project is named main. When the project is saved for the first time, its name changes automatically to match the project file name.
The first code file is the project entry file. It stays at the top of the Code list and cannot be renamed, deleted, or moved directly.
Code File Operations
| Action | Mouse | Keyboard | Result |
|---|---|---|---|
| Add | Use + next to Code, or Add on the context menu for the Code group or a file | - | Adds and opens a new .ino file at the end of the list. |
| Rename | Double-click a file, or choose Rename from its context menu | F2 or Enter | Renames an additional code file. |
| Delete | Use the file's ×, or choose Delete from its context menu | Delete | Deletes the file after confirmation. |
| Move in list | Drag a file up or down | Ctrl + ↑ or Ctrl + ↓ | Moves the selected additional file one position in Explorer. |
Do not type the extension in a code file name. A name cannot be empty, start with a period, contain /ㆍ\ㆍ.., or differ from an existing name only by letter case.
Moving an additional file updates the current working list. When the project is opened again, additional files are sorted by name.
3. Write Code and Use Functions Across Files
Separating code by function makes a project easier to navigate and maintain. In this example, a function that limits a value is written in control and called from the primary code file.
''control'' file
int limitValue(int value) { return constrain(value, 0, 100); // Limit the value to the range 0 to 100. }
Primary code file
void setup() { } void loop() { D0 = limitValue(D1); // Limit D1 to 0 through 100 and store it in D0. ladderLoop(); // Run the ladder logic. }
limitValue()uses the Arduino functionconstrain()to return its argument within the range 0 through 100.- Multiple
.inofiles in one project are built together as one sketch, so a function in one file can be called from another. - This example was compiled successfully in an
MPINO-8A4R(T)-Sproject.
For the storage types of D0 and D1 and sharing PLC memory with Arduino Code, see Phase 2 · Understand Memory. To call an Arduino function from a ladder box function, see Calling an Arduino Code Function.
Caution: If ladderLoop() is removed from loop(), the ladder logic will not run.
4. Use Code Completion
As you type the beginning of a function or variable name, available items appear in the completion list.
- Type the beginning of a function or variable name in the code editor.
- If the list does not open, press
Ctrl + Space. - Select an item with
↑or↓. - Insert the selected item with
EnterorTab.
In the preceding example, typing limitV lets you select limitValue() from the other code file.
| Completion source | Example | What it contains |
|---|---|---|
| Project functions and variables | limitValue() | Names written in the project's code files |
| Arduino functions and constants | constrain() and HIGH | Functions and constants provided by Arduino |
| Board core and libraries | Analyzed functions and constants | Items from the selected board core and project libraries |
Board-core and library items may appear after code analysis finishes. A completed name still needs the argument count and types required by its definition.
5. Go to Definition
Place the cursor on a function or variable name and press F12 to open its definition.
| Definition location | Result of F12 |
|---|---|
| Current code file | Moves to the line containing the definition. |
| Another code file | Opens that file and moves to the definition. |
| Arduino core or library | Opens a read-only definition view. |
Pressing F12 on limitValue() in the primary code file opens its definition in control. Arduino-core functions such as constrain() open in a read-only definition view. Close that view with its close button or Esc.
- 1 Call site: The function whose definition you want to inspect.
- 2 Function definition: The declaration or implementation opened by
F12. - 3 Read-only: Arduino-core and library definitions cannot be edited here.
| Focused editor | F12 action |
|---|---|
| Arduino Code | Go to Definition |
| Ladder Logic | Create a falling-edge contact |
The same shortcut performs a different action according to the focused editor.
6. Find and Replace
Arduino Code and Ladder Logic use a find-and-replace interface suited to the active editor.
Find and Replace in Arduino Code
| Task | Control | Result |
|---|---|---|
| Open Find | Ctrl + F | Finds text in the current code file. |
| Open Replace | Ctrl + H | Shows fields for the search and replacement text. |
| Previous or next result | Shift + Enter or Enter, or the on-screen buttons | Moves among matches. |
| Replace | Replace or Replace All | Changes the selected match or all matches in the current file. |
Match Case, Match Whole Word, and Regular Expression options are available.
Find and Replace in Ladder Logic
Focus the ladder grid and press Ctrl + F. Search the current ladder or all ladders for contact and coil addresses and code text in cells.
| Mode | Search target | Replace |
|---|---|---|
| General search | Addresses and cell code | Replace and Replace All are available |
| Whole word | Searching M1 excludes M10 | Finds complete addresses |
| Box-function search | Box-function command names | Finds exact command names; replacement is disabled |
7. Check Code Errors
When a new error or warning is added, you can inspect its message and location in the bottom Problems panel. If the panel is hidden, press Ctrl + J and select Problems.
- Read the badge on the Problems tab for the combined error and warning count.
- Read the severity and diagnostic message.
- Check the displayed file name and line and column numbers.
- Selecting a problem in the primary code file moves to that code location.
- 1 Problems and count: The combined number of errors and warnings.
- 2 Error message: The diagnostic text used to identify the cause.
- 3 File, line, and column: The location where the problem was found.
- 4 Code location: The line opened by selecting the problem.
For an error in an additional code file, read its file name and line number in Problems, then open that file directly from Explorer.
For the full build output and rebuilding a project, see Phase 1 · Create Your First Project.
8. Arduino Code Editing Shortcuts
Shortcuts can be changed under File → Preferences → Shortcuts.
| Task | Default shortcut | Where it applies |
|---|---|---|
| Open completion | Ctrl + Space | Code editor |
| Go to definition | F12 | Function or variable in code |
| Find | Ctrl + F | Code or ladder editor |
| Replace | Ctrl + H | Arduino Code editor |
| Show or hide bottom panel | Ctrl + J | Workspace |
| Rename code file | F2 or Enter | Additional code file in Explorer |
| Delete code file | Delete | Additional code file in Explorer |
| Move code file | Ctrl + ↑ or Ctrl + ↓ | Additional code file in Explorer |
F2, F12, Delete, and Ctrl + ↑ or Ctrl + ↓ can perform other actions when focus is elsewhere. Select the code area or file in Explorer before using them.
9. Troubleshooting
| Symptom | What to check |
|---|---|
| The completion list does not open. | Select the code editor, press Ctrl + Space, and check the spelling of the name. |
| A function from another code file is absent from completion. | Check the function name and braces, make sure both files belong to the same project, and wait for code analysis to finish. |
F12 does not open a definition. | Place the cursor on the name, focus Arduino Code, and check the code for syntax errors. |
| The definition view cannot be edited. | Arduino-core and library definitions open read-only. |
| The find interface is not the one expected. | Check whether Arduino Code or Ladder Logic is currently focused. |
| The first code file cannot be changed. | The project manages the first code file, so it cannot be renamed, deleted, or moved. |
| A problem in an additional code file does not open its line. | Read the file name and line in Problems and open the file directly from Explorer. |
Related Documentation
- Phase 1 · Create Your First Project — Build, upload, and build output
- Phase 2 · Understand Memory — Share PLC memory with Arduino Code
- Phase 3 · Ladder Editing Basics — Edit ladder cells, contacts, and coils
- Phase 4 · Box Functions — Box functions and Arduino function calls
