Priya Jain - Skills Dev 1

Made by Priya Jain

The goal of this project is to build a simple internet connected light with an LED.

Created: November 7th, 2021

0

Process and Outcome

0
int ledPin = D2;
int ledValue = 0;

void setup() {
    Particle.function("led", ledControl);
    Particle.variable("brightness", ledValue);
    pinMode(ledPin, OUTPUT);


}

void loop() {
digitalWrite(ledPin, HIGH);
     delay(1000);
    
     digitalWrite(ledPin, LOW);
     delay(1000);
     
}

int ledControl(String command)
{
    // Convert the passed variable to an integer
   ledValue = command.toInt();

   // Check it is a valid number
   if( ledValue > 255 ) return -1;
   if( ledValue < 0 ) return -1;

   // Use PWM to set the brightness
   // of the LED
   analogWrite(ledPin, ledValue);

   // Return 1 to say completed successfully
   return 1;
}
Click to Expand
0

Process

  • The second exercise I did was experimenting with the code to make the LED behave differently. In this exercise the LED blinks 5 times and then there is a longer delay after the fifth blink. The cycle repeats on loop. 
  • Here is the video link: https://youtu.be/c-vnKkYZZvM (excuse the background, I recorded this before I was aware we needed videos for the assignment)
  • Below the additional code I added to the function.
0
void loop() {
    // digitalWrite(ledPin, HIGH);
    // delay(1000);
    
    // digitalWrite(ledPin, LOW);
    // delay(1000);
    
    //exercise 3
    analogWrite(ledPin, 150);

    
    for(int i=0; i<=5; i++){
        digitalWrite(ledPin, HIGH);
        delay(500);
        digitalWrite(ledPin, LOW);
        delay(500);
        if(i==5){
            delay(3000);
            i=0;
        }
    }

}
Click to Expand
0

Here I connected it to a particle function so that it turns on and off when I type HIGH and LOW

0
Skill dev 1 function
Priya Jain - https://youtu.be/g2voR__bR2M
0

Here I set up two LED lights and updated the code.

0
int ledPin1 = D2;
int ledPin2 = D3;
int ledValue = 0;

void setup() {
    Particle.function("led1", ledControl);
    Particle.function("led2", led2Control);
    Particle.variable("brightness", ledValue);
    pinMode(ledPin1, OUTPUT);
    pinMode(ledPin2, OUTPUT);


}



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

Reflection

Doing this first simple skills dev assignment was very encouraging. The fact that everything worked correctly was a relief because it meant my environment is set up correctly. 

This is my first time working with microcontrollers and it was nice to play around with the code to make the physical components behave as I wanted. I have no experience with hardware, so just following a diagram to make a simple circuit helped a lot. 

0
0
x
Share this Project

Courses

About

The goal of this project is to build a simple internet connected light with an LED.