int ledPin = D2;
int ledPin2 = D3;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
Particle.function("led3x", ledControl);
// Particle.function("ledUser", ledTimes);
Particle.function("led3x2", ledControl2);
}
void loop()
{
// Nothing
}
// Ex 1 & 3: Blink LED 3 times
int ledControl(String command)
{
int state = LOW;
if(command == "HIGH") {
for(int i = 0; i < 3; i++){
digitalWrite(ledPin, HIGH);
delay(300);
digitalWrite(ledPin, LOW);
delay(300);
}
}
else if(command == "LOW") {
state = LOW;
}
else {
return -1;
}
// write to the appropriate pin
digitalWrite(ledPin, state);
return 1;
}
// // Ex 2: Blink LED USer input
// int ledTimes(String command)
// {
// int num = command.toInt();
// for(int i = 0; i < num; i++){
// digitalWrite(ledPin, HIGH);
// delay(300);
// digitalWrite(ledPin, LOW);
// delay(300);
// }
// return 1;
// }
// Ex 3: Blink 2nd LED 3 times
int ledControl2(String command)
{
int state = LOW;
if(command == "HIGH") {
for(int i = 0; i < 3; i++){
digitalWrite(ledPin2, HIGH);
delay(300);
digitalWrite(ledPin2, LOW);
delay(300);
}
}
else if(command == "LOW") {
state = LOW;
}
else {
return -1;
}
// write to the appropriate pin
digitalWrite(ledPin2, state);
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. .