Skills Dev I: A Simple Internet Appliance

Made by Shih-Hsueh Wang

The goal is to understand the basic knowledge of Particle Argon regarding the circuit and codes.

Created: October 28th, 2022

0

INTENTION

First Sketch: Making an LED Blink

Exercise 1 -1: Make an LED on and off with 3-sec intervals. Video

Exercise 1- 2: Make an LED blink a specific number of times. Video

Exercise 1-3: Make two LEDs in alternate blinks. Video

Making a Connected LED

Exercise 2-1: Make a cloud-based control to blink an LED 3 times. Video

Exercise 2-2: Make a cloud-based control to blink an LED a customized number of times. Video

Exercise 2-3: Make a cloud-based control to blink two LEDs a customized number of times. Video

PROCESS

Based on the instructions on the DioT website, I tried to use the "for" loop to set a specific number of times instead of using multiple HIGH and LOW as the LED output.

REFLECTION

I tried multiple times to use the combination of the "for" loop and the "if" condition to set up the program. Yet, it was not successful as the LEDs didn't light up in the way I expected. Fortunately, I figured out the problem, which is the order of the lines of code. Since I shifted the order of digitalWrite() to the lines within each curly bracket under the "if" conditions, I could achieve my intention. 


0
//Exercise 1-1

int led = D2;

void setup() {
    pinMode (led, OUTPUT);
}

void loop() {
    digitalWrite(led, HIGH);
    delay(3000);
    
    digitalWrite(led, LOW);
    delay(3000);
}
Click to Expand
0
//Exercise 1-2

int led = D2;

void setup() {
    pinMode (led, OUTPUT);
}

void loop() {
    
    for(int i = 0; i <= 4; i++){
        if (i <= 4){
            digitalWrite(led, HIGH);
            delay(500);
            
            digitalWrite(led, LOW);
            delay(500);
        }
    }
    digitalWrite(led, LOW);
    delay(2500);
}
Click to Expand
0
//Exercise 1-3

int led1 = D2;
int led2 = D3;

void setup() {
    pinMode (led1, OUTPUT);
    pinMode (led2, OUTPUT);
}

void loop() {
    
    for(int i = 0; i <= 4; i++){
        if (i <= 4){
            digitalWrite(led1, HIGH);
            digitalWrite(led2, LOW);
            delay(500);
            
            digitalWrite(led1, LOW);
            digitalWrite(led2, HIGH);
            delay(500);
            
        }
    }
}
Click to Expand
0
//Exercise 2-1

int led = D2;
int status = LOW;

void setup() {
    pinMode (led, OUTPUT);
    Particle.function ("ControlLight", lightControl);
    digitalWrite(led, LOW);
}

void loop() {

}

//Cloud-based control
int lightControl (String command) {
        
    if (command.equals ("on")){
        for (int i = 0; i <= 5; i++){

            if (i % 2 == 0){
                status = HIGH;
                delay(500);     
                digitalWrite (led, status);
            }else{
                status = LOW;
                delay(500);
                digitalWrite (led, status);
            }
            
            
        }

            
        
        return 1;
        
    }else if (command.equals("off")){
        
        status = LOW;
        digitalWrite (led, status);
        return -1;
        
    }else{
    
        return 0;
    }
    

}
Click to Expand
0
//Exercise 2-2

int led1 = D2;
int status = LOW;

void setup() {
    pinMode (led1, OUTPUT);
    pinMode(led2, OUTPUT);
    Particle.function ("LEDlLight 1", ledControl1);
    digitalWrite(led1, LOW);
}

void loop() {

}

//Cloud-based control
int ledControl1 (String command) {
    
    int i = command.toInt();
    
    for (i = 0; i <= command.toInt() * 2 - 1; i++){

        if (i % 2 == 0){
            status = HIGH;
            delay(500);     
            digitalWrite (led1, status);
        }else{
            status = LOW;
            delay(500);
            digitalWrite (led1, status);
        }
        
    }
    return i / 2;

}
Click to Expand
0
//Exercise 2-3

int led1 = D2;
int led2 = D3;
int status = LOW;

void setup() {
    pinMode (led1, OUTPUT);
    pinMode(led2, OUTPUT);
    Particle.function ("LEDlLight 1", ledControl1);
    Particle.function ("LEDlLight 2", ledControl2);
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
}

void loop() {

}

//Cloud-based control
int ledControl1 (String command) {
    
    int i = command.toInt();
    
    for (i = 0; i <= command.toInt() * 2 - 1; i++){

        if (i % 2 == 0){
            status = HIGH;
            delay(500);     
            digitalWrite (led1, status);
        }else{
            status = LOW;
            delay(500);
            digitalWrite (led1, status);
        }
        
    }
    return i / 2;

}

int ledControl2 (String command) {
    
    int i = command.toInt();
    
    for (i = 0; i <= command.toInt() * 2 - 1; i++){

        if (i % 2 == 0){
            status = HIGH;
            delay(500);     
            digitalWrite (led2, status);
        }else{
            status = LOW;
            delay(500);
            digitalWrite (led2, status);
        }
        
    }
    return i / 2;

}
Click to Expand
x
Share this Project

Courses

About

The goal is to understand the basic knowledge of Particle Argon regarding the circuit and codes.