Ahmed Elsagaan
Published

Countdown timer using GLCD shield

Countdown timer using GLCD shield of 1sheeld and Arduino.

BeginnerFull instructions provided6 hours1,888
Countdown timer using GLCD shield

Things used in this project

Story

Read more

Schematics

countdown timer using glcd shield of 1sheeld

Code

countdown timer using glcd shield of 1sheeld

Arduino
/*

This project uses a GLCD shiled of the one shiled to creat a count down counter using a smartphone and arduino with 1sheeld.
*/

#define CUSTOM_SETTINGS
#define INCLUDE_GLCD_SHIELD
#define INCLUDE_BUZZER_SHIELD 
#define INCLUDE_VIBRATION_SHIELD

/* Include 1Sheeld library. */
#include <OneSheeld.h>


/* GLCD Setup */

GLCDRectangle border1(0,0,255,127);
GLCDRectangle border2(2,2,251,123);

/* The  Buttons.*/
GLCDButton  startButton(37,87,97,122,"Start");
GLCDButton  hm(77,4,94,21,"+")  ;
GLCDButton  hl(77,66,94,83,"-") ;
GLCDButton  mm(119,4,136,21,"+");
GLCDButton  ml(119,66,136,83,"-");
GLCDButton  sm(162,4,179,21,"+");
GLCDButton  sl(162,66,179,83,"-");
/*Text boxs */
GLCDTextBox hourTextbox(75,30,"0");
GLCDTextBox minutesTextbox(120,30,"0");
GLCDTextBox secondsTextbox(165,30,"0");

int hours=0,minutes=0,second=0;
int hour_counter,minutes_counter,second_counter;
bool countDownState=false;

void setup() {

/* Start communication with 1Sheeld. */
  OneSheeld.begin();
/* Clear the GLCD. */
  GLCD.clear();
  
/* Draw all shaps. */
  GLCD.draw(border1);
  GLCD.draw(border2);
  GLCD.draw(startButton);
  GLCD.draw(hm);
  GLCD.draw(hl);
  GLCD.draw(mm);
  GLCD.draw(ml);
  GLCD.draw(sm);
  GLCD.draw(sl);
  GLCD.draw(hourTextbox);
  GLCD.draw(minutesTextbox);
  GLCD.draw(secondsTextbox);

/* Change the styles of the buttons to 3D. */
  startButton.setStyle(STYLE_3D);
  hm.setStyle(STYLE_3D);
  hl.setStyle(STYLE_3D);
  mm.setStyle(STYLE_3D);
  ml.setStyle(STYLE_3D);
  sm.setStyle(STYLE_3D);
  sl.setStyle(STYLE_3D);
  
/* Set the button dimensions. */
startButton.setDimensions(64,30);
hm.setDimensions(32,17);
hl.setDimensions(32,17);
mm.setDimensions(32,17);
ml.setDimensions(32,17);
sm.setDimensions(32,17);
sl.setDimensions(32,17);

/* set the size of the numbers*/
 hourTextbox.setSize(MEDIUM);
 minutesTextbox.setSize(MEDIUM);
 secondsTextbox.setSize(MEDIUM);
 
/* Set the button handlers. */
 
  
}

void setButtonTasks()
{
  hm.setOnChange(&hmtask);
  hl.setOnChange(&hltask);
  mm.setOnChange(&mmtask);
  ml.setOnChange(&mltask);
  sm.setOnChange(&smtask);
  sl.setOnChange(&sltask);
  startButton.setOnChange(&startButtontask);
  
}

/*Increase the hourse */
void hmtask(bool state)
{
  if (state){
  hours++;
  if (hours>23)
  {
  hours=0;
  }

/* converting from interger to char array as setText just take char array*/
  char charArray[4];
  String(hours).toCharArray(charArray,4);
  hourTextbox.setText(charArray);
}

//decrease hours 
}
void hltask(bool state)
{
  if (state){
  hours--;
  if (hours<0)
  {
  hours=23;
  }
/* converting from interger to char array as setText just take char array*/
  char charArray[4];
  String(hours).toCharArray(charArray,4);
  hourTextbox.setText(charArray);
  }
}

/*Increase the minutes */
void mmtask(bool state)
{
  if (state){
  minutes++;
  if (minutes>59)
  {
  minutes=0;
  }
  /* converting from interger to char array as setText just take char array*/
  char charArray[4];
  String(minutes).toCharArray(charArray,4);
  minutesTextbox.setText(charArray);
}

//decrease minutes
}
void mltask(bool state)
{
  if (state){
  minutes--;
  if (minutes<0)
  {
  minutes=59;
  }
  /* converting from interger to char array as setText just take char array*/
  char charArray[4];
  String(minutes).toCharArray(charArray,4);
  minutesTextbox.setText(charArray);
  }
}

/*Increase the seconds */
void smtask(bool state)
{
  if (state){
  second++;
  if (second>59)
  {
  second=0;
  }
  /* converting from interger to char array as setText just take char array*/
  char charArray[4];
  String(second).toCharArray(charArray,4);
  secondsTextbox.setText(charArray);
}

//decrease seconds
}
void sltask(bool state)
{
  if (state){
  second--;
  if (second<0)
  {
  second=59;
  }
/* converting from interger to char array as setText just take char array*/
  char charArray[4];
  String(second).toCharArray(charArray,4);
  secondsTextbox.setText(charArray);
  }
}

void startButtontask(bool state)
{ 
   if (state)
  {
      hm.setVisibility(false);
      hl.setVisibility(false);
      mm.setVisibility(false);
      ml.setVisibility(false);
      sm.setVisibility(false);
      sl.setVisibility(false);
      startButton.setVisibility(false);
      hour_counter=hours;
      minutes_counter=minutes;
      second_counter=second;
 
    for ( hour_counter;hour_counter>=0;hour_counter--)
    {
      for (minutes_counter;minutes_counter>=0;minutes_counter--)
      {
        for (second_counter; second_counter>=0;second_counter--)
        {
          char charArray[3];
          String(second_counter).toCharArray(charArray,3);
          secondsTextbox.setText(charArray);
          
         
          String(minutes_counter).toCharArray(charArray,3);
          minutesTextbox.setText(charArray);

          
          String(hour_counter).toCharArray(charArray,3);
          hourTextbox.setText(charArray);
          delay(1000);// delay one second
          
         
        }
        second_counter=59;
      }
      minutes_counter=59;
    }
    /* Vibrate  and buzzer on for 1 second. */
      Buzzer.buzzOn();
      Vibration.start(1000);
      hm.setVisibility(true);
      hl.setVisibility(true);
      mm.setVisibility(true);
      ml.setVisibility(true);
      sm.setVisibility(true);
      sl.setVisibility(true);
      startButton.setVisibility(true);
      Buzzer.buzzOff();
      /* Stop the vibration. */
      Vibration.stop();
      
  }
  hours=0,minutes=0,second=0;
}


/*start button function to countdown */
void loop() {
 
 setButtonTasks();
}

Credits

Ahmed Elsagaan

Ahmed Elsagaan

3 projects • 4 followers
Thanks to 1sheeld.

Comments