Back to Parent

// Include Particle Device OS APIs
#include "Particle.h"

int solPin = D2;
bool startt = false;

int motortimes = 5;
int delay1 = 500;
int delay2 = 300;
int delay3 = 100;
int timelef = 5; //5,3,1 import when only have 5 minites   50%-20%-10%
int phase1 = 0.5;
int phase2 = 0.3;
int phase3 = 0.1;

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

void setup(){
     Serial.begin(9600);
     pinMode( solPin, OUTPUT);
     Particle.function("Start to Count", start);
     
     Particle.function("SetDelay1", delay11);
     Particle.function("SetDelay2", delay22);
     Particle.function("SetDelay3", delay33);
     
     Particle.function("motortimes",motortime);
     Particle.function("bustimeleftset",lefttime);

}
 
 void loop(){
     if (startt){
        for(int i = 0; i < motortimes; i++){
            Serial.println("on");
            digitalWrite(solPin, HIGH);
            delay(delay1); //focus on delay
        
            Serial.println("off");
            digitalWrite(solPin, LOW);
            delay(delay1);
            // in 1-0.5
        } 
        delay(minite*timelef*phase1 - motortimes*delay1*2);
        
        for(int j = 0; j < motortimes; j++){
            Serial.println("on");
            digitalWrite(solPin, HIGH);
            delay(delay2); //focus on delay
        
            Serial.println("off");
            digitalWrite(solPin, LOW);
            delay(delay2);
            
        } // in 0.5-0.3
        delay(minite*timelef*phase2 - motortimes*delay2*2);
        
        for(int l = 0; l < motortimes; l++){
            Serial.println("on");
            digitalWrite(solPin, HIGH);
            delay(delay3); //focus on delay
        
            Serial.println("off");
            digitalWrite(solPin, LOW);
            delay(delay3);
            
        } // in 0.3-0.1
        delay(minite*timelef*phase3 - motortimes*delay3*2);
     }
     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 delay22(String cmd){
     Serial.println("SetDelay2"+ cmd);
     int value = cmd.toInt();
     
     if(value<0)return -1;
     if(value>1000)return -1;
     if(value>delay1)return -1;
     delay2 = constrain(value, 0, 1000);
     return 1;
 }
 
  int delay33(String cmd){
     Serial.println("SetDelay3"+ cmd);
     int value = cmd.toInt();
     
     if(value<0)return -1;
     if(value>1000)return -1;
     if(value>delay2)return -1;
     delay3 = 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<3)return -1;
     if(value>20)return -1;
     
     timelef = constrain(value, 3, 20);
     return 1;
 }
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0