Problem with LED blinking

For some reason, LED1 is blinking randomly.

Code below

int led0Toggle(String command);
int led1Toggle(String command);
int led2Toggle(String command);
int led3Toggle(String command);

int led0 = D0;
int led1 = D1;
int led2 = D2;
int led3 = D3;

void setup() {
    pinMode(led0,OUTPUT);
    pinMode(led1,OUTPUT);
    pinMode(led2,OUTPUT);
    pinMode(led3,OUTPUT);
    
    Particle.function("LED0", led0Toggle);
    Particle.function("LED1", led1Toggle);
    Particle.function("LED2", led2Toggle);
    Particle.function("LED3", led3Toggle);
    
    digitalWrite(led0, LOW);
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
}

void loop() {
}

int led0Toggle(String command) {
        if (command=="ON") {
        digitalWrite(led0,HIGH);
            return 1;
        }
        else if (command=="OFF") {
        digitalWrite(led0,LOW);
            return 0;
        }
        else {
            return -1;
        }
}    

int led1Toggle(String command) {
        if (command=="ON") {
        digitalWrite(led1,HIGH);
            return 1;
        }
        else if (command=="OFF") {
        digitalWrite(led1,LOW);
            return 0;
        }
        else {
            return -1;
        }
}

int led2Toggle(String command) {
        if (command=="ON") {
        digitalWrite(led2,HIGH);
            return 1;
        }
        else if (command=="OFF") {
        digitalWrite(led2,LOW);
            return 0;
        }
        else {
            return -1;
        }
}    

int led3Toggle(String command) {
        if (command=="ON") {
        digitalWrite(led3,HIGH);
            return 1;
        }
        else if (command=="OFF") {
        digitalWrite(led3,LOW);
            return 0;
        }
        else {
            return -1;
        }
}

Functions did control led but now commands don’t seem to do anything.

I’d suspect some bad connection or the LED dying.
What current limiting resistors do you use?
Have you removed and reinserted the LED or used another?

They are 220 ohm and i did switch them out.

I even loaded up tinker and the circuit worked fine but when i flash my code it starts to blink again.

Can you provide a video of the random blinking?
As far as I can tell, the code above would not explain that behaviour.

What device OS version have you got on your Photon and which are you targeting with your build?
What IDE are you using?
Do all other LEDs behave as expected - only led1 misbehaves?

I put my photon in safemode and then flashed and everything is working.
Not sure what caused my problem but thanks for your help.

1 Like