Skills Dev 1: A Simple Internet Appliance

Made by Donner Kahl · UNLISTED (SHOWN IN POOLS)

The goal was to gain a preliminary understanding to creating circuits, writing code, and connecting devices to the internet. We use LED lights and functions to turn them on/off and blink. This gave us experience in debugging and making more complex variations of base code.

Created: November 3rd, 2022

0
//Part 1

//Create variable connecting to D2
int ledPin = D2;

void setup() {
//Create a function led blink
Particle.function("ledBlink",ledBlink);

pinMode(ledPin, OUTPUT);

digitalWrite(ledPin, LOW);

}

void loop() {

}

//Initiate function led blink
int ledBlink(String command)
{
    
int state = LOW;

//If command is high, blink 3 times
if(command == "HIGH")
    {
    
    digitalWrite(ledPin,LOW);
    delay(500);

    digitalWrite(ledPin,HIGH);
    delay(500);

    digitalWrite(ledPin,LOW);
    delay(500);

    digitalWrite(ledPin,HIGH);
    delay(500);

    digitalWrite(ledPin,LOW);
    delay(500);

    digitalWrite(ledPin,HIGH);
    delay(500);

    digitalWrite(ledPin,LOW);
    delay(500);
    }

//Else return -1
else
    {
    return -1;
    }

}

//Part 2
//Create variable for D2
int ledPin = D2;

void setup() {

//Create a function to control the led
Particle.function("led",ledControl);

pinMode(ledPin, OUTPUT);

digitalWrite(ledPin, LOW);

}

void loop() {

}

//Initiate the led function
int ledControl(String command)
{
int amnt = 0;
//If the amount is not 0 then create an variable of the number
if(command != "0")
    {
    amnt = command.toInt();
    }
    
else
    {
    return -1;
    }

//Then run a loop to blink once for the number of the variable amount
for (int i=1; i <= amnt; i++)
    {
    digitalWrite(ledPin, LOW);
    delay(50);
    digitalWrite(ledPin, HIGH);
    delay(50);
    digitalWrite(ledPin, LOW);
    delay(50);
    }
return amnt;
}

//Part 3
//Create 2 variables, one for D2 and one for D3
int led1 = D2;
int led2 = D3;

//Create a function to control the different lights
void setup()
{
Particle.function("lights",lights);

pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);

pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
}

void loop()
{}

//have 4 different commands to determine which light to turn on
int lights(String command)
{
    
int state = LOW;
int light = led1;

if(command == "gron")
    {
    state = HIGH;
    light = led1;
    }

else if (command == "groff")
    {
    state = LOW;
    light = led1;
    }
    
else if (command == "redon")
    {
    state = HIGH;
    light = led2;
    }

else if (command == "redoff")
    {
    state = LOW;
    light = led2;
    }

else
    {
    return -1;
    }

digitalWrite(light, state);

return light;
}
Click to Expand
0

Part 1 included a function to turn a light on and off by command using HIGH and LOW.

Part 2 required a loop that blinks the light equal to the number input of the function.

Part 3 involved creating a circuit for a second LED. Then the function determines which light to turn on and off using redon and redoff for red light on and off, and gron and groff for green light on and off.

x
Share this Project

This project is only listed in this pool. Be considerate and think twice before sharing.


Courses

About

The goal was to gain a preliminary understanding to creating circuits, writing code, and connecting devices to the internet. We use LED lights and functions to turn them on/off and blink. This gave us experience in debugging and making more complex variations of base code.