Skip to content

Commit

Permalink
Adds missing pinMode (#8312)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SuGlider authored Jun 13, 2023
1 parent c34f850 commit 4f94154
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions libraries/USB/examples/CompositeDevice/CompositeDevice.ino
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ void setup() {
HWSerial.begin(115200);
HWSerial.setDebugOutput(true);

pinMode(buttonPin, INPUT_PULLUP);

USB.onEvent(usbEventCallback);
USBSerial.onEvent(usbEventCallback);
MSC_Update.onEvent(usbEventCallback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ USBHIDKeyboard Keyboard;
// change this to match your platform:
int platform = OSX;

const int buttonPin = 0; // input pin for pushbutton

void setup() {
// make pin 0 an input and turn on the pull-up resistor so it goes high unless
// connected to ground:
pinMode(0, INPUT_PULLUP);
pinMode(buttonPin, INPUT_PULLUP);
Keyboard.begin();
USB.begin();
}

void loop() {
while (digitalRead(0) == HIGH) {
while (digitalRead(buttonPin) == HIGH) {
// do nothing until pin 2 goes low
delay(500);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ void loop(){}
#include "USBHIDKeyboard.h"
USBHIDKeyboard Keyboard;

const int buttonPin = 0; // input pin for pushbutton

// use this option for OSX.
// Comment it out if using Windows or Linux:
char ctrlKey = KEY_LEFT_GUI;
Expand All @@ -45,14 +47,14 @@ char ctrlKey = KEY_LEFT_GUI;
void setup() {
// make pin 0 an input and turn on the pull-up resistor so it goes high unless
// connected to ground:
pinMode(0, INPUT_PULLUP);
pinMode(buttonPin, INPUT_PULLUP);
// initialize control over the keyboard:
Keyboard.begin();
USB.begin();
}

void loop() {
while (digitalRead(0) == HIGH) {
while (digitalRead(buttonPin) == HIGH) {
// do nothing until pin 0 goes low
delay(500);
}
Expand Down

0 comments on commit 4f94154

Please sign in to comment.