Skip to content

The first program in the simulator

On three short examples, you will try output to the terminal, LED control and button reading. First, in Device → Processor, select Simulator and wait for the Ready status. Details about the panel can be found in simulator overview.

Do you want ready-made blocks straight away?

Open Blink LED in ESP IDE or LED Push Button in ESP IDE. The link loads the blocks as well as the Simulator processor. Save your own project in progress before opening it; the example will replace the blocks on the workspace. After loading, click on Run code.

1. Message in terminal

What you will learn: run a program and find its text output.

  1. Use block code that runs once from the Program category. If it's already on the workspace, don't add another one.
  2. From the Text category, attach the print block behind it.
  3. Type Hello, simulator! in its text field.
  4. Click on the green Run code.

A message appears in the terminal below the editor:

Hello, simulator!

The block after code that runs once is executed once at startup. If you also leave an empty block repeat forever on the workspace, the program continues to run in an empty loop, but does not repeat the message. You end it with the button Stop program.

Do you want to repeat the message?

Move the block print inside repeat forever and behind it connect from the category Time the block wait set to 1 second. The message will then be added approximately once per second. Without waiting, the terminal would fill up quickly.

2. Flashing LED

What you will learn: set the output to 1 and 0 and insert a delay between changes.

Use the LED labeled GPIO 1. It is already connected to the correct pin in the simulator.

  1. In the code section of the repeat forever block, insert the set digital output block from the Outputs category.
  2. Set the pin number to 1 and the value after the word to also to 1. This will light up the LED.
  3. After it, connect the wait block with the value 500 and the milliseconds unit from the Time category.
  4. Connect the second digital output: pin 1, value 0. This will turn off the LED.
  5. Add another wait of 500 milliseconds behind it.
  6. Click on Run code and watch the GPIO 1 LED. The

LED should be on for half a second and off for half a second. The entire cycle repeats approximately once per second. You can leave the message from the previous example for code that runs once; it will be written again every time it is restarted.

Block program for flashing GPIO 1 LED, simulator panel and terminal listing

Settings Meaning
Pin 1 LED controlled GPIO number. It is not the order of the command.
Value 1 Turns on this LED.
Value 0 Turns off this LED.
Waiting 500 milliseconds It will keep the previous state for about half a second.

Watch out for the unit of time

A value of 500 with unit seconds indicates a wait of over eight minutes. For this example, select milliseconds in the roller. If the program seems to freeze after the LED lights up, check the selected time unit.

Try changing both waits to 100 milliseconds and run the program again. The LED will flash faster. Changing a block on the workspace does not by itself modify the running program.

3. LED controlled by button

What you will learn: read the input and select one of the two actions according to its value.

Use GPIO Button 17 and the same GPIO 1 LED. This time, the LED should only be lit for as long as you hold down the Press button.

Detecting a button press

GPIO button status 17 Digital input value
Released 1
Pressed 0

This reversal is not an error. Pressing the button is active at zero in this connection. Therefore, in the program we test whether the input is equal to 0.

Building the program

  1. Remove previous flashing from repeat forever. Don't let two different processes control the same LED.
  2. From the Logic category, insert the if block. Using its gear, add the else branch.
  3. Insert the comparison = from the category Logic into the condition.
  4. On the left side of the comparison, insert the logic state of a digital pin block from the Inputs category and set pin 17. Put the number 0 on the right side.
  5. Insert a digital output with pin 1 and value 1 into branch do.
  6. Insert a digital output with pin 1 and value 0 into branch else.
  7. After the entire block if, still inside repeat forever, add a wait of 20 milliseconds.
  8. Run the program. In the panel, find GPIO button 17, press its button Press and hold it for a while.

GPIO 1 LED lights up when held and turns off when released. The condition is checked repeatedly; a short wait will leave room for servicing other activities as well.

Condition compares GPIO input 17 to zero; when the button is held, the GPIO 1 LED lights up

Why is there a different branch

The command to turn on the LED itself does not say what to do after the button is released. Branch else explicitly turns it off. Without it, the LED would remain lit after the first press.

How to exit and save the attempt

Click on Stop program. This ends the run in the simulator and cancels its variables, but the blocks remain in the editor. Another click on Run code will start the program again from the beginning.

Save your project via Project → Save to PC. You can later reopen and edit the saved file .blk. Running the program itself does not save this block project to the computer.

Further explanation of the blocks used: after start, repeat always, digital output and digital input.

Once you've mastered these trials, proceed to simulator virtual parts. Try the analog slider and you will find the connection of the joystick, display and drives there.