Skill Dev I
Made by Emily Liu · UNLISTED (SHOWN IN POOLS)
Made by Emily Liu · UNLISTED (SHOWN IN POOLS)
LED blink
Created: November 18th, 2021
Exercise 1: blink every 3 seconds
int led1 = D3;
int led2 = D2;
//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.
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop() {
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
delay(500);
digitalWrite(led2, LOW);
}
Click to Expand
int led1 = D3;
void setup() {
pinMode(led1, OUTPUT);
Particle.function("ThreeBlinks", threeBlink);
}
int threeBlink(String a){
digitalWrite(led1, HIGH);
delay(1000);
digitalWrite(led1, LOW);
delay(1000);
digitalWrite(led1, HIGH);
delay(1000);
digitalWrite(led1, LOW);
delay(1000);
digitalWrite(led1, HIGH);
delay(1000);
digitalWrite(led1, LOW);
delay(1000);
return 1;
}
Click to Expand
int led1 = D3;
void setup() {
pinMode(led1, OUTPUT);
Particle.function("ThreeBlinks", threeBlink);
Particle.function("nBlinks", nBlinks);
}
int threeBlink(String a){
digitalWrite(led1, HIGH);
delay(1000);
digitalWrite(led1, LOW);
delay(1000);
digitalWrite(led1, HIGH);
delay(1000);
digitalWrite(led1, LOW);
delay(1000);
digitalWrite(led1, HIGH);
delay(1000);
digitalWrite(led1, LOW);
delay(1000);
return 1;
}
int nBlinks(String a){
int n = a.toInt();
for(int i = 0; i<n; i++){
digitalWrite(led1, HIGH);
delay(1000);
digitalWrite(led1, LOW);
delay(1000);
}
return 1;
}
Click to Expand
int ledPin1 = D2;
int ledPin2 = D3;
void setup() {
// Configure the pins to be outputs
pinMode(ledPin1, OUTPUT);
// Initialize both the LEDs to be OFF
digitalWrite(ledPin1, LOW);
pinMode(ledPin2, OUTPUT);
digitalWrite(ledPin2, LOW);
Particle.function("led1", ledControl1);
Particle.function("led2", ledControl2);
}
void loop() {
// Nothing to do here
}
int ledControl1(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 ledControl2(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