From ac0585c7755655f2b6868e4d0503013fcd633525 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 1 Jul 2021 14:03:14 +0200 Subject: [PATCH] Add arduino sketch --- kbdswitch.ino | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 kbdswitch.ino diff --git a/kbdswitch.ino b/kbdswitch.ino new file mode 100644 index 0000000..af8bff8 --- /dev/null +++ b/kbdswitch.ino @@ -0,0 +1,21 @@ +#define LED_PIN 1 // LED inside the pushbutton. +#define RELAY_PIN 3 // Pin, the relay (transistor) is connected to. +#define SWITCH_PIN 2 // The actual pushbutton. + +bool relay_on = 0; +uint16_t debounce_time = 450; // In ms. Adjust, if desired. + +void setup() { + pinMode(LED_PIN, OUTPUT); + pinMode(RELAY_PIN, OUTPUT); + pinMode(SWITCH_PIN, INPUT_PULLUP); // Saves some space on the PCB. +} + +void loop() { + if (digitalRead(SWITCH_PIN) == LOW) { + relay_on ^= 1; // Toggle the relay state. + digitalWrite(RELAY_PIN, relay_on); + digitalWrite(LED_PIN, relay_on); // One could switch the LED state around if desired. + delay(debounce_time); // Simple switch debouncing. + } +}