Hi there,
i’m using a simple cloud function to turn on and off 4 different relays. I tested the hardware using the iOS Particle app Tinker firmware first and I’m able to run all the relays on and off. Now i used this code below and when i send a msg to enable0 or the other ports of the relays they turn on for a few seconds and turn back off. I’m not sure what is wrong.
void setup() {
Spark.function("parse", parse);
// 0-7 maps to D0-D7
for (int i = 0; i <= 7; i++) {
pinMode(i, OUTPUT);
}
}
void loop() {
}
int parse(String cmd) {
cmd.trim();
cmd.toUpperCase();
if (cmd.startsWith("ENABLE")) {
int pin = cmd.substring(6).toInt();
digitalWrite(pin, HIGH);
}
if (cmd.startsWith("DISABLE")) {
int pin = cmd.substring(7).toInt();
digitalWrite(pin, LOW);
}
}