// Include Particle Device OS APIs
#include "Particle.h"
int solPin = D2;
bool startt = false;
int motortimes = 5;
int delay1 = 500;
int timelef = 5;
int phasenum = 3;
int minite = 60000;
//you can set the time reminder how many minites left you want to be reminded
//according to the percentage to change the frequency
//(1/2)**n
void setup(){
Serial.begin(9600);
pinMode( solPin, OUTPUT);
Particle.function("Start to Count", start);
Particle.function("SetDelay1", delay11);
Particle.function("motortimes",motortime);
Particle.function("bustimeleftset",lefttime);
Particle.function("phasenumm",phasenum1);
}
void loop(){
if (startt){
for(int i = 0; i < phasenum; i++){
for(int j = 0; j < motortimes; j++){
Serial.println("on");
digitalWrite(solPin, HIGH);
delay(delay1* (phasenum/i));
Serial.println("off");
digitalWrite(solPin, LOW);
delay(delay1* (phasenum/i));
}
delay(pow(1/2,i+1)*timelef*minite - (delay1*(phasenum/i)));
}
}
startt = false;
}
int start(String cmd){
startt = true;
return 1;
}
int delay11(String cmd){
Serial.println("SetDelay1"+ cmd);
int value = cmd.toInt();
if(value<0)return -1;
if(value>1000)return -1;
delay1 = constrain(value, 0, 1000);
return 1;
}
int motortime(String cmd){
Serial.println("motortimes"+ cmd);
int value = cmd.toInt();
if(value<0)return -1;
if(value>5)return -1;
motortimes = constrain(value, 0, 5);
return 1;
}
int lefttime(String cmd){
Serial.println("bustimeleftset"+ cmd);
int value = cmd.toInt();
if(value<0)return -1;
if(value>20)return -1;
timelef = constrain(value, 0, 20);
return 1;
}
int phasenum1(String cmd){
Serial.println("phasenumm"+ cmd);
int value = cmd.toInt();
if(value<2)return -1;
if(value>10)return -1;
phasenum = constrain(value, 2, 10);
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. .