I copied the array and i have the variables that are from the structure. My code still works fine, but value indicators are switched up
RemoteXY Code:
/*
-- v4 --
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 10
#define REMOTEXY_SERIAL_TX 11
#define REMOTEXY_SERIAL_SPEED 9600
#include <RemoteXY.h>
// RemoteXY GUI configuration
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] = // 206 bytes
{ 255,10,0,8,0,199,0,19,0,0,0,0,31,1,106,200,1,1,14,0,
2,4,13,29,13,0,2,26,31,31,79,78,0,79,70,70,0,2,4,37,
31,12,0,2,26,31,31,79,78,0,79,70,70,0,129,9,4,16,9,64,
17,76,69,68,0,129,8,30,21,7,64,17,69,110,97,98,108,101,0,2,
89,5,11,6,0,2,26,31,31,79,78,0,79,70,70,0,2,89,14,12,
5,0,2,26,31,31,79,78,0,79,70,70,0,4,21,99,14,67,0,2,
26,4,69,99,15,66,0,2,26,129,16,171,23,8,64,24,83,112,101,101,
100,0,129,61,171,32,8,64,8,68,105,115,116,97,110,99,101,0,67,8,
92,40,10,78,2,26,2,67,56,92,40,10,78,2,26,2,7,53,39,40,
10,110,64,2,26,2,2,129,54,31,39,7,64,17,83,119,105,116,99,104,
32,84,105,109,101,0 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
uint8_t LED; // =1 if switch ON and =0 if OFF
uint8_t enable; // =1 if switch ON and =0 if OFF
uint8_t dir; // =1 if switch ON and =0 if OFF
uint8_t step; // =1 if switch ON and =0 if OFF
int8_t Speed; // from 0 to 100
int8_t Distance; // from 0 to 100
float switchTime;
// output variables
float speed_indicator;
float distance_indicator;
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define PIN_LED 13
#define PIN_ENABLE 4
#define PIN_DIR 2
#define PIN_STEP 3
void setup()
{
RemoteXY_Init ();
pinMode (PIN_LED, OUTPUT);
pinMode (PIN_ENABLE, OUTPUT);
pinMode (PIN_DIR, OUTPUT);
pinMode (PIN_STEP, OUTPUT);
// TODO you setup code
}
void loop()
{
RemoteXY_Handler ();
digitalWrite(PIN_LED, (RemoteXY.LED==0)?LOW:HIGH);
digitalWrite(PIN_ENABLE, (RemoteXY.enable==0)?LOW:HIGH);
digitalWrite(PIN_DIR, (RemoteXY.dir==0)?LOW:HIGH);
digitalWrite(PIN_STEP, (RemoteXY.step==0)?LOW:HIGH);
// TODO you loop code
// use the RemoteXY structure for data transfer
// do not call delay(), use instead RemoteXY_delay()
}
my code:
#define REMOTEXY_MODE__SOFTSERIAL
#include <SoftwareSerial.h>
#define REMOTEXY_SERIAL_RX 10
#define REMOTEXY_SERIAL_TX 11
#define REMOTEXY_SERIAL_SPEED 9600
#include <RemoteXY.h>
// RemoteXY configuration structure
#pragma pack(push, 1)
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] = // 206 bytes
{ 255,10,0,8,0,199,0,19,0,0,0,0,31,1,106,200,1,1,14,0,
2,4,13,29,13,0,2,26,31,31,79,78,0,79,70,70,0,2,4,37,
31,12,0,2,26,31,31,79,78,0,79,70,70,0,129,9,4,16,9,64,
17,76,69,68,0,129,8,30,21,7,64,17,69,110,97,98,108,101,0,2,
89,5,11,6,0,2,26,31,31,79,78,0,79,70,70,0,2,89,14,12,
5,0,2,26,31,31,79,78,0,79,70,70,0,4,21,99,14,67,0,2,
26,4,69,99,15,66,0,2,26,129,16,171,23,8,64,24,83,112,101,101,
100,0,129,61,171,32,8,64,8,68,105,115,116,97,110,99,101,0,67,8,
92,40,10,78,2,26,2,67,56,92,40,10,78,2,26,2,7,53,39,40,
10,110,64,2,26,2,2,129,54,31,39,7,64,17,83,119,105,116,99,104,
32,84,105,109,101,0 };
struct {
uint8_t LED;
uint8_t enable;
uint8_t dir;
uint8_t step;
int8_t Speed;
int8_t Distance;
float speed_indicator;
float distance_indicator;
uint8_t connect_flag;
float switch_time;
} RemoteXY;
#pragma pack(pop)
#define PIN_LED 13
#define PIN_ENABLE 4
#define PIN_DIR 2
#define PIN_STEP 3
unsigned long previousStepTime = 0;
int stepCounter = 0;
int targetSteps = 0;
bool currentDirection = true; // true for one direction, false for the other
void setup() {
RemoteXY_Init();
pinMode(PIN_LED, OUTPUT);
pinMode(PIN_ENABLE, OUTPUT);
pinMode(PIN_DIR, OUTPUT);
pinMode(PIN_STEP, OUTPUT);
digitalWrite(PIN_ENABLE, LOW); // Enable the driver
}
void loop() {
RemoteXY_Handler();
// Update indicators and LED
RemoteXY.speed_indicator = map(RemoteXY.Speed, 1, 100, 5000, 500);
RemoteXY.distance_indicator = map(RemoteXY.Distance, 1, 100, 0, 16000);
digitalWrite(PIN_LED, (RemoteXY.LED==0)?LOW:HIGH);
// Control motor
digitalWrite(PIN_ENABLE, (RemoteXY.enable==0)?HIGH:LOW); // Enable is active LOW
if (RemoteXY.enable == 1) { // If motor is enabled
unsigned long currentMicros = micros();
if (currentMicros - previousStepTime >= RemoteXY.speed_indicator) {
previousStepTime = currentMicros;
if (stepCounter < RemoteXY.distance_indicator) {
digitalWrite(PIN_DIR, currentDirection ? HIGH : LOW);
digitalWrite(PIN_STEP, HIGH);
delayMicroseconds(2); // Short delay for the step pulse
digitalWrite(PIN_STEP, LOW);
stepCounter++;
} else {
// Change direction and reset counter when target is reached
currentDirection = !currentDirection;
stepCounter = 0;
}
}
} else {
stepCounter = 0; // Reset counter when motor is disabled
}
}