Configurable countdown timer

Dependencies:   mbed PinDetect TextLCD

main.cpp

Committer:
MarceloSalazar
Date:
2020-06-06
Revision:
2:ecbc6a14824c
Parent:
1:0ed57c2fd528
Child:
3:3facd92a3f37

File content as of revision 2:ecbc6a14824c:

#include "mbed.h"
#include "TextLCD.h"

DigitalOut myled(LED1);

//TextLCD(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type = LCD16x2);
// Note: VCC=5V, V0=0V, via 330 resistor)
TextLCD lcd(p15, p16, p17, p18, p19, p20);

Ticker flipper;

volatile int t1s = 0;

volatile char seconds = 0;
volatile char minutes = 25;
volatile char hours = 0;
volatile char alarm = 1;   // alarm set on/off ==> enables buzzer
 
void update_lcd() {
    lcd.locate (0,1);
    lcd.printf("%02d:%02d:%02d",hours, minutes, seconds);
}

void flip() {
    t1s = 1;
}

void count_down(){
  
  if(seconds == 0 && minutes == 0 && hours == 0)
      return;
  
  if(seconds != 0) {
      seconds -= 1;
      return;
  }
  
  if(minutes != 0){
      minutes -= 1;
      seconds = 59;
      return;      
  }
  
  if(hours != 0){
      hours -= 1;
      minutes = 59;
      seconds = 59;
      return;    
  }    
}
 
int main () {
    
    // Clean screen
    lcd.cls();
    lcd.printf("Countdown");

    update_lcd(); 
          
    flipper.attach(&flip, 1.0); // interval 1 second
  
    while(1) {
        if (t1s){
          t1s = 0;
          myled = !myled;
          count_down();
          update_lcd(); 
        }
   }
}