each button represents a different relay, when the button is clicked, a formula has to be computed, then sent to the external card.
ie press 1 for relay one, so 1 is sent to the following
Code:
int GetBox(int Relay)
{
int V = Relay;
int Box = 1;
do
{
if (V > 8)
{
Box++;
V = V - 8;
}
}while (V > 8 );
return Box;
}
then relay and box is sent to
Code:
int GetChannel(int Relay,int Box)
{
int Channel = Relay-((Box-1)*8);
return Channel;
}
then channel and box sent to make mask (dont worry, array is being changed also)
Code:
void SetMask(int Channel, int Box)
{
int MaskHolder;
switch (Channel)
{
case 1:
MaskHolder = 1;
break;
case 2:
MaskHolder = 2;
break;
case 3:
MaskHolder = 4;
break;
case 4:
MaskHolder = 8;
break;
case 5:
MaskHolder = 16;
break;
case 6:
MaskHolder = 32;
break;
case 7:
MaskHolder = 64;
break;
case 8:
MaskHolder = 128;
break;
}
Boxes[Box].Word = Boxes[Box].Word ^ MaskHolder;
}
then all sent to the relay controller in a 6 pass write set up...
Code:
void SetRelays(int Box)
{
if (Simulation == 0)
{
int Bank,BankBox;
if(Box >= 1 && Box <= 8){ Bank = 8; BankBox = Box-1; }
if(Box >= 9 && Box <= 16){ Bank = 16; BankBox = Box-9; }
if(Box >= 17 && Box <= 24){ Bank = 32; BankBox = Box-17; }
if(Box >= 25 && Box <= 32){ Bank = 64; BankBox = Box-25; }
if(Box >= 33 && Box <= 40){ Bank = 128; BankBox = Box-33; }
WriteAllDigital(Boxes[Box].Word);
SetAnalogChannel(1);
ClearAnalogChannel(1);
WriteAllDigital(Bank+BankBox);
SetAnalogChannel(2);
ClearAnalogChannel(2);
ClearAllDigital();
}
}
i want to call these functions, instead of putting all of this onto each button!
dont want all this code, 320 times!