upload switch
This commit is contained in:
parent
ddd9fd9577
commit
7c8f6fc9fc
1 changed files with 25 additions and 0 deletions
25
sketch_aug02a.ino
Normal file
25
sketch_aug02a.ino
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#include <Keyboard.h>
|
||||||
|
|
||||||
|
const int switchPin = 2; // Pin connected to the switch
|
||||||
|
int switchState = 0; // Variable to hold the switch
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
pinMode(switchPin, INPUT_PULLUP); // Set pin mode with internal pull-up resistor
|
||||||
|
Keyboard.begin(); // Begin keyboard communication
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Read the state of the switch
|
||||||
|
switchState = digitalRead(switchPin);
|
||||||
|
|
||||||
|
// Check if the switch is pressed (LOW due to pull-up resistor)
|
||||||
|
if (switchState == LOW) {
|
||||||
|
// Send the string "thisstring"
|
||||||
|
Keyboard.print("thisstring");
|
||||||
|
|
||||||
|
// Wait for the switch to be released
|
||||||
|
while (digitalRead(switchPin) == LOW) {
|
||||||
|
delay(10); // Debounce delay
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue