Should the LEDs on the relay light up when the light is on? For me they shine when it is off, ie "Turn off". I need to give a specific answer why the consumption in the off state is higher because it is a project to pass.
Code: Select all
int relay = D1;
int relay2 = D2;
int boardLed = D7;
bool vin = LOW;
bool vin2 = LOW;
void setup() {
// Ustawienia GPIO
pinMode(relay,OUTPUT);
pinMode(relay2,OUTPUT);
digitalWrite(relay,HIGH);
digitalWrite(relay2,HIGH);
Particle.subscribe("LED_on", myHandler);
Particle.subscribe("LED_off", thisHandler);
Particle.subscribe("kitchen_on", myHandler2);
Particle.subscribe("kitchen_off", thisHandler2);
bool success;
success = Particle.publish("LED_on", PUBLIC);
success = Particle.publish("LED_off", PUBLIC);
success = Particle.publish("kitchen_on", PUBLIC);
success = Particle.publish("kitchen_off", PUBLIC);
}
void loop() {
if (vin==HIGH){
digitalWrite(relay,HIGH);
}
else if (vin==LOW){
digitalWrite(relay,LOW);
}
if (vin2==HIGH){
digitalWrite(relay2,HIGH);
}
else if (vin2==LOW){
digitalWrite(relay2,LOW);
}
}
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;
}
Is the code more correct now? When it says "Turn on", the LED on the relay also starts.