Search
 
SCRIPT & CODE EXAMPLE
 

CPP

C++ Counting

/*
	A simple program designed to count in seconds without using the Millis function
	
    The program displays this timer on an I2C LCD screen
    
    Last modified - 01/06/2022
    by Plasma
	*/
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 20, 4); // 20 x 4 I2C LCD screen

LiquidCrystal_I2C lcd(0x27, 16, 2); // 16 x 2 I2C LCD screen

signed short hours, minutes, seconds;
char Total_Time[16];

void setup() {

  lcd.init();
  lcd.backlight();
  lcd.clear();
}

void loop() {
  lcd.setCursor(0,0);
  sprintf(Total_Time, "%0.2d:%0.2d:%0.2d", hours, minutes, seconds);
  lcd.print(Total_Time);

  lcd.setCursor(0,2);
  lcd.print("Your Name");
  
  delay(1000);
  seconds++;
  
  if (seconds == 60) {	// When seconds = 60
    seconds = 0; 	    // Seconds become 0
    minutes ++;			// Adds 1 minute
  }
  if (minutes == 60) {	// When minutes = 60
    minutes = 0;		// Minutes become 0
    hours ++;			// Adds 1 hour
  }
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: mac emoji shortcut 
Cpp :: how to download c++ portable compiler 
Cpp :: quick sort 
Cpp :: how to know the number of a certain substring in a string in c++ 
Cpp :: C++ Increment and Decrement 
Cpp :: print hello world in c++ 
Cpp :: how to initialize 2d array with values c++ 
Cpp :: min element in vector c++ 
Cpp :: c++ exceptions 
Cpp :: stl c++ 
Cpp :: c++ get pointer from unique_ptr 
Cpp :: vector in c++ 
Cpp :: explicit c++ 
Cpp :: c++ inheritance 
Cpp :: lambda function in c++ 
Cpp :: visual studio cpp compiler 
Cpp :: print in c ++ 
Cpp :: rock paper scissor c++ 
Cpp :: Chocolate Monger codechef solution in c++ 
Cpp :: c++ code executio canntot proceed because glew32.dll was not founud 
Cpp :: c++ unittest in ros 
Cpp :: creating node in c++ 
Cpp :: how to pass an array by reference in c++ 
Cpp :: log base e synthax c++ 
Cpp :: initialize a vector with same values 
Cpp :: C++ to specify size and value 
Cpp :: memset in cpp 
Cpp :: c++ switch case 
Cpp :: c++ last element of array 
Cpp :: && c++ 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =