#include <serialStr.h>
#define RELAY_PIN_1 18 // Pin für das erste Relais
#define RELAY_PIN_2 15 // Pin für das zweite Relais
serialStr serialMgr;
void setup() {
Serial.begin(115200); // Serielle Kommunikation starten
Serial.println("Type relay# on/off to see if this works.");
Serial.println("For example : 1 on");
pinMode(RELAY_PIN_1, OUTPUT); // Relais 1 als Ausgang
pinMode(RELAY_PIN_2, OUTPUT); // Relais 2 als Ausgang
setRelay(1,false);
setRelay(2,false);
serialMgr.setCallback(gotStr);
}
void setRelay(int relay,bool onOff) {
switch( relay) {
case 1 :
digitalWrite(RELAY_PIN_1,onOff);
break;
case 2 :
digitalWrite(RELAY_PIN_2,onOff);
break;
default : Serial.println("Bad relay num.");
}
}
void gotStr(char* inStr) {
char* token;
int relayNum;
token = strtok (inStr," ,");
relayNum = atoi(token);
token = strtok (NULL," ,");
if (!strcmp(token,"on")) {
setRelay(relayNum,true);
} else {
setRelay(relayNum,false);
}
}
void loop() { idle(); }