HyperChiicken
Published © MIT

Pomodoro Timer Thingamajig

Be a productivity monster by connecting DC/AC stuff to your Pomodoro Timer Thingamajig! A pomodo timer using an MSP430 and a relay board.

BeginnerShowcase (no instructions)2 hours70
Pomodoro Timer Thingamajig

Things used in this project

Hardware components

MSP-EXP430G2 MSP430 LaunchPad
Texas Instruments MSP-EXP430G2 MSP430 LaunchPad
×1
Sainsmart 4-Port Relay
×1
Arcade Button w/ LED
×1
RGB LED
×1
2-state Switch
×1

Software apps and online services

Energia
Texas Instruments Energia

Story

Read more

Code

Pomodoro_Timer.ino

Arduino
Upload this to your MSP430 using Energia. If there is a significant delay before the program starts, changes need to be made on boards.txt file (depending on your specific MSP430 model).
/*

Pomodoro Timer Thingamajig

Set off AC/DC devices with respect to current timer state.
The states are the following:
	-Work Time
	-Transition Time
	-Break Time
	-Long Break Time

These times can easily changed by reassigning work_time, break_time, and ext_break_time	
by: HyperChiicken

 */
#ifdef __cplusplus
extern "C" {
#endif
void enableXtal() {
  // avoid startup delay
}
#ifdef __cplusplus
}
#endif

#define PIN_RED RED_LED
#define PIN_GREEN GREEN_LED
#define PIN_BLUE P2_5
#define CH1 P2_1
#define CH2 P2_2
#define CH3 P2_3
#define CH4 P2_4

/* Set pomodoro timers in MINUTES!*/
const unsigned long work_time = 27;	//offset due to internal clock drift
const unsigned long break_time = 5;
const unsigned long ext_break_time = 32; //offset due to internal clock drift
const long interval = 333;
int ledState = LOW;
/* Set variables */
unsigned long current_time, minutes, work_time_min, break_time_min, ext_break_time_min;
unsigned long seconds = 1000; // 1000 millis = 1 second
unsigned long start_time = 0;
unsigned long previousMillis = 0;  
int pom_count = 0;  //counter for how many times you went on break
bool state = 0;
bool buttonState = 1;
bool prevState = 1;

void setup() {
  // Set LED pins
  pinMode(PIN_RED, OUTPUT);
  pinMode(PIN_GREEN, OUTPUT);
  pinMode(PIN_BLUE, OUTPUT);
  // Set output GPIO pins
  pinMode(CH1, OUTPUT);
  pinMode(CH2, OUTPUT);
  pinMode(CH3, OUTPUT);
  pinMode(CH4, OUTPUT);
  
  
  digitalWrite(PIN_RED, HIGH); // start work
  digitalWrite(PIN_GREEN, LOW); // stop rest
  digitalWrite(PIN_BLUE, LOW);  
  
  // Initialize GPIO states
  digitalWrite(CH1, LOW);
  digitalWrite(CH2, LOW);
  digitalWrite(CH3, LOW); 
  digitalWrite(CH4, LOW);  
  
  
  pinMode(P2_0,INPUT_PULLUP);  //set the pin to input, with pull-up resistor
  attachInterrupt(P2_0,button_ISR,FALLING); // and initially set the interrupt for falling.
  
  minutes = 60 * seconds;
  work_time_min = work_time * minutes;

}

void loop() {
  switch (state){
    case 0:
      work_mode();
      flash_and_press();
      break;
    case 1:
      break_mode();
      flash_and_press(); 
      break;
    default:
      Serial.println("ERROR");
      break; 
  }
}

void work_mode(){    
  digitalWrite(PIN_RED, HIGH);
  digitalWrite(PIN_GREEN, LOW);
  digitalWrite(PIN_BLUE, LOW);

  digitalWrite(CH1, HIGH);  //turn on CH1
  
  while (millis()-start_time < work_time_min); //loop while timer is less than allotted time
}

void break_mode() {
  if (pom_count == 2) {
    digitalWrite(CH4, HIGH);  //turn on CH4
    break_time_min = ext_break_time * minutes;  //set break time to extended when you took a break 4 times
    pom_count = 0;  //reset pomodoro counter

    digitalWrite(PIN_RED, LOW);
    digitalWrite(PIN_GREEN, LOW);
    digitalWrite(PIN_BLUE, HIGH);  //turn on BLUE LED
  } 
  else {
    digitalWrite(CH3, HIGH); //turn on CH3
    break_time_min = break_time * minutes;  //set break time to regular minutes

    digitalWrite(PIN_RED, LOW);
    digitalWrite(PIN_GREEN, HIGH);
    digitalWrite(PIN_BLUE, LOW);
    
  }
  
  while (millis()-start_time < break_time_min); //loop while timer is less than allotted time

  pom_count++;
}

void flash_and_press() {
  
  prevState = buttonState;
  
  digitalWrite(CH1, LOW); //turn off CH1
  digitalWrite(CH2, HIGH);//turn on CH2
  digitalWrite(CH3, LOW); //turn off CH3
  digitalWrite(CH4, LOW); //turn off CH4
	
  // Flash all LEDs at the same time
  do { 
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
      // save the last time you blinked the LED
      previousMillis = currentMillis;

      // if the LED is off turn it on and vice-versa:
      if (ledState == LOW) {
        ledState = HIGH;
      } else {
        ledState = LOW;
      }
    
    digitalWrite(PIN_RED, ledState);
    digitalWrite(PIN_GREEN, ledState);
    digitalWrite(PIN_BLUE, ledState);
  }
  
  } while (buttonState == prevState);

    digitalWrite(CH2, LOW); //turn off CH2
    start_time = millis();  
    state = !state;
  }

void button_ISR() {
  buttonState = !buttonState;

  P2IES=(P2IES & ~B00000001) | (P2IN & B00000001);
}

Credits

HyperChiicken

HyperChiicken

10 projects • 12 followers
I cobble things together :]

Comments

Add projectSign up / Login