Skills Dev I: A Simple Internet Appliance

Made by Peng Dou

Created: December 6th, 2022

0

Outcome

      • Control two led by inputting the times they blink.
0

Process

Connect two leds to the circuit. The red one is connected to D3 and the blue one is connected to D4.

0
Skill Dev1
Peng Dou - https://youtu.be/k4d2HfrqzMk
0

Reflection

Particle functions always input things as string. Thus, the command should be casted to different data types according to the usage. Some validation would be required if the input is undetermined.

0
int led1Pin = D3;
int led2Pin = D4;

int led1Control(String command) {
   int times = atoi(command);
   for(int i = 0; i < times; i++) {
       digitalWrite(led1Pin, HIGH);
       delay(500);
       digitalWrite(led1Pin, LOW);
       delay(500);
   }
   return 1;
}

int led2Control(String command) {
   int times = atoi(command);
   for(int i = 0; i < times; i++) {
       digitalWrite(led2Pin, HIGH);
       delay(500);
       digitalWrite(led2Pin, LOW);
       delay(500);
   }
   return 1;
}

void setup() {
    Particle.function("led1", led1Control);
    Particle.function("led2", led2Control);
    pinMode(led1Pin, OUTPUT);
    pinMode(led2Pin, OUTPUT);
}

void loop() {

}
Click to Expand
x