///////////////////////////////////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
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .