// Version 0.0
#define NUM_RELAYS 2
#define RELAY_PIN1 22
#define RELAY_PIN2 23
int relays[2] = { RELAY_PIN1, RELAY_PIN2 };
#define NUM_BUTTONS 2
#include "KTS_Button.h"
KTS_Button buttons[NUM_BUTTONS] = { 7, 6 };
enum Modes {
NORMAL = 0,
LOOP,
CC,
NUM_MODES
}; Modes mode = NORMAL;
char* modeNames[NUM_MODES] = { "Normal Mode", "Loop Mode", "CC Mode" };
void toggleState() {
static bool state = false;
state = !state;
Serial.print(F("State: "));
Serial.println(state ? "On" : "Off");
}
void changeModes(Modes newMode) {
mode = (mode == newMode ? NORMAL : newMode);
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:
switch(mode) {
case NORMAL:
toggleState();
break;
case LOOP:
if (i == 0) activateRelay(0);
else if (i == 1) activateRelay(1);
break;
case CC:
if (i == 0) runMenu();
else if (i == 1) incrementCounter();
break;
}
break;
case LONG_PRESS:
if (i == 0) changeModes(LOOP);
else if (i == 1) changeModes(CC);
break;
}
}
}