Witam, chciałbym sterować diodami na RPI za pomocą głosu, jednak mam problem z stworzeniem poprawnego kodu.
int relay = D1; //pin to which relay is connected
int relay2 = D2;
int boardLed = D7;
bool vin = LOW; //a virtual boolean variable
bool vin2 = LOW; //a virtual boolean variable
// setup() is run only once, it's where we set up GPIO and //initialise peripherals
void setup() {
// Setup GPIO
pinMode(relay,OUTPUT); // relay pin is set as output
digitalWrite(relay,HIGH);
// Setup GPIO
pinMode(relay2,OUTPUT); // relay pin is set as output
digitalWrite(relay2,HIGH);
// Subscribe to events published by IFTTT using Particle.subscribe
Particle.subscribe("LED_on", myHandler);
//turning off function declaration
Particle.subscribe("LED_off", thisHandler);
//turning on function declaration
// Subscribe to events published by IFTTT using Particle.subscribe
Particle.subscribe("LED_on_kitchen", myHandler2);
//turning off function declaration
Particle.subscribe("LED_off_kitchen", thisHandler2);
//turning on function declaration
}
// loop() runs continuously, it's our infinite loop.
void loop() {
if (vin==HIGH){
digitalWrite(relay,LOW);
}
else if (vin==LOW){
digitalWrite(relay,HIGH);
}
if (vin2==HIGH){
digitalWrite(relay2,LOW);
}
else if (vin2==LOW){
digitalWrite(relay2,HIGH);
}
}
//our events are called when IFTTT applets are triggered
void myHandler(const char *event, const char *data){
vin=LOW;
}
void thisHandler(const char *event, const char *data){
vin=HIGH;
}
void myHandler2(const char *event, const char *data){
vin2=LOW;
}
void thisHandler2(const char *event, const char *data){
vin2=HIGH;
}
Potrafię sterować jedną diodą, ale chcę sterować dwiema niezależnie. - prosiłbym o wskazówki
up. wystarczyło zrobić jedną pętlę, - ale teraz przy wyłączonych diodach po wypowiedzeniu polecenia LED_on_kitchen uruchamiają się obie diody, w czym może być problem?