A Simple Internet Appliance

Made by Yuhan Wu

In this exercise, we’re going to create the first circuit, create a short program and control some components with code.

Created: November 1st, 2023

1

Intention

Get to learn about Particle and get hands on the circuit.

0

Process

First 3 exercise are focused on basic knowledge about coding surrounding LED.

The last 3 are focused on functions that send argument to call the LED.

0
Skill Dev 1 Exercise 1
DIOT-Max - https://youtube.com/shorts/yUk9aNmPkN4?feature=share
0
//Setup variables

int led = D2;

void setup() {
    
    pinMode( led, OUTPUT );
// D2 is the out put pin

}

void loop() {

    digitalWrite( led, HIGH );
    delay( 3000 );
    //delay( 3000 ); - Delay 3 second
    
    digitalWrite( led, LOW );
    delay( 3000 );
    //repeat blinking
    
}
Click to Expand
0
Skill Dev 1 Exercise 2
DIOT-Max - https://youtube.com/shorts/PTZ8ZXrm-sQ?feature=share
0
int led = D2;

void setup() {
    
    pinMode( led, OUTPUT );
// D2 is the out put pin

}

void loop() {
    
    for( int i = 0; i < 5; i++ ) {
    //loop for 5 times 
    
        digitalWrite( led, HIGH );
        delay( 500 );

        digitalWrite( led, LOW );
        delay( 500 );
        //each blink is 1/2 second
    
    }
    
    digitalWrite( led, LOW );
    delay( 3000 );
    //stop for 3 seconds after 5 blinks
    
}
Click to Expand
0
Skill Dev 1 Exercise 3
DIOT-Max - https://youtube.com/shorts/dWjieeLC1ZM?feature=share
0
//Setup variables

int led = D2;
//orange LED
int led1 = D3;
//green LED
//it is obvious that the green LED is much lower in brightness

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

}

void loop() {

    digitalWrite( led, HIGH );
    digitalWrite( led1, LOW );
    delay( 1000 );
 
    digitalWrite( led1, HIGH );
    digitalWrite( led, LOW );
    delay( 1000 );
//turning one of them on and another off together at the same time

}
Click to Expand
0
Skill Dev 1 Exercise on Function 1
DIOT-Max - https://youtu.be/EXJ8xLZIdbg
0
int ledPin = D2;

void setup() {
    
    pinMode( ledPin, OUTPUT );
    digitalWrite( ledPin, LOW );
    //LED is initially turned off.
    
    Particle.function( "led", ledControl );
    //register function
    
}

int ledControl( String command ) {
    
    int state = LOW;
    
    if( command == "CALL" ) {
        
        for ( int i = 0; i < 3; i++ ) {
        
        digitalWrite( ledPin, HIGH );
        delay( 500 );
        digitalWrite(ledPin, LOW );
        delay( 500 );
        }
    }    
    
    else if( command == "HIGH" ) {
        state = HIGH;
    } else if( command == "LOW" ) {
        state = LOW;
    } else {
        return -1;
    }
    
    digitalWrite( ledPin, state );
    return 1;
}



void loop() {
    
}
Click to Expand
0
Skill Dev 1 Exercise on Function 2
DIOT-Max - https://youtu.be/0SHK4AsIp2g
0
int ledPin = D2;

void setup() {
    
    pinMode( ledPin, OUTPUT );
    digitalWrite( ledPin, LOW );
    //LED is initially turned off.
    
    Particle.function( "led", ledControl );
    //register function
    
}

int ledControl( String command ) {
    
    int state = LOW;
    int val =  command.toInt( );
    //toInt mentioned in arduino's website
    //https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/toint/
   
    for( int i=0; i < val; i++ ){
        
        digitalWrite( ledPin, HIGH );
        delay( 500 );
        digitalWrite(ledPin, LOW );
        delay( 500 );
    }    
    digitalWrite( ledPin, state );
    return 1;
}



void loop() {
    
}
Click to Expand
0
Skill Dev 1 Exercise on Function 3
DIOT-Max - https://youtu.be/0z0Om9h3Xgc
0
int ledPin1 = D2;
int ledPin2 = D1;


void setup() {
    
    pinMode( ledPin1, OUTPUT );
    pinMode( ledPin2, OUTPUT );
    digitalWrite( ledPin1, LOW );
    digitalWrite( ledPin2, LOW );
    //LED is initially turned off.
    
    Particle.function( "led", ledControl );
    //register function
    
}

int ledControl( String command ) {
    
    int state = LOW;
    
        if( command == "CALL" ) {
        
        for ( int i = 0; i < 3; i++ ) {
        
        digitalWrite( ledPin1, HIGH );
        digitalWrite( ledPin2, HIGH );
        delay( 500 );
        digitalWrite(ledPin1, LOW );
        digitalWrite(ledPin2, LOW );
        delay( 500 );
        }
    }    
    
    else if( command == "CALL1" ) {
        
        for ( int i = 0; i < 3; i++ ) {
        
        digitalWrite( ledPin1, HIGH );
        delay( 500 );
        digitalWrite(ledPin1, LOW );
        delay( 500 );
        }
    }    
    
    else if( command == "CALL2" ) {
        
        for ( int i = 0; i < 3; i++ ) {
        
        digitalWrite( ledPin2, HIGH );
        delay( 500 );
        digitalWrite(ledPin2, LOW );
        delay( 500 );
        }
    }
    
    else if( command == "HIGH" ) {
        state = HIGH;
    } else if( command == "LOW" ) {
        state = LOW;
    } else {
        return -1;
    }
    
    digitalWrite( ledPin1, state );
    digitalWrite( ledPin2, state );
    return 1;
}



void loop() {
    
}
Click to Expand
0

Reflection

First take away for me might be a more common situation for beginners of circuit and coding, which is missing semicolons, comma and other elements of coding.

To be specific, like replacing the semicolons in the for loop with comma.

Another one is to locate the toINT command to turn string command into int. Which I found on the Arduino website.

  https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/toint/ 

The website us really helpful to find relevant commands.

x
Share this Project

Courses

48-675 Designing for the Internet of Things

· 11 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


About

In this exercise, we’re going to create the first circuit, create a short program and control some components with code.