Skill Dev I - Miley Hu
Made by Miley Hu
Made by Miley Hu
Created: November 7th, 2021
int led1 = D2;
void setup() {
// Configure the pins to be outputs
pinMode(led1, OUTPUT);
// Initialize both the LEDs to be OFF
digitalWrite(led1, LOW);
//Register our Particle function here
Particle.function("led1", led1Control);
}
void loop() {
}
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(led1, state);
return 1;
}
Click to Expand
//Exercise #2
//Change the program to blink on and off 5 times then stop for 3 seconds. Each blink should be 0.5s
int led1 = D2;
void setup() {
// Configure the pins to be outputs
pinMode(led1, OUTPUT);
}
void loop() {
for (int i = 0; i < 5; i++) {
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led1, LOW);
delay(500);
}
delay(3000);
}
Click to Expand
//Exercise #3
//Program the LED’s to alternate blinks
void setup() {
// Configure the pins to be outputs
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop() {
for (int i = 0; i < 5; i++) {
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led1, LOW);
delay(500);
digitalWrite(led2, HIGH);
delay(500);
digitalWrite(led2, LOW);
delay(500);
}
delay(3000);
}
Click to Expand
//independent exercise 1
int led1 = D2;
void setup() {
// Configure the pins to be outputs
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
Particle.function("led1", ledControl);
}
void loop() {
}
int ledControl (String command) {
int state = LOW;
if (command == "HIGH") {
for (int i = 0; i < 3; i++) {
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led1, LOW);
delay(500);
}
return 1;
} else if (command == "LOW") {
state = LOW;
return -1;
}
}
Click to Expand
//independent exercise 2
int led1 = D2;
void setup() {
// Configure the pins to be outputs
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
Particle.function("led1", ledControl);
}
void loop() {
}
int ledControl (String command) {
int state = LOW;
int number = atoi(command);
if (number > 0) {
for (int i = 0; i < number; i++) {
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led1, LOW);
delay(500);
}
return 1;
} else {
state = LOW;
return -1;
}
}
Click to Expand
//independent exercise 3
int led1 = D2;
int led2 = D5;
void setup() {
// Configure the pins to be outputs
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
// Initialize both the LEDs to be OFF
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
// //Register our Particle function here
Particle.function("led1", led1Control);
Particle.function("led2", led2Control);
}
void loop() {
}
int led1Control(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(led1, 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(led2, state);
return 1;
}
Click to Expand
This is the first Skill Development assignment that I worked on, so I learned how to work with Argon and the console, and the cloud functions from the start on. The part where we need to connect two LEDs was particularly challenging as I am very new to the idea of building circuits and making things connected.