Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Relay Control
- - Source Code NOT compiled for: Arduino Mega
- - Source Code created on: 2024-10-16 14:24:56
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* PIN 28 Relais, PIN 30 Taster. Schreiben einen Code */
- /* dass wenn ich den Taster das erste mal betätige */
- /* das relais einmal schaltet und bleibt, wenn ich */
- /* das zweite mal drücke soll dass Relais erst nach 2 */
- /* Sekunden schalten und warten bis ich das nächste */
- /* mal */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> // https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t RELAY_PIN = 28; // Pin for the relay
- const uint8_t BUTTON_PIN = 30; // Pin for the button
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Instance of the button using the EasyButton library.
- EasyButton button(BUTTON_PIN); // Initialize the EasyButton object with the defined button pin
- // State variable to track the relay status
- bool relayState = false; // Relay is initially off
- bool firstPress = true; // Variable to track if it's the first press
- void setup(void)
- {
- // Set the relay pin as output
- pinMode(RELAY_PIN, OUTPUT);
- digitalWrite(RELAY_PIN, LOW); // Ensure relay is off initially
- // Set the button pin as input with pull-up resistor
- pinMode(BUTTON_PIN, INPUT_PULLUP);
- // Initialize the button.
- button.begin();
- }
- void loop(void)
- {
- // Continuously read the status of the button.
- button.read();
- // Check if the button was pressed
- if (button.wasPressed()) {
- if (firstPress) {
- // If it's the first press, turn on the relay
- digitalWrite(RELAY_PIN, HIGH); // Turn on the relay
- relayState = true; // Update the relay state
- firstPress = false; // Change state to indicate first press is done
- } else {
- // If it's the second press, wait for 2 seconds before turning it off
- delay(2000); // Wait for 2 seconds
- digitalWrite(RELAY_PIN, LOW); // Turn off the relay
- relayState = false; // Update the relay state
- firstPress = true; // Reset for the next cycle
- }
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement