-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Docs integration with Wokwi - Blink Tutorial #5685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pedrominatel
merged 4 commits into
espressif:master
from
pedrominatel:docs/integration_with_wokwi
Sep 21, 2021
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7a35be3
Added blink example with Wokwi embedded simulation
pedrominatel e1cdbd7
Minor changes on the blink tutorial
pedrominatel 8be2f7b
Changes according to the PR review
pedrominatel 1f4dd7f
Merge branch 'master' into docs/integration_with_wokwi
pedrominatel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
########################## | ||
Blink Interactive Tutorial | ||
########################## | ||
|
||
Introduction | ||
------------ | ||
|
||
This is the interactive blink tutorial using `Wokwi`_. For this tutorial, you don't need the ESP32 board or the Arduino toolchain. | ||
|
||
.. note:: If you don't want to use this tutorial with the simulation, you can copy and paste the :ref:`blink_example_code` from `Wokwi`_ editor and use on the Arduino IDE or PlatformIO. | ||
|
||
About this Tutorial | ||
------------------- | ||
|
||
This tutorial is the most basic for any getting started. In this tutorial, we will show how to set a GPIO pin as output to drive a LED to blink each 1 second. | ||
|
||
Step by step | ||
------------ | ||
|
||
In order to make this simple blink tutorial, you'll need to do the following steps. | ||
|
||
1. Define the GPIO for the LED. | ||
pedrominatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. code-block:: | ||
|
||
#define LED 2 | ||
|
||
This ``#define LED 2`` will be used to set the GPIO2 as the ``LED`` output pin. | ||
|
||
2. Setup. | ||
|
||
Inside the ``setup()`` function, we need to add all things we want to run once during the startup. | ||
Here we'll add the ``pinMode`` function to set the pin as output. | ||
|
||
.. code-block:: | ||
|
||
void setup() { | ||
pinMode(LED, OUTPUT); | ||
} | ||
|
||
The first argument is the GPIO number, already defined and the second is the mode, here defined as output. | ||
|
||
3. Main Loop. | ||
|
||
After the ``setup``, the code runs the ``loop`` function infinitely. Here we will handle the GPIO in order to get the LED blinking. | ||
|
||
.. code-block:: | ||
|
||
void loop() { | ||
digitalWrite(LED, HIGH); | ||
delay(100); | ||
digitalWrite(LED, LOW); | ||
delay(100); | ||
} | ||
|
||
The first function is the ``digitalWrite()`` with two arguments: | ||
|
||
* GPIO: Set the GPIO pin. Here defined by our ``LED`` connected to the GPIO2. | ||
* State: Set the GPIO state as HIGH (on) or LOW (off). | ||
|
||
This first ``digitalWrite`` we will set the LED on. | ||
|
||
After the ``digitalWrite``, we will set a ``delay`` function in order to wait for some time, defined in milliseconds. | ||
|
||
Now we can set the GPIO to ``LOW`` to turn the LED off and ``delay`` for more few milliseconds to get the LED blinking. | ||
|
||
4. Run the code. | ||
|
||
To run this code, you'll need a development board and the Arduino toolchain installed in your computer. If you don't have both, you can use the simulator to test and edit the code. | ||
|
||
Simulation | ||
---------- | ||
|
||
This simulator is provided by `Wokwi`_ and you can test the blink code and play with some modification to learn mode about this example. | ||
pedrominatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. raw:: html | ||
|
||
<iframe src="https://wokwi.com/arduino/projects/305566932847821378?embed=1" width="100%" height="400" border="0"></iframe> | ||
|
||
Change the parameters, like the delay period, to test the code right on your browser. You can add more LEDs, change the GPIO and more. | ||
|
||
.. _blink_example_code: | ||
|
||
Example Code | ||
------------ | ||
|
||
Here is the full blink code. | ||
|
||
.. code-block:: | ||
|
||
#define LED 2 | ||
|
||
void setup() { | ||
pinMode(LED, OUTPUT); | ||
} | ||
|
||
void loop() { | ||
digitalWrite(LED, HIGH); | ||
delay(100); | ||
digitalWrite(LED, LOW); | ||
delay(100); | ||
} | ||
|
||
Resources | ||
--------- | ||
|
||
* `ESP32 Datasheet`_ (Datasheet) | ||
* `Wokwi`_ (Wokwi Website) | ||
|
||
.. _ESP32 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf | ||
.. _Wokwi: https://wokwi.com/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.