[SOLVED] LED widget and microswitch

Please help before I go crazy. I have made a garage door controller and would like to add a status monitor using the Blynk LED widget and a microswitch. What I have set up so far is D3 and VIN hooked up as output for the relay to open and close the door. This works perfectly. I cannot get the BLYNK LED to work. Below is the code I have flashed to the photon and I realize this is for two doors and two LEDS put I cannot seem to clean it up for a single door and LED and make it compile correctly. What I am having difficulty with is where do I hook up the LED/ microswitch lead wires to function the LED? I have tried D0 and ground, and have opened and closed the switch with no results. I have tried D0 and VIN, and have opened and closed the switch with no results. I have the LED set on V5. Please help and show me the error of my ways. I am totally new to all of this and would appreciate if someone could break it down to me in “WalMart” language. If you could break down this code for me to use just magSwitch1 and relaySwitch1 that would be an added bonus. Thanks!!!

// This #include statement was automatically added by the Particle IDE.
#include “blynk/blynk.h”
#include “SparkCorePolledTimer/SparkCorePolledTimer.h”

char auth[] = “my token";

// door 1 sensor and control
const int magSwitch1 = D0;
const int relaySwitch1 = D3;
// door 2 sensor and control
const int magSwitch2 = D1;
const int relaySwitch2 = D4;

// door 1 status
int magStatus1 = 0;
int ledStatus1 = 0;
// door 2 status
int magStatus2 = 0;
int ledStatus2 = 0;

// timeout in milliseconds
SparkCorePolledTimer updateTimer(1000);

void OnTimer(void) {
sendDoorStatus();
}

void setup() {
Serial.begin(9600);
Blynk.begin(auth);
while (Blynk.connect() == false) {
// Wait until connected
}

pinMode(relaySwitch1, OUTPUT);
pinMode(relaySwitch2, OUTPUT);
pinMode(magSwitch1, INPUT_PULLDOWN);
pinMode(magSwitch2, INPUT_PULLDOWN);

updateTimer.SetCallback(OnTimer);

}

void sendDoorStatus() {
Blynk.virtualWrite(V5, ledStatus1);
Blynk.virtualWrite(V6, ledStatus2);
}

void loop() {
Blynk.run();

//constantly monitor the door magnetic switch status (garage door open or closed)
magStatus1 = digitalRead(magSwitch1);
magStatus2 = digitalRead(magSwitch2);

if (magStatus1 == HIGH) {
    ledStatus1 = 1023; // 100% brightness
    //Serial.println("LED1: high");
} else {
    ledStatus1 = 0;
    //Serial.println("LED1: low");
}
if (magStatus2 == HIGH) {
    ledStatus2 = 1023;
} else {
    ledStatus2 = 0;
}

updateTimer.Update();

}

LED widget get’s values in range of 0-255

Thanks Pavel for the reply. However, I have no idea what that statement means. I am totally new to all of this, but willing to learn. Could you explain further, or link me to a tutorial that covers this? Is this code correct? Do I have to do something else in the Blynk app?

Change that too:

if (magStatus1 == HIGH) {
    ledStatus1 = 255; // 100% brightness
    //Serial.println("LED1: high");
} else {
    ledStatus1 = 0;
    //Serial.println("LED1: low");
}
if (magStatus2 == HIGH) {
    ledStatus2 = 255;
} else {
    ledStatus2 = 0;
}

I got it !! Thanks so much for your help Lichtsignaal

You’re welcome. Code reading is not really hard to do, but to write is more difficult. If you want to learn you just edit all things away with “2” in it and try it untill it works, that is how I learned :wink: