Skip to content

Commit 4f94154

Browse files
authored
Adds missing pinMode (#8312)
* Adds missing pinMode The example code lacks a pinMode() to initialize the GPIO 0 (button). In Arduino Core 3.0.0, it prints an error message when trying to read a not initialized GPIO. * Update KeyboardLogout.ino Adds <buttonPin> to keep code standard * Update KeyboardReprogram.ino Adds <buttonPin> to keep code standard
1 parent c34f850 commit 4f94154

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

Diff for: libraries/USB/examples/CompositeDevice/CompositeDevice.ino

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ void setup() {
166166
HWSerial.begin(115200);
167167
HWSerial.setDebugOutput(true);
168168

169+
pinMode(buttonPin, INPUT_PULLUP);
170+
169171
USB.onEvent(usbEventCallback);
170172
USBSerial.onEvent(usbEventCallback);
171173
MSC_Update.onEvent(usbEventCallback);

Diff for: libraries/USB/examples/Keyboard/KeyboardLogout/KeyboardLogout.ino

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,18 @@ USBHIDKeyboard Keyboard;
4141
// change this to match your platform:
4242
int platform = OSX;
4343

44+
const int buttonPin = 0; // input pin for pushbutton
45+
4446
void setup() {
4547
// make pin 0 an input and turn on the pull-up resistor so it goes high unless
4648
// connected to ground:
47-
pinMode(0, INPUT_PULLUP);
49+
pinMode(buttonPin, INPUT_PULLUP);
4850
Keyboard.begin();
4951
USB.begin();
5052
}
5153

5254
void loop() {
53-
while (digitalRead(0) == HIGH) {
55+
while (digitalRead(buttonPin) == HIGH) {
5456
// do nothing until pin 2 goes low
5557
delay(500);
5658
}

Diff for: libraries/USB/examples/Keyboard/KeyboardReprogram/KeyboardReprogram.ino

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ void loop(){}
3434
#include "USBHIDKeyboard.h"
3535
USBHIDKeyboard Keyboard;
3636

37+
const int buttonPin = 0; // input pin for pushbutton
38+
3739
// use this option for OSX.
3840
// Comment it out if using Windows or Linux:
3941
char ctrlKey = KEY_LEFT_GUI;
@@ -45,14 +47,14 @@ char ctrlKey = KEY_LEFT_GUI;
4547
void setup() {
4648
// make pin 0 an input and turn on the pull-up resistor so it goes high unless
4749
// connected to ground:
48-
pinMode(0, INPUT_PULLUP);
50+
pinMode(buttonPin, INPUT_PULLUP);
4951
// initialize control over the keyboard:
5052
Keyboard.begin();
5153
USB.begin();
5254
}
5355

5456
void loop() {
55-
while (digitalRead(0) == HIGH) {
57+
while (digitalRead(buttonPin) == HIGH) {
5658
// do nothing until pin 0 goes low
5759
delay(500);
5860
}

0 commit comments

Comments
 (0)