Skill Dev I - Miley Hu

Made by Miley Hu

Created: November 7th, 2021

0

Outcome

I worked through the exercises for Making a connected LED. 

0
int led1 = D2;


void setup() {
    // Configure the pins to be outputs
    pinMode(led1, OUTPUT);

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

   //Register our Particle function here
    Particle.function("led1", led1Control);

}


void loop() {
    
}

int ledControl(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(led1, state);
  return 1;
}
Click to Expand
0

Process

I followed the instructions on the lab page and first worked through a few exercises in "First Sketch: making a LED blink" 

Making an LED blink Exercise #1-3

0
//Making an LED blink 

int led1 = D2;

void setup() {
    // Configure the pins to be outputs
    pinMode(led1, OUTPUT);
   
}


void loop() {
    
    digitalWrite(led1, HIGH);
    delay(1000);
    
    digitalWrite(led1, LOW);
    delay(1000);
    
}
Click to Expand
0
Blink 1s interval
Miley Hu - https://youtu.be/za0U03xZb5A
0
//Exercise 1
//Modify the program to Blink on and off every 3 seconds

int led1 = D2;

void setup() {
    // Configure the pins to be outputs
    pinMode(led1, OUTPUT);
   
}


void loop() {
    
    digitalWrite(led1, HIGH);
    delay(3000);
    
    digitalWrite(led1, LOW);
    delay(3000);
    
}
Click to Expand
0
Blink - 3s intervals
Miley Hu - https://youtu.be/a-kZOU_8sfk
0
//Exercise #2
//Change the program to blink on and off 5 times then stop for 3 seconds. Each blink should be 0.5s

int led1 = D2;

void setup() {
    // Configure the pins to be outputs
    pinMode(led1, OUTPUT);
   
}

void loop() {
    
    for (int i = 0; i < 5; i++) {
        digitalWrite(led1, HIGH);
        delay(500);
    
        digitalWrite(led1, LOW);
        delay(500);
    }
    
    delay(3000);
    
}
Click to Expand
0
Blink 3 times and wait
Miley Hu - https://youtu.be/LluvtNe_IUQ
0
2 LEDs alternating to blink
Miley Hu - https://youtu.be/k4nAX8E8kuI
0
//Exercise #3
//Program the LED’s to alternate blinks

void setup() {
    // Configure the pins to be outputs
    pinMode(led1, OUTPUT);
    pinMode(led2, OUTPUT);   
}

void loop() {
    
    for (int i = 0; i < 5; i++) {
        digitalWrite(led1, HIGH);
        delay(500);
    
        digitalWrite(led1, LOW);
        delay(500);
        
        digitalWrite(led2, HIGH);
        delay(500);
    
        digitalWrite(led2, LOW);
        delay(500);
    }
    
    delay(3000);
    
}
Click to Expand
0

Independent exercise 1

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

0
//independent exercise 1

int led1 = D2;

void setup() {
    // Configure the pins to be outputs
    pinMode(led1, OUTPUT);
   
    digitalWrite(led1, LOW);

    Particle.function("led1", ledControl);

}


void loop() {
    
}

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

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

}
Click to Expand
0
Blink 3 times upon calling function
Miley Hu - https://youtu.be/QacLOohnqeI
0

Independent exercise 2

Modify the cloud function as follows:

Instead of passing a high Or low string pass the number of times you would like it to blink
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
//independent exercise 2

int led1 = D2;

void setup() {
    // Configure the pins to be outputs
    pinMode(led1, OUTPUT);
   
    digitalWrite(led1, LOW);

    Particle.function("led1", ledControl);

}


void loop() {
    
}

int ledControl (String command) {
    int state = LOW; 
    int number = atoi(command);
    if (number > 0) {
        
        for (int i = 0; i < number; i++) {
            digitalWrite(led1, HIGH);
            delay(500);
            digitalWrite(led1, LOW);
            delay(500);
        }
        return 1;
        
    } else {
        state = LOW;
        return -1;
        }
}
Click to Expand
0
Blink [x] times according to input
Miley Hu - https://youtu.be/beSm3kxogas
0

Independent exercise 3

add a second LED to the circuit. Change the program and cloud function to allow you to control both LEDs remotely

0
//independent exercise 3

int led1 = D2;
int led2 = D5;

void setup() {
    // Configure the pins to be outputs
    pinMode(led1, OUTPUT);
    pinMode(led2, OUTPUT);
   
      // Initialize both the LEDs to be OFF
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
//   //Register our Particle function here
    Particle.function("led1", led1Control);
    Particle.function("led2", led2Control);
}


void loop() {
    
}

int led1Control(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(led1, state);
  return 1;
}

int led2Control(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(led2, state);
  return 1;
}
Click to Expand
0

Reflection

This is the first Skill Development assignment that I worked on, so I learned how to work with Argon and the console, and the cloud functions from the start on. The part where we need to connect two LEDs was particularly challenging as I am very new to the idea of building circuits and making things connected.

x