User Tools

Site Tools


en-us_products:mpino_studio2:code_editor

This is an old revision of the document!


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.

Arduino Code workflow from choosing a file to checking problems

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.

Arduino Code editor marked with the Code group, line numbers and folding, editing area, and minimap

  • 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.

Code file controls marked with add, primary file, additional file, and rename or delete menu

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 function constrain() to return its argument within the range 0 through 100.
  • Multiple .ino files 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)-S project.

limitValue function defined in control and called from the primary code file

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.

  1. Type the beginning of a function or variable name in the code editor.
  2. If the list does not open, press Ctrl + Space.
  3. Select an item with or .
  4. Insert the selected item with Enter or Tab.

In the preceding example, typing limitV lets you select limitValue() from the other code file.

limitV in the editor and the limitValue completion item

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.

Function call, definition opened with F12, and read-only state

  • 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

Comparison of find and replace in Arduino Code and Ladder Logic

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.

  1. Read the badge on the Problems tab for the combined error and warning count.
  2. Read the severity and diagnostic message.
  3. Check the displayed file name and line and column numbers.
  4. Selecting a problem in the primary code file moves to that code location.

Problems tab, error message, file and line location, and erroneous code line

  • 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.

Main Arduino Code editing 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.
en-us_products/mpino_studio2/code_editor.1789009453.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki