A quick an easy keyboard switching thingy.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

22 lines
693 B

  1. #define LED_PIN 1 // LED inside the pushbutton.
  2. #define RELAY_PIN 3 // Pin, the relay (transistor) is connected to.
  3. #define SWITCH_PIN 2 // The actual pushbutton.
  4. bool relay_on = 0;
  5. uint16_t debounce_time = 450; // In ms. Adjust, if desired.
  6. void setup() {
  7. pinMode(LED_PIN, OUTPUT);
  8. pinMode(RELAY_PIN, OUTPUT);
  9. pinMode(SWITCH_PIN, INPUT_PULLUP); // Saves some space on the PCB.
  10. }
  11. void loop() {
  12. if (digitalRead(SWITCH_PIN) == LOW) {
  13. relay_on ^= 1; // Toggle the relay state.
  14. digitalWrite(RELAY_PIN, relay_on);
  15. digitalWrite(LED_PIN, relay_on); // One could switch the LED state around if desired.
  16. delay(debounce_time); // Simple switch debouncing.
  17. }
  18. }