Like this?
// Version 0.0
#define NUM_BUTTONS 2
#define NUM_RELAYS 2
#define RELAY_PIN1 22
#define RELAY_PIN2 23
int relays[2] = {RELAY_PIN1, RELAY_PIN2};
#include "KTS_Button.h"
KTS_Button buttons[NUM_BUTTONS] = { 7, 6 };
enum Modes {
LOOP = 0,
EDIT,
NUM_MODES
}; Modes mode = LOOP;
char* modeNames[NUM_MODES] = { "Loop Mode", "Edit Mode" };
void cycleModes() {
mode = mode + 1;
if(mode == NUM_MODES)
mode = 0;
Serial.print(F("Mode Change: "));
Serial.println(modeNames[mode]);
}
void runMenu() {
Serial.println(F("Menu Active"));
}
void incrementCounter() {
static int counter = 0;
counter = (counter == 100 ? 0 : counter+1);
Serial.print(F("Counter is: "));
Serial.println(counter);
}
void activateRelay(int choice) {
digitalWrite(relays[choice], HIGH);
delay(100); // Or whatever you need
digitalWrite(relays[choice], LOW);
Serial.print(F("Relay: "));
Serial.print(choice);
Serial.println(F(" Activated"));
}
void setup() {
Serial.begin(9600);
for (int i = 0; i < NUM_RELAYS; i++)
pinMode(relays[i], OUTPUT);
}
void loop() {
for (int i = 0; i < NUM_BUTTONS; i++) {
switch (buttons[i].read()) {
case SINGLE_PRESS:
if (mode == LOOP)
activateRelay(i);
else if (mode == EDIT) {
if (i == 0) runMenu();
if (i == 1) incrementCounter();
}
break;
case LONG_PRESS:
cycleModes();
break;
}
}
}
By the way I don't think this is quite how I would solve it but just trying to get the logic down