TimerInstance_Class

LCD digital clock

(:source lang=c :) /*Timer library - digital clock/chronometer demo.

 demonstrates the use of timer functionalities within a 16x2 LCD display.
 VGALiquidCrystal library works with all LCD displays that are compatible with the 
 Hitachi HD44780 driver.
 Created 17/10/2013 by Nassim TLILI */

// Include the library code

  1. include <Timer.h>
  2. include <LiquidCrystal.h>
  3. include <VGA.h>
  4. include <VGALiquidCrystal.h>

// Initialize the LCD instance with the number of interface pins LiquidCrystal lcd(14,13,12,11,10,9,8); //connect LCD Wing to AH, change all instances of AH to your desired wing slot

// Creating Timers_class variable Zpuino::Timers_class Timers;

// second, minute, hour variables (two for each one) int s1,S2,m1,m2,h1,h2;

// Displaying function void display () {

   lcd.setCursor(1,1); lcd.print(h2);  //column 2, row 2
   lcd.setCursor(2,1); lcd.print(h1);  //column 3, row 2
   lcd.setCursor(3,1); lcd.print(":");
   lcd.setCursor(4,1); lcd.print(m2);
   lcd.setCursor(5,1); lcd.print(m1);
   lcd.setCursor(6,1); lcd.print(":");
   lcd.setCursor(7,1); lcd.print(s2);
   lcd.setCursor(8,1); lcd.print(s1);

}

// The function used to handle timer interruption void handle_interrupt () {

   //incrementing the colck
   s1++;
   //controlling value transition
   if (s1==10) {s1=0; s2++;}
   if (s2==6)  {s1=s2=0; m1++;}
   if (m1==10) {s1=s2=m1=0; m2++;}
   if (m2==6)  {s1=s2=m1=m2=0; h1++;}
   if (h1==10) {s1=s2=m1=m2=h1=0; h2++;}
   if (h1==4 && h2==2)  {s1=s2=m1=m2=h1=h2=0;}
   //displying new clock state
   display ();

}

// The main setup void setup() {

   s1=s2=m1=m2=h1=h2=0;    //initialize displaying variables
   pinMode(15,Output);     //set contrast to GND
   digitalWrite(15,LOW);   //set contrast to GND
   lcd.begin(16,2);        //set up the LCD's number of columns and rows
   lcd.noCursor();         //hide the cursor
   lcd.clear();            //clear the LCD screen
   Timers.begin();         //initialize the timers
   display();              //the first display 00:00:00
   Timers.periodic(1000,&handle_interrupt,-1)  //calling the handling function each one second

} //infinite loop void loop() { }

(:sourceend:)

  

Share |