Priya Jain - Skills Dev 1
Made by Priya Jain
Made by Priya Jain
The goal of this project is to build a simple internet connected light with an LED.
Created: November 7th, 2021
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
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
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
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.