Hello there.
I'm trying to make percent timer by using arduino. But can't find any example code on internet. I will control percentage by Blynk slider. Can anyone help me please?
Thanks in advance.
#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM900
#include <SoftwareSerial.h>
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
#include <SimpleTimer.h>
BlynkTimer timer;
SoftwareSerial SerialAT(7, 8);
TinyGsm modem(SerialAT);
char apn = "internet";
char user = "";
char pass = "";
int startrelay = 9;
int startrelesi = 0;
bool startrelesiON;
unsigned long cycleTime = 60000;
unsigned long starttime ;
unsigned long onTime ;
unsigned long lastTime = 0;
float percent = 0;
char auth = "MyAuth";
BLYNK_WRITE(V3){ // START/STOP switch button in blynk app
startrelesi = param.asInt();
if (startrelesi== HIGH)
{
Blynk.virtualWrite(V3, param.asInt());
}
else {
digitalWrite(startrelay, LOW);
Blynk.virtualWrite(V3, LOW);
}
}
BLYNK_WRITE(V6){ //slider for percentage adjusting from blynk app
percent = param.asFloat();
starttime = cycleTime * (1-(percent/100))-1000;
onTime = cycleTime * (percent/100);
Blynk.virtualWrite(V5, percent);
}
void start(){
Blynk.virtualWrite(V3,startrelesi);
if(millis() - starttime < onTime)
startrelesiON = true;
else
startrelesiON = false;
if(millis() - starttime > cycleTime)
starttime += cycleTime; // starttime= starttime + cycleTime
if((startrelesiON == true) && (startrelesi == HIGH ) ){
digitalWrite(startrelay,HIGH);
}
else
digitalWrite(startrelay,LOW);
}
void setup(){
pinMode(12, OUTPUT);
digitalWrite(12,LOW);
delay(1000);
digitalWrite(12,HIGH);
delay(2000);
SerialAT.begin(9600);
modem.restart();
Blynk.begin(auth, modem, apn, user, pass);
pinMode(startrelay, OUTPUT);
Blynk.virtualWrite(V6,0);// Slider in Blynk app
Blynk.virtualWrite(V3,0); // toggle button in Blynk app
Blynk.virtualWrite(V5,0);// labeled value in Blynk app
}
void loop(){
//CheckConnection();
timer.run();
Blynk.run();
start();
}