Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- -- New project --
- This source code of graphical user interface
- has been generated automatically by RemoteXY editor.
- To compile this code using RemoteXY library 3.1.13 or later version
- download by link http://remotexy.com/en/library/
- To connect using RemoteXY mobile app by link http://remotexy.com/en/download/
- - for ANDROID 4.15.01 or later version;
- - for iOS 1.12.1 or later version;
- This source code is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- */
- //////////////////////////////////////////////
- // RemoteXY include library //
- //////////////////////////////////////////////
- // you can enable debug logging to Serial at 115200
- //#define REMOTEXY__DEBUGLOG
- // RemoteXY select connection mode and include library
- #define REMOTEXY_MODE__SOFTSERIAL
- #include <SoftwareSerial.h>
- // RemoteXY connection settings
- #define REMOTEXY_SERIAL_RX 2
- #define REMOTEXY_SERIAL_TX 3
- #define REMOTEXY_SERIAL_SPEED 9600
- // Define the relay pin
- #define RELAY_PIN 4 // Change this to the pin your relay is connected to
- #include <RemoteXY.h>
- // RemoteXY GUI configuration
- #pragma pack(push, 1)
- uint8_t RemoteXY_CONF[] = // 37 bytes
- { 255,1,0,0,0,30,0,19,0,0,0,0,31,1,106,200,1,1,1,0,
- 1,30,33,43,43,0,36,31,79,112,101,110,32,66,111,120,0 };
- // this structure defines all the variables and events of your control interface
- struct {
- // input variables
- uint8_t button_01; // =1 if button pressed, else =0
- // other variable
- uint8_t connect_flag; // =1 if wire connected, else =0
- } RemoteXY;
- #pragma pack(pop)
- // Variables for relay control
- unsigned long relayStartTime = 0;
- bool relayActive = false;
- const unsigned long relayDuration = 3000; // 3 seconds relay activation time
- void setup()
- {
- RemoteXY_Init();
- pinMode(RELAY_PIN, OUTPUT);
- digitalWrite(RELAY_PIN, LOW); // Ensure relay is off initially
- }
- void loop()
- {
- RemoteXY_Handler();
- // Check if button is pressed and relay is not already active
- if (RemoteXY.button_01 && !relayActive) {
- relayActive = true;
- relayStartTime = millis();
- digitalWrite(RELAY_PIN, HIGH); // Turn on relay
- RemoteXY.button_01 = 0; // Reset button state
- }
- // Check if relay has been active for the required duration
- if (relayActive && (millis() - relayStartTime >= relayDuration)) {
- relayActive = false;
- digitalWrite(RELAY_PIN, LOW); // Turn off relay
- }
- // Use RemoteXY_delay instead of delay if needed
- // RemoteXY_delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment