Skills Dev I: Simple Internet Appliance-Hongyu Mao

Made by Hongyu Mao

I test my first code for blink a led

Created: December 15th, 2021

0

Outcome

    • This should provide at least one clear illustration of the final outcome (photo or video as appropriate).
  • It should ideally have several supporting images as well as a video demonstrating the working prototype, circuit diagrams, etc.)
  • Add completed code and any supporting documentation and file (and/or a completed zip folder containing all of your source code)
  • a clear overhead (or top-down) photo of your completed circuit
0

Process

Exercise 1 : Blink LED

0
// name the pins
int ledPin = D6;

// create a variable to store the
// current brightness of the LED
int ledValue = 0;
void setup()
{
   //Register our Particle function to allow
   // Control of the LED
   Particle.function("led", ledControl);

   // Make the variable 'ledValue' available through
   // the Particle cloud as 'brightness'
   Particle.variable("brightness", ledValue);

   // Set up pin for output
   pinMode(ledPin, OUTPUT);

}
void loop()
{
   // Nothing to do here
}

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

Exercise2: blink 3 times then stop 3 seconds

I only change the loop and delay time to achieve it

0
// variables 
int ledPin = D2;
// make it run once //
void setup() {
    pinMode(ledPin,OUTPUT); //definte ledPin is output use pinMode //

}

void loop() {
    digitalWrite(ledPin,HIGH);
    delay(100);
    digitalWrite(ledPin,LOW);
    delay(100);
    digitalWrite(ledPin,HIGH);
    delay(100);
    digitalWrite(ledPin,LOW);
    delay(100);
    digitalWrite(ledPin,HIGH);
    delay(100);
    digitalWrite(ledPin,LOW);
    delay(3000);
   

}
Click to Expand
0
nt ledPin = D6;
int buttonPin = D2;

void setup()
{
    pinMode(buttonPin,INPUT_PULLUP);
    pinMode(ledPin,OUTPUT);
}

void loop()
{
    int buttonState = digitalRead(buttonPin);
    if (buttonState == LOW)
    { digitalWrite(ledPin,HIGH);
    }else{
        digitalWrite(ledPin,LOW);
    }
}
Click to Expand
0
skill dev 1.3
Hongyu Mao - https://www.youtube.com/watch?v=5n1ASCIQjOM
0

Reflection:

To finish this task, I watched the class video again and went through the circuit slides. Then I get the detailed instructions. Through this exercise I start to understand the basic knowledge of a simple circuit and I find it interesting when I try to connect all the things together.

x