You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Start a time entry when a momentary button is pressed.
A LED will also light up while the timer is running!
The timer will stop when the button is pressed a second time.
The LED will also turn of once the timer is stopped!
The LED will also light up if a timer is started/ running through the website. The LED will also turn off if the timer is stopped remotely.
It is also able to stop a timer that is started through the website.
NOTE: This example is slower than the simple button but adds a fluid transition between the website and the independent "ESP Button".
/*This is an "advanced" version of the Button example.It uses a momentary button to start and stop a timer.The timer will start if no timer is active, otherwise it will stop the timer.A LED will light up and indicate if a timer is started or running.The LED will turn of if the timer is stopped either through a button press or the website.*/
#include<Toggl.h>constchar* SSID = "SSID";
constchar* PASS = "PASSWORD";
// Toggl informationintconst PID{123456789}; //Project ID is specific to each user project
String const Token{"TOKEN"}; //API Token is found in "Profile Settings" charconst Description[]{"HelloWorld"}; // Timer descriptioncharconst TagName[]{""}; // Timer tag nameconstint ButtonPin = D7;
constint LedPin = D8;
bool TOGGLE = true;
bool BUTTON = false;
bool TimerActive = false;
void ICACHE_RAM_ATTR HandleInterrupt();
Toggl toggl;
voidsetup(){
pinMode(LedPin, OUTPUT);
pinMode(ButtonPin, INPUT);
digitalWrite(LedPin, LOW);
Serial.begin(115200);
attachInterrupt(digitalPinToInterrupt(ButtonPin), HandleInterrupt, FALLING); // Triggers on falling edge, change it to "RISING" depending on your button.
toggl.init(SSID,PASS);
toggl.setAuth(Token);
}
voidHandleInterrupt() {
BUTTON = true;
}
voidloop(){
TimerActive = toggl.isTimerActive();
// Button is pressed and the timer startsif(TOGGLE == true && BUTTON == true && TimerActive == false){
digitalWrite(LedPin, HIGH);
toggl.StartTimeEntry(Description, TagName, PID, "ESP");
TimerActive = true;
TOGGLE = false;
BUTTON = false;
}
// Button is pressed and the timer stopsif (TOGGLE == false && BUTTON == true && TimerActive == true){
digitalWrite(LedPin, LOW);
toggl.StopTimeEntry(toggl.getTimerID());
TimerActive = false;
TOGGLE = true;
BUTTON = false;
}
// Keeping LED active if timer is runningelseif(TimerActive == true){
digitalWrite(LedPin, HIGH);
TOGGLE = false;
}
// Keeping LED off if timer is not runningelseif (TimerActive == false){
digitalWrite(LedPin, LOW);
TOGGLE = true;
}
}