Dear Thorsten
I have been trying without success to produce a function which will reduce the amount of code considerably. I understand the concept, I think, but cannot implement it. I will show below a section of code derived from your previous suggestion. This is repeated about 10 times with changes of pin numbers and groupxselected
/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when an button has been toggled
// pin_value is 1 when button released, and 0 when button pressed
/////////////////////////////////////////////////////////////////////////////
unsigned char group1_selected;//Pedal group, Pins 19-25
unsigned char group2_selected;//Tremelo Fast, Pin 28
unsigned char group3_selected;//Sw_P Group, Pins 33-34
unsigned char group4_selected;//Sw_M Group, Pins 36-38
unsigned char group5_selected;//Sw_R Group, Pin 40
unsigned char group6_selected;//Gt_P Group, Pins 42-47
unsigned char group7_selected;//Gt_M Group, Pin 49
unsigned char group8_selected;//Gt_R Group, Pins 51-57
unsigned char group9_selected;// Pedal couplers pins 16 & 17
unsigned char group10_selected;// Pedal Sub-Octave pin 18
unsigned char group11_selected;// Tremelo Swell Select
unsigned char group12_selected;// Tremelo Great Select
void DIN_NotifyToggle(unsigned char pin, unsigned char pin_value) __wparam
{
unsigned char i;// used for MIOS_DOUT_PinSet0
//////// Pedal Radio Group///////
if( (pin >= 19 && pin <= 25) && (pin_value == 0)){
//if button already selected, turn off LED's
//this is identified with group1_selected = 0xFF
if(group1_selected == pin)
{
group1_selected = 0xFF;// all LED's Off
}else{
//save the selected button function of the group
group1_selected = pin ;}
//LED's should be cleared
for(i=19; i<= 25; i++)
MIOS_DOUT_PinSet0(i);
//set the LED which relates to the selected function
if(group1_selected != 0xFF)
MIOS_DOUT_PinSet1(group1_selected);
}else{
//////////Tremelo Fast/ Slow Push Button/////////
if( (pin >= 28 && pin <= 28) && (pin_value == 0)){
//if button already selected, turn off LED's
//this is identified with group2_selected = 0xFF
if(group2_selected == pin)
etc etc I think that it should be possible to add a function “ControlGroupLed” immediately after the line.
if( (pin >= 19 && pin <= 25) && (pin_value == 0)){
in each repeated section. There are 3 variables associated with each group, “lowest pin”, " highest pin" and “group’x’connected”.
From the different sections of DIN_NotifyToggle I would call ControlGroupLed (r,s,x) corresponding to the pins and identifying the relevant group’x’connected
After the “ControlGroupLed” I could call the "SendDump2 function.
I will be very grateful for your help.
Regards Robin
PS After sending this message it occurred to me that my Function “ControlGroupLed” needs only to be called with one variable ie groupxselected and that the other parameters could be loaded from an constant array above the function statement. Does this make sense?