Skip to content

Instantly share code, notes, and snippets.

@technobly
Last active July 6, 2016 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technobly/910c66f30c7c50fa56231ed215de5e42 to your computer and use it in GitHub Desktop.
Save technobly/910c66f30c7c50fa56231ed215de5e42 to your computer and use it in GitHub Desktop.
Super simple Pomodoro Timer via the Particle Internet Button!
// This #include statement was automatically added by the Particle IDE.
#include "InternetButton/InternetButton.h"
InternetButton b = InternetButton();
uint32_t workTime = 0;
uint32_t restTime = 0;
// Time definitions in milliseconds
uint32_t WORKPERIOD = 25*60*1000; // 25 minutes
uint32_t RESTPERIOD = 5*60*1000; // 5 minutes
bool startTimer = false;
bool resetTimer = false;
bool workDone = false;
uint8_t ledNum = 0;
void setup()
{
//initiating Internet button
b.begin();
initPomo();
}
void loop() {
checkButton();
pomoMain();
}
void pomoMain() {
// Start the work time sequence
if ((startTimer == true) && (workDone == false))
{
if(millis()-workTime >= WORKPERIOD/8)
{
workTime = millis();
if (ledNum < 9)
{
ledNum++;
b.ledOn(ledNum, 0,100,10);
}
if (ledNum == 8)
{
workDone = true;
Particle.publish("Pomo", "WORK ENDED",PRIVATE);
b.playSong("E5,2,G5,8,E6,8,C6,4,D6,8,G6,8\n"); //song that plays at completion of work time
b.ledOn(9, 100, 0,50);
ledNum++;
Particle.publish("Pomo", "REST STARTED",PRIVATE);
restTime = millis();
}
}
}
// If work time is complete, move on to rest time sequence
else if ((startTimer == true) && (workDone == true))
{
if(millis()-restTime >= RESTPERIOD/2)
{
restTime = millis();
if (ledNum < 12 )
{
ledNum++;
b.ledOn(ledNum, 100, 0,50);
}
if (ledNum == 11)
{
startTimer = false;
Particle.publish("Pomo", "REST ENDED",PRIVATE);
b.playSong("C6,4,G4,8,G4,8,A4,4,G4,4,0,4,B4,4,C5,4\n"); //song that plays at completion of rest time
b.allLedsOff();
initPomo();
}
}
}
}
// Initialize the timer
void initPomo(){
ledNum = 0;
b.allLedsOff();
workTime = 0;
restTime = 0;
startTimer = false;
resetTimer = false;
}
// Check which button is pressed
void checkButton(){
// If either button 2,3 or 4 is pressed, start the timer
if( b.buttonOn(2) || b.buttonOn(3) || b.buttonOn(4)){
delay(100);
b.ledOn(1, 0,100,10);
Particle.publish("Pomo", "WORK STARTED", PRIVATE);
startTimer = true;
resetTimer = false;
workDone = false;
delay(100);
}
// If button 1 is pressed, reset the timer
if( b.buttonOn(1)){
b.playSong("E6,8,G6,8\n");
delay(50);
initPomo();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment