safwan092

Untitled

Apr 19th, 2025
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. /*
  2. -- New project --
  3.  
  4. This source code of graphical user interface
  5. has been generated automatically by RemoteXY editor.
  6. To compile this code using RemoteXY library 3.1.13 or later version
  7. download by link http://remotexy.com/en/library/
  8. To connect using RemoteXY mobile app by link http://remotexy.com/en/download/
  9. - for ANDROID 4.15.01 or later version;
  10. - for iOS 1.12.1 or later version;
  11.  
  12. This source code is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU Lesser General Public
  14. License as published by the Free Software Foundation; either
  15. version 2.1 of the License, or (at your option) any later version.
  16. */
  17.  
  18. //////////////////////////////////////////////
  19. // RemoteXY include library //
  20. //////////////////////////////////////////////
  21.  
  22. // you can enable debug logging to Serial at 115200
  23. //#define REMOTEXY__DEBUGLOG
  24.  
  25. // RemoteXY select connection mode and include library
  26. #define REMOTEXY_MODE__SOFTSERIAL
  27.  
  28. #include <SoftwareSerial.h>
  29.  
  30. // RemoteXY connection settings
  31. #define REMOTEXY_SERIAL_RX 2
  32. #define REMOTEXY_SERIAL_TX 3
  33. #define REMOTEXY_SERIAL_SPEED 9600
  34.  
  35. // Define the relay pin
  36. #define RELAY_PIN 4 // Change this to the pin your relay is connected to
  37.  
  38. #include <RemoteXY.h>
  39.  
  40. // RemoteXY GUI configuration
  41. #pragma pack(push, 1)
  42. uint8_t RemoteXY_CONF[] = // 37 bytes
  43. { 255,1,0,0,0,30,0,19,0,0,0,0,31,1,106,200,1,1,1,0,
  44. 1,30,33,43,43,0,36,31,79,112,101,110,32,66,111,120,0 };
  45.  
  46. // this structure defines all the variables and events of your control interface
  47. struct {
  48. // input variables
  49. uint8_t button_01; // =1 if button pressed, else =0
  50.  
  51. // other variable
  52. uint8_t connect_flag; // =1 if wire connected, else =0
  53. } RemoteXY;
  54. #pragma pack(pop)
  55.  
  56. // Variables for relay control
  57. unsigned long relayStartTime = 0;
  58. bool relayActive = false;
  59. const unsigned long relayDuration = 3000; // 3 seconds relay activation time
  60.  
  61. void setup()
  62. {
  63. RemoteXY_Init();
  64. pinMode(RELAY_PIN, OUTPUT);
  65. digitalWrite(RELAY_PIN, LOW); // Ensure relay is off initially
  66. }
  67.  
  68. void loop()
  69. {
  70. RemoteXY_Handler();
  71.  
  72. // Check if button is pressed and relay is not already active
  73. if (RemoteXY.button_01 && !relayActive) {
  74. relayActive = true;
  75. relayStartTime = millis();
  76. digitalWrite(RELAY_PIN, HIGH); // Turn on relay
  77. RemoteXY.button_01 = 0; // Reset button state
  78. }
  79.  
  80. // Check if relay has been active for the required duration
  81. if (relayActive && (millis() - relayStartTime >= relayDuration)) {
  82. relayActive = false;
  83. digitalWrite(RELAY_PIN, LOW); // Turn off relay
  84. }
  85.  
  86. // Use RemoteXY_delay instead of delay if needed
  87. // RemoteXY_delay(10);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment