#include "math.h"
int ledPin1 = D2;
int ledPin2 = D1;
int ledPin3 = D0;
bool isEmitting;
int brightness1 = 0;
int fadeAmount1 = 5;
int brightness2 = 85;
int fadeAmount2 = 5;
int brightness3 = 170;
int fadeAmount3 = 5;
int myValue;
int fan = A0;
void setup ()
{
isEmitting = false;
pinMode(fan, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
digitalWrite(fan,LOW);
Particle.function("led",ledToggle);
}
void loop ()
{
if(isEmitting){
SendScent();
}else{
StopSendingScent();
}
}
void SendScent(){
myValue = random(255);
// digitalWrite(ledPin2,HIGH);
analogWrite(ledPin1, brightness1);
analogWrite(ledPin2, brightness2);
analogWrite(ledPin3, brightness3);
digitalWrite(fan, HIGH);
brightness1 = brightness1 + fadeAmount1;
brightness2 = brightness2 + fadeAmount2;
brightness3 = brightness3 + fadeAmount3;
if (brightness1 <= -50 || brightness1 >= 255) {
fadeAmount1 = -fadeAmount1;
}
if (brightness2 <= -50|| brightness2 >= 255) {
fadeAmount2 = -fadeAmount2;
}
if (brightness3 <= -50 || brightness3 >= 255) {
fadeAmount3 = -fadeAmount3;
}
delay(15);
}
void StopSendingScent(){
analogWrite(ledPin1, 0);
analogWrite(ledPin2, 0);
analogWrite(ledPin3, 0);
digitalWrite(fan, LOW);
}
int ledToggle(String command) {
if (command=="on") {
isEmitting = true;
return 1;
}
else if (command=="off") {
isEmitting = false;
return 0;
}
else {
return -1;
}
}
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. .