Skills Dev I: A Simple Internet Appliance

Made by Xuan Peng

Created: November 2nd, 2023

0

Process


0

Exercise 1-1

0
//Exercise 1.1
int led = D2;

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

void loop() {
    
    digitalWrite( led, HIGH );
    delay( 3000 );
    //Delay 3 second
    
    digitalWrite( led, LOW );
    delay( 3000 );
    //repeat
}
Click to Expand
0

Exercise 1-2

0
//Exercise 1.2
int led = D2;

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

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

    digitalWrite( led, LOW);
    delay( 3000);
//stop for 3 seconds
}
Click to Expand
0
Exercise 1-2
Xuan - DIoT - https://youtube.com/shorts/LDl597rJYzs
0

Exercise 1-3

0
//Exercise 1.3
int led1 = D2;
int led2 = D0;
//define 2 led

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

void loop() {

    digitalWrite( led1, HIGH );
    digitalWrite( led2, LOW);
    delay( 3000 );

    
    digitalWrite( led1, LOW );
    digitalWrite( led2, HIGH );
    delay( 3000 );
    //the 2 led work in opposite way
}
Click to Expand
0
aad5006a507802a89be889c87d23e529
Xuan - DIoT - https://youtube.com/shorts/oa1pRJ4Tt3A?feature=share
0

Function Exercise 1

0
//Function Exercise 1

// name the pins
int ledPin = D2;

void setup() {

   //Register our Particle function here
   Particle.function("led", ledControl);
   
   // Configure the pins to be outputs
   pinMode(ledPin, OUTPUT);

   // Initialize both the LEDs to be OFF
   digitalWrite(ledPin, LOW);

}

void loop() {

}

int ledControl(String command)
{
   int state = LOW;

   // Make it blink!
   if(command == "BLINK"){
	  for (int i = 0; i<3; i++){
	      
	  digitalWrite(ledPin, HIGH);
	  delay(500);
	  digitalWrite(ledPin, LOW);
	  delay(500);}
 
   //other states
   }else if (command == "HIGH"){
   state = HIGH;
   }else if (command == "LOW"){
   state = LOW;
   
   }else{
	   return -1;
   }

   // write to the appropriate pin
   digitalWrite(ledPin, state);
   return 1;
}
Click to Expand
0
Function Exercise 1
Xuan - DIoT - https://youtube.com/shorts/2vh_furoNgM?feature=share
0

Function Exercise 2

0
//Function Exercise 2

// name the pins
int ledPin = D2;

void setup() {

   //Register our Particle function here
   Particle.function("led", ledControl);
   
   // Configure the pins to be outputs
   pinMode(ledPin, OUTPUT);

   // Initialize both the LEDs to be OFF
   digitalWrite(ledPin, LOW);

}

void loop() {

}

int ledControl(String command)
{
   int state = LOW;
   int val = command.toInt( );

   // Converts a valid String to an integer
	  for (int i = 0; i< val ; i++){
	      
	  digitalWrite(ledPin, HIGH);
	  delay(500);
	  digitalWrite(ledPin, LOW);
	  delay(500);}

   // write to the appropriate pin
   digitalWrite(ledPin, state);
   return 1;
}
Click to Expand
0
Function Exercise 2
Xuan - DIoT - https://youtube.com/shorts/DGXYQv_9ctk?feature=share
0

Function Exercise 3

0
//fuction exercise 3

int ledPin1 = D1;
int ledPin2 = D2;

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 < 5; i++ ) {
        
        digitalWrite( ledPin1, HIGH );
        digitalWrite( ledPin2, HIGH );
        delay( 300 );
        digitalWrite(ledPin1, LOW );
        digitalWrite(ledPin2, LOW );
        delay( 300 );
        }
    }    
    
    else if( command == "CALL1" ) {
        
        for ( int i = 0; i < 5; i++ ) {
        
        digitalWrite( ledPin1, HIGH );
        delay( 300 );
        digitalWrite(ledPin1, LOW );
        delay( 300 );
        }
    }    
    
    else if( command == "CALL2" ) {
        
        for ( int i = 0; i < 5; i++ ) {
        
        digitalWrite( ledPin2, HIGH );
        delay( 300 );
        digitalWrite(ledPin2, LOW );
        delay( 300 );
        }
    }
    
    
    else {
        return -1;
    }
    
    digitalWrite( ledPin1, state );
    digitalWrite( ledPin2, state );
    return 1;
}

void loop() {

}
Click to Expand
0
Function Exercise 3
Xuan - DIoT - https://youtube.com/shorts/d8FUuAfKDYs?feature=share
0

Reflection

0

At first I was confused about the connections of the circuits, but now I'm more aware of the logic.

I may need to learn more about building physical circuits in the next few weeks.

x
Share this Project

Courses

48-675 Designing for the Internet of Things 24

· 11 members

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


Focused on
About

~