A Simple Internet Appliance

Made by Yiming Jiao

Start to learning the basic function of Argon and cloud function.

Created: November 2nd, 2023

0

Outcome: 

As above picture, this is an introductory skill build documentation. I learnt how Argon work through particle, and how cloud function work.

Process: 

By following with the tutorial step by step, I finally get everything list understand and done.

Next Steps:

Continuing to explore and utilize the platform and different features.

Reflection:

In this lab, it takes me some time to figuring out how to get the token.

0

First Sketch: Making an LED Blink

Ex.1

Modify the program to Blink on and off every 3 seconds.  

0
const int LEDPIN0 = D0;

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

void loop() {
    //First Sketch: Making an LED Blink
    //Ex.1
     digitalWrite(LEDPIN0, HIGH);
     delay(3000);
     digitalWrite(LEDPIN0, LOW);
     delay(3000);
}
Click to Expand
0

Ex.2

Change the program to blink on and off 5 times then stop for 3 seconds. Each blink should be 0.5s. 

0
const int LEDPIN0 = D0;
const int LEDPIN1 = D1;

void setup() {
    pinMode(LEDPIN0, OUTPUT);
    pinMode(LEDPIN1, OUTPUT);
}

void loop() {
    //Ex.2
     for(int i = 0; i < 5; i++){
         digitalWrite(LEDPIN0, HIGH);
         delay(500);
         digitalWrite(LEDPIN0, LOW);
         delay(500);
     }
     delay(2500);
}
Click to Expand
0

Ex.3

Program the LED’s to alternate blinks i.e. when LED 1 turns on, LED 2 turns off, then when LED 2 turns on, LED 1 turns off

0
const int LEDPIN0 = D0;
const int LEDPIN1 = D1;

void setup() {
    pinMode(LEDPIN0, OUTPUT);
    pinMode(LEDPIN1, OUTPUT);
}

void loop() {    
    //Ex.3
     digitalWrite(LEDPIN0, HIGH);
     digitalWrite(LEDPIN1, LOW);
     delay(1000);
     digitalWrite(LEDPIN0, LOW);
     digitalWrite(LEDPIN1, HIGH);
     delay(1000);
}
Click to Expand
0

Making a Connected LED

Ex.1

Modify the cloud function to blink the LED 3 times after it is called. 

0
const int LEDPIN0 = D0;

void setup() {
    pinMode(LEDPIN0, OUTPUT);
    
    //Making a Connected LED
    digitalWrite(LEDPIN0, LOW);
    
    Particle.function("led", ledControl);
}

void loop() {

}


//Making a Connected LED
//Ex.1
int ledControl(String command)
{
   for(int i = 0; i < 3; i++){
       digitalWrite(LEDPIN0, HIGH);
       delay(500);
       digitalWrite(LEDPIN0, LOW);
       delay(500);
   }
   return 1;
}
Click to Expand
0

Ex.2

Set the function to blink that number of times. Finally once it has completed all of the blinking it should turn the LED off.

0
const int LEDPIN0 = D0;

void setup() {
    pinMode(LEDPIN0, OUTPUT);
    
    //Making a Connected LED
    digitalWrite(LEDPIN0, LOW);
    
    Particle.function("led", ledControl);
}

void loop() {

}


//Making a Connected LED
//Ex.2
int ledControl1(String num)
{
  int n = num.toInt();
  for(int i = 0; i < n; i++){
    digitalWrite(LEDPIN0, HIGH);
    delay(500);
    digitalWrite(LEDPIN0, LOW);
    delay(500);
  }
  return 1;
}
Click to Expand
0

Ex.3

Change the program and cloud function to allow you to control both LEDs remotely.

0
const int LEDPIN0 = D0;
const int LEDPIN1 = D1;

void setup() {
    pinMode(LEDPIN0, OUTPUT);
    pinMode(LEDPIN1, OUTPUT);
    
    //Making a Connected LED
    digitalWrite(LEDPIN0, LOW);
    
    Particle.function("led", ledControl);
}

void loop() {
}

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

   // find out the state of the led
   if(command == "HIGH"){
	   state = HIGH;
   }else if(command == "LOW"){ 
	   state = LOW;
   }else{
	   return -1;
   }

   // write to the appropriate pin
   digitalWrite(LEDPIN0, state);
   digitalWrite(LEDPIN1, state);
   return 1;
}
Click to Expand
0
x
Share this Project


About

Start to learning the basic function of Argon and cloud function.