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