//Connected LED Exercise 3: Add second LED and control remotely (both blink the number of times you input)
int ledPin1 = D2;
int ledPin2 = D3;
void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// Initialize both the LEDs to be OFF
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
Particle.function("Number of red led blinks", ledControl1);
Particle.function("Number of orange led blinks", ledControl2);
}
void loop() {
}
//Note: Functions cannot happen simultaneously, when you execute ledControl2 while ledControl1 is happening, it pauses ledControl1 to run ledControl2 until that is comnplete
int ledControl1(String command)
{
int value = command.toInt();
// find out the state of the led
if(value > 0)
{
for (int i = 0; i < value; i++)
{
digitalWrite(ledPin1, HIGH);
delay(500);
digitalWrite(ledPin1, LOW);
delay(500);
}
}
else
{
return -1;
}
return 1;
}
int ledControl2(String command)
{
int value2 = command.toInt();
// find out the state of the led
if(value2 > 0)
{
for (int i = 0; i < value2; i++)
{
digitalWrite(ledPin2, HIGH);
delay(500);
digitalWrite(ledPin2, LOW);
delay(500);
}
}
else
{
return -1;
}
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. .