Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7a35be3

Browse filesBrowse files
committed
Added blink example with Wokwi embedded simulation
1 parent 078671d commit 7a35be3
Copy full SHA for 7a35be3

File tree

2 files changed

+110
-0
lines changed
Filter options

2 files changed

+110
-0
lines changed

‎docs/source/tutorials/blink.rst

Copy file name to clipboard
+109Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
##########################
2+
Blink Interactive Tutorial
3+
##########################
4+
5+
Introduction
6+
------------
7+
8+
This is the interactive blink tutorial using `Wokwi`_. For this tutorial you don't need the ESP32 board or the Arduino toolchain.
9+
10+
.. note:: If you don't want to use this tutorial with the simulation, you can copy and paste the code from `Wokwi`_ editor and use on the Arduino IDE or PlatformIO.
11+
12+
About this Tutorial
13+
-------------------
14+
15+
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.
16+
17+
Step by step
18+
------------
19+
20+
In order to make this simple blink tutorial, you'll need to do the following steps.
21+
22+
1. Define the GPIO for the LED.
23+
24+
.. code-block::
25+
26+
#define LED 2
27+
28+
This ``#define LED 2`` will be used to set the GPIO2 as the ``LED`` output pin.
29+
30+
2. Setup.
31+
32+
Inside the ``setup()`` function, we need to add all things we want to run once during the startup.
33+
Here we'll add the ``pinMode`` function to set the pin as output.
34+
35+
.. code-block::
36+
37+
void setup() {
38+
pinMode(LED, OUTPUT);
39+
}
40+
41+
The first argument is the GPIO number, already defined and the second is the mode, here defined as output.
42+
43+
3. Main Loop.
44+
45+
After the ``setup``, the code runs the ``loop`` function infinitely. Here we will handle the GPIO in order to get the LED blinking.
46+
47+
.. code-block::
48+
49+
void loop() {
50+
digitalWrite(LED, HIGH);
51+
delay(100);
52+
digitalWrite(LED, LOW);
53+
delay(100);
54+
}
55+
56+
The first function is the ``digitalWrite()`` with two arguments:
57+
58+
* GPIO: Set the GPIO pin. Here defined by our ``LED`` connected to the GPIO2.
59+
* State: Set the GPIO state as HIGH (on) or LOW (off).
60+
61+
This first ``digitalWrite`` we will set the LED on.
62+
63+
After the ``digitalWrite``, we will set a ``delay`` function in order to wait for some time, defined in milliseconds.
64+
65+
Now we can set the GPIO to ``LOW`` to turn the LED off and ``delay`` for more few milliseconds to get the LED blinking.
66+
67+
4. Run the code.
68+
69+
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.
70+
71+
Simulation
72+
----------
73+
74+
This simulator is provided by `Wokwi`_ and you can test the blink code and play with some modification to learn mode about this example.
75+
76+
.. raw:: html
77+
78+
<iframe src="https://wokwi.com/arduino/projects/305566932847821378?embed=1" width="100%" height="400" border="0"></iframe>
79+
80+
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.
81+
82+
Code
83+
----
84+
85+
Here is the full blink code.
86+
87+
.. code-block::
88+
89+
#define LED 2
90+
91+
void setup() {
92+
pinMode(LED, OUTPUT);
93+
}
94+
95+
void loop() {
96+
digitalWrite(LED, HIGH);
97+
delay(100);
98+
digitalWrite(LED, LOW);
99+
delay(100);
100+
}
101+
102+
Resources
103+
---------
104+
105+
* `ESP32 Datasheet`_ (Datasheet)
106+
* `Wokwi`_ (Wokwi Website)
107+
108+
.. _ESP32 Datasheet: https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf
109+
.. _Wokwi: https://wokwi.com/

‎docs/source/tutorials/tutorials.rst

Copy file name to clipboardExpand all lines: docs/source/tutorials/tutorials.rst
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Tutorials
66
:maxdepth: 2
77
:caption: Tutorials:
88

9+
Blink <blink>
910
Basic <basic>
1011
DFU <dfu>
1112
GPIO Matrix and Pin Mux <io_mux>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.