From 7c8f6fc9fcab9544fa0055ea5d20926a79c0204a Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 2 Aug 2024 16:42:04 -0700 Subject: [PATCH] upload switch --- sketch_aug02a.ino | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 sketch_aug02a.ino diff --git a/sketch_aug02a.ino b/sketch_aug02a.ino new file mode 100644 index 0000000..e73fe83 --- /dev/null +++ b/sketch_aug02a.ino @@ -0,0 +1,25 @@ +#include + +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 + } + } +}