Browse Source

Add arduino sketch

master
Lukas 3 years ago
parent
commit
ac0585c775
1 changed files with 21 additions and 0 deletions
  1. +21
    -0
      kbdswitch.ino

+ 21
- 0
kbdswitch.ino View File

@@ -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.
}
}

Loading…
Cancel
Save