Skills Dev I: A Simple Internet Appliance
Made by Sohail Shaikh
Made by Sohail Shaikh
Goals: Get oriented with the Particle platform, build your first circuit and code your first project.
Created: November 3rd, 2022
Process:
I initiated this project by going through the course instructions for making a circuit and coding in Arduino. After following the initial steps of connecting an LED to a particle cloud, I started learning about for loops and if conditions to control the LED from the particle cloud. The main challenge for me was to think of a way to fade two led pins by giving brightness from the Particle platform. I learned about converting the user input into an integer value using the toInt() function.
Reflection:
In this project, I learned how to code using the particle platform and control LED through the cloud. It also helped me learn the basics of Arduino language (Variables, Loops, if Conditions). It helped me develop confidence in making basic circuits. I tried the Controlling PWM exercise as well to fade two LEDs using the user input.
Next Steps :
I would like to learn more about the inbuilt functions and more about the other Pins of Argon.
int led1= D2;
void setup() {
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
Particle.function("led", ledControl);
}
void loop() {
}
int ledControl(String command)
{
if(command == "HIGH"){
for(int i=0; i<3; i++){
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led1, LOW);
delay(500);
}
}else if(command == "LOW"){
digitalWrite(led1, LOW);
return 0;
}else{
return -1;
}
return 1;
}
Click to Expand
int led1= D2;
void setup() {
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
Particle.function("ledBlinkCounts", ledControl);
}
void loop() {
}
int ledControl(String command)
{
int blinkCounts= command.toInt();
if(blinkCounts<0)
{
return -1;
}
for(int i=0; i<blinkCounts; i++){
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led1, LOW);
delay(500);
}
digitalWrite(led1, LOW);
return 1;
}
Click to Expand
int led1= D2;
int led2= D1;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
// Initialize both the LEDs to be OFF
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
Particle.function("ledBlinkCounts", ledControl);
}
void loop() {
}
int ledControl(String command)
{
delay(2000);
int blinkCounts= command.toInt();
if(blinkCounts<0)
{
return -1;
}
for(int i=0; i<blinkCounts; i++){
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
delay(500);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
delay(500);
}
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
return 1;
}
Click to Expand
Go back to the original program. Now add a second LED to the circuit.
Set the second LED to work as the opposite amount of brightness to the first. For example if the first is set at 55, the second should be set at 200. Hint: led2Brightness = (255 - led1Brightness)
int ledPin1 = D2;
int ledPin2 = D3;
// 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);
Particle.variable("brightness", ledValue);
// Set up pin for output
pinMode(ledPin2, OUTPUT);
pinMode(ledPin1, OUTPUT);
}
void loop() {
}
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;
if (ledValue < 255){
int led2Brightnes= (255 - ledValue);
for(int j=led2Brightnes; j>=0; j--){
analogWrite(ledPin2, j);
delay(10);
}
for(int i=ledValue; i>=0; i--){
analogWrite(ledPin1, i);
delay(10);
}
}
// Return 1 to say completed successfully
return 1;
}
Click to Expand