# Akshay - Skills Dev I

Made by Akshay Soma · UNLISTED (SHOWN IN POOLS)

Learn how to work with this little breadboard

Created: November 10th, 2021

0

## Outcome

By going through these exercises, I was able to learn the basics of creating a program and connecting it to the Particle dashboard so it can receive instructions from the internet.

First Sketch:

Exercise 1

Modify the program to Blink on and off every 3 seconds.

Exercise 2

Change the program to blink on and off 5 times then stop for 3 seconds. Each blink should be 0.5s (a half second)

Exercise 3

Go back to the original program. Now add a second LED to the circuit.

Program the LED’s to alternate blinks i.e. when LED 1 turns on, LED 2 turns off, then when LED 2 turns on, LED 1 turns off.

0
``````/////////////////////////////////////Exercise 1:

int ledPin = D2;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(3000);
digitalWrite(ledPin, LOW);
delay(3000);
}

//////////////////////////////////////Exercise 2:

int ledPin = D2;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
for(int i = 0; i < 5; i++){
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(300);
};
delay(3000);
}

////////////////////////////////////////Exercise 3:

int ledPin = D2;
int ledPin2 = D3;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
}

void loop() {
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, LOW);
delay(300);

digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, HIGH);
delay(300);
}``````
Click to Expand
0
Exercise 1: On 3s / Off 3s
Akshay
0
Akshay
0
Exercise 3: Alternating LED's
Akshay
0

Making a Connected LED

Exercise 1:

Modify the cloud function to blink the LED 3 times after it is called

Exercise 2:

Modify the cloud function as follows:

Instead of passing a `HIGH` Or `LOW` string pass the number of times you would like it to blink
Set the function to blink that number of times
Finally once it has completed all of the blinking it should turn the LED off

Exercise 3:

Go back to the original program. Now add a second LED to the circuit.

Change the program and cloud function to allow you to control both LEDs remotely

0
Connected Exercise 1: Blink 3 times after call
Akshay
0
``````///////////////////////////////////Exercise 1:

int ledPin = D2;

void setup() {

Particle.function("ledFlash", ledControl);

pinMode(ledPin, OUTPUT);

digitalWrite(ledPin, LOW);
}

void loop() {

//Particle.function()

}

int ledControl(int command){
int state = LOW;

for(int i=0; i<3;i++){
if(command =="HIGH"){

state = HIGH;
digitalWrite(ledPin, state);
delay(300);
state = LOW;
digitalWrite(ledPin, state);
delay(300);
state = HIGH;
digitalWrite(ledPin, state);
delay(300);
state = LOW;
digitalWrite(ledPin, state);
delay(300);
state = HIGH;
digitalWrite(ledPin, state);
delay(300);
state = LOW;
digitalWrite(ledPin, state);
return 1;

}else if(command == "LOW"){
state = LOW;
digitalWrite(ledPin, state);
return 1;

}else{
return -1;
}
}
}

//////////////////////////////////////Exercise 2:
int ledPin = D2;
void setup() {

Particle.function("ledFlash", ledControl);

pinMode(ledPin, OUTPUT);

digitalWrite(ledPin, LOW);
}

void loop() {

//Particle.function()

}

int ledControl(String s){
int x = s.toInt();

for(int i=0; i<x;i++){
digitalWrite(ledPin, 1);
delay(200);
digitalWrite(ledPin, 0);
delay(150);
}

return x;
}

/////////////////////////////////////Exercise 3:
int ledPin = D2;
int ledPin2 = D3;
void setup() {

Particle.function("redLEDFlash", ledControl);
Particle.function("blueLEDFlash", ledControl2);

pinMode(ledPin, OUTPUT);
pinMode(ledPin2,OUTPUT);

digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
}

void loop() {

//Particle.function()

}

int ledControl(String a){
int x = a.toInt();

for(int i=0; i<x;i++){
digitalWrite(ledPin, 1);
delay(200);
digitalWrite(ledPin, 0);
delay(150);
}

return x;
}

int ledControl2(String b){
int y = b.toInt();

for(int j=0; j<y;j++){
digitalWrite(ledPin2, HIGH);
delay(200);
digitalWrite(ledPin2, LOW);
delay(150);
}

return y;
}``````
Click to Expand
0
Connected Exercise 2: Blink as many times as requested
Akshay
0
Connected Exercise 3: Remote Control 2 LEDs
Akshay
0

## Process

If appropriate, if you ran into difficulties and/or if you experimented (went beyond the materials), describe how you arrived at the outcome. Outline the process you underwent to reach the outcome (experiments, hacks, tests, refinements, iterations, failures)

One difficulty I ran into was trying to execute a for loop inside of an if statement's actions in a function being defined. As such, I ended up hard coding the number of flashes required for some pieces. Eventually I was able to figure it out and solve that issue by moving the for loop outside of the if statement.

Something I experimented with was the timing of LED on and LED off times to make blinks look more clustered together instead of having uniform on/off times. Personally, I prefer the result because it allows me to more easily understand when the LED is taking a break between clustered blinking.

I also took the liberty of making both LED's callable for a certain number of blinks for the final exercise instead of using the original program exactly because it seemed more intuitive for the user to input the number of blinks rather than having the program break if someone did not enter HIGH or LOW.

0

## Reflection

In this project I learned to be conscious of my syntax, make sure I have things wired correctly, and learned to experiment with my code a bit to find new results. Overall, I found that the coding portion was quite similar to the C++ that I have used before, so it was not overly challenging. The wiring required a bit of thought, but once I had everything logically organized, it also became relatively easy.

If I were to do something differently, I would waste less time reading and more time tinkering with the code. I feel that I learn better with a more hands-on and experimental touch. In addition, I would have coded the final program to work in a couple more ways such that either LED could be called and set to stay on HIGH, LOW, or be asked to blink a number of times. It would have made the little app a bit more fun and intuitive to engage with.