Skip to content

Commit e25ea6b

Browse files
committed
Use standardized pin macros in Nano ESP32 "default" sketch
This sketch is intended to produce the LED blinking behavior the board has when shipped. Previously, bespoke pin name macros were defined in the sketch, which were problematic: The green and blue LED pin numbers were only appropriate for the first limited run of the board that used a different RGB LED than the LED on subsequent runs of the board, which the majority of customers will have. The pin numbers were not correct when the development tool had the "By Arduino pin (default)" pin numbering configuration. The "Arduino ESP32 Boards" core provides pin macros for all four of the LEDs. Using these macros in the sketch sets an example of best practices programming for the reader and fixes both the problems that were present in the previous version of the sketch: The LED_GREEN and LED_BLUE are the correct pin numbers for the LEDs on the majority of the Nano ESP32 boards. These macros are configured to be correct for both pin numbering configurations.
1 parent efe5356 commit e25ea6b

File tree

1 file changed

+12
-20
lines changed
  • content/hardware/03.nano/boards/nano-esp32/tutorials/cheat-sheet

1 file changed

+12
-20
lines changed

content/hardware/03.nano/boards/nano-esp32/tutorials/cheat-sheet/cheat-sheet.md

+12-20
Original file line numberDiff line numberDiff line change
@@ -112,41 +112,33 @@ If you need to reflash the bootloader, you can follow the steps of this [Help Ce
112112
The default sketch loaded on the Nano ESP32 board is found in the code snippet below:
113113

114114
```arduino
115-
#define LEDR 46
116-
#define LEDG 45
117-
#define LEDB 0
118-
#ifdef LED_BUILTIN
119-
#undef LED_BUILTIN
120-
#define LED_BUILTIN 48
121-
#endif
122-
123115
void setup() {
124116
// put your setup code here, to run once:
125-
pinMode(LEDR, OUTPUT);
126-
pinMode(LEDG, OUTPUT);
127-
pinMode(LEDB, OUTPUT);
117+
pinMode(LED_RED, OUTPUT);
118+
pinMode(LED_GREEN, OUTPUT);
119+
pinMode(LED_BLUE, OUTPUT);
128120
pinMode(LED_BUILTIN, OUTPUT);
129121
}
130122
131123
void loop() {
132124
digitalWrite(LED_BUILTIN, HIGH);
133-
digitalWrite(LEDR, LOW);
134-
digitalWrite(LEDG, HIGH);
135-
digitalWrite(LEDB, HIGH);
125+
digitalWrite(LED_RED, LOW);
126+
digitalWrite(LED_GREEN, HIGH);
127+
digitalWrite(LED_BLUE, HIGH);
136128
137129
delay(1000);
138130
139131
digitalWrite(LED_BUILTIN, LOW);
140-
digitalWrite(LEDR, HIGH);
141-
digitalWrite(LEDG, LOW);
142-
digitalWrite(LEDB, HIGH);
132+
digitalWrite(LED_RED, HIGH);
133+
digitalWrite(LED_GREEN, LOW);
134+
digitalWrite(LED_BLUE, HIGH);
143135
144136
delay(1000);
145137
146138
digitalWrite(LED_BUILTIN, HIGH);
147-
digitalWrite(LEDR, HIGH);
148-
digitalWrite(LEDG, HIGH);
149-
digitalWrite(LEDB, LOW);
139+
digitalWrite(LED_RED, HIGH);
140+
digitalWrite(LED_GREEN, HIGH);
141+
digitalWrite(LED_BLUE, LOW);
150142
151143
delay(1000);
152144
digitalWrite(LED_BUILTIN, LOW);

0 commit comments

Comments
 (0)