// Two lights alternating blinking
// Name and assign the pins
int ledPin1 = D3; // First LED (RED)
int ledPin2 = D2; // Second LED (Orange)
void setup() {
// Configure the pins to be outputs
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// LED Off
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
// Register cloud function here
Particle.function("led", ledControl);
}
void loop() {
// LED Blinking between LED 1 and LED 2
digitalWrite(ledPin1, HIGH); // Turn ON the first LED
digitalWrite(ledPin2, LOW); // Turn OFF the second LED
delay(500); // 0.5 Sec Delay
digitalWrite(ledPin1, LOW); // Turn OFF the first LED
digitalWrite(ledPin2, HIGH); // Turn ON the second LED
delay(500); // 0.5 Sec Delay
}
int ledControl(String command) {
if (command == "LED1_ON") {
digitalWrite(ledPin1, HIGH);
} else if (command == "LED1_OFF") {
digitalWrite(ledPin1, LOW);
} else if (command == "LED2_ON") {
digitalWrite(ledPin2, HIGH);
} else if (command == "LED2_OFF") {
digitalWrite(ledPin2, LOW);
} else {
return -1; // Incorrect command
}
return 1;
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .