Topic: Input / Output Array
Hi!
I want to know if is possible to use app input and output (RemoteXY.button or .led) in an Array.
I try but unsuccesfully. The physics button and phisics LED are OK (switch ON with one press of button and OFF with another press of button and ON/OFF the corresponding led).
Can someone help me please for the remotexy code?
thanks
/////////////////////////////////////////////
// RemoteXY include library //
/////////////////////////////////////////////
/* RemoteXY select connection mode and include library */
#define REMOTEXY_MODE__ETHERNET_LIB
#include <Ethernet.h>
#include <SPI.h>
#include <RemoteXY.h>
/* RemoteXY connection settings */
#define REMOTEXY_ETHERNET_MAC "DE:AD:BE:EF:EF:ED"
#define REMOTEXY_SERVER_PORT 6377
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,3,0,3,0,51,0,8,13,0,
1,0,12,12,12,12,2,31,88,0,
1,0,31,12,12,12,2,31,88,0,
1,0,75,14,12,12,2,31,88,0,
65,4,13,29,9,9,65,4,33,29,
9,9,65,4,77,28,9,9 };
// this structure defines all the variables of your control interface
struct {
// input variable
uint8_t button_1; // =1 if button pressed, else =0
uint8_t button_2; // =1 if button pressed, else =0
uint8_t button_3; // =1 if button pressed, else =0
// output variable
uint8_t led_1_r; // =0..255 LED Red brightness
uint8_t led_2_r; // =0..255 LED Red brightness
uint8_t led_3_r; // =0..255 LED Red brightness
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
int buttPin[3] = {27,28,29}; // arrow for real switch button
int relayPin[3] = {30,31,32}; // arrow for real output relay
int buttRemote[3] = {RemoteXY.button_1,RemoteXY.button_2,RemoteXY.button_3}; //IS OK TO PUT THEM IN AN ARROW?
int ledRemote[3] = {RemoteXY.led_1_r,RemoteXY.led_2_r,RemoteXY.led_3_r}; //IS OK TO PUT THEM IN AN ARROW?
int lastButtState[3];
int buttState[3];
int debounceDelay = 50;
int ledState[3];
int reading[3];
int readingRemote[3];
unsigned long lastDebounceTime[3];
void setup()
{
RemoteXY_Init ();
for (int i = 0; i < 3; i++)
{
pinMode(relayPin[i], OUTPUT);
pinMode(buttPin[i], INPUT_PULLUP);
}
}
void loop()
{
RemoteXY_Handler ();
for (int i = 0; i < 3; i++) // I USE ARRAY BECAUSE I NEED IN THE FUTURE 16 INPUT/RELAYS TO USE
{
reading[i] = digitalRead(buttPin[i]);
// readingRemote[i] = digitalRead(buttRemote[i]);
if (reading[i] != lastButtState[i]) {
// if (reading[i] != lastButtState[i] || readingRemote[i] != lastButtState[i]) { // I NEED SWITCH ON or OFF with a change of phisic button or APP button
lastDebounceTime[i] = millis(); // for don't use DELAY functions i USE millis
lastButtState[i] = reading[i];
}
if ((millis() - lastDebounceTime[i]) > debounceDelay) {
if (buttState[i] != lastButtState[i]) {
buttState[i] = lastButtState[i];
if (buttState[i] == HIGH) {
ledState[i] = !ledState[i];
digitalWrite(relayPin[i], ledState[i]);
}
RemoteXY.led_1_r = (digitalRead(30)==HIGH)?255:0; // with a defined (ledRemote[i]) ARRAY i can't monitoring the led if I put it in for loop, so i use here succesfully
RemoteXY.led_2_r = (digitalRead(31)==HIGH)?255:0; // with a defined (ledRemote[i]) ARRAY i can't monitoring the led if I put it in for loop, so i use here succesfully
RemoteXY.led_3_r = (digitalRead(32)==HIGH)?255:0; // with a defined (ledRemote[i]) ARRAY i can't monitoring the led if I put it in for loop, so i use here succesfully
}
}
}
}