Skip to main content
added some proper grammar, formatted the code with Arduino's autoformat, and changed single character named variables 'S' 'M' and 'H' to seconds, minutes, and hours
Source Link

iI have aan Arduino project to do  , with arduino , to make anwhich requires a countdown timer  (i make thatwhich I've already done)  .I connect I connected a push button  , and i want when I press the butonthat button I need it to increase time with 10+my countdown timer by +10 seconds. Cand

Can anyone help me with adding the code for thethis button?

thereHere is the code: so far(iI declared the button, ibut I don't know if isit's any good):

#include <LiquidCrystal.h> 

int buttonPin = 7; 
int buttonState = 0;
int Sseconds = 30; // count seconds 
int Mminutes = 0; // count minutes
int Hhours = 0; // count hours
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // pins connected to LCD

void setup()
{
  lcd.begin(16, 2); //set up the LCD's number of columns and rows
  pinMode(buttonPin, INPUT);
}
void loop()
{
  buttonState = digitalRead(buttonPin);
  lcd.setCursor(1, 0); 
  lcd.print ("Sosire in:");
  lcd.setCursor(6, 1);
  lcd.print(":");
  lcd.setCursor(9, 1);
  lcd.print(":");
 
 S seconds--;
  delay(1000);
  
 if (S<0seconds < 0)
  {
 M   minutes--;
 S=59;   seconds = 59;
  }
 if (M<0minutes < 0)
  {
 H   hours--;
 M=59;   minutes = 59;
  }
 if (H<0hours < 0)
  { 
 H=0; M=0; S=30; hours = 0;
    minutes = 0;
    seconds = 30;
  } 
 if (M>9minutes > 9)
  {
    lcd.setCursor(7, 1);
    lcd.print(Mminutes);
  }
 else
  {
    lcd.setCursor(7, 1);
    lcd.print("0"); 
    lcd.setCursor(8, 1);
    lcd.print(Mminutes);
    lcd.setCursor(9, 1);
    lcd.print(":");
  }
  
 if (S>9seconds > 9)
  {
    lcd.setCursor(10, 1);
    lcd.print(Sseconds);
  }
 else
  {
    lcd.setCursor(10, 1);
    lcd.print("0"); 
    lcd.setCursor(11, 1);
    lcd.print(Sseconds);
    lcd.setCursor(12, 1);
    lcd.print(" ");
  }
  
 if (H>9hours > 9)
  {
    lcd.setCursor(4, 1);
    lcd.print (Hhours);
  }
 else
  {
    lcd.setCursor(4, 1);
    lcd.print("0"); 
    lcd.setCursor(5, 1);
    lcd.print(Hhours);
    lcd.setCursor(6, 1);
    lcd.print(":");
  }
 if (S==0seconds == 0)
  {
    lcd.clear();
    lcd.print("Este in statie");
    delay(5000);
    lcd.clear();
  }

}

i have a project to do  , with arduino , to make an countdown timer  (i make that already)  .I connect a push button  , and i want when press the buton to increase time with 10+ seconds. Cand anyone help me with the code for the button?

there is the code:(i declared the button, i don't know if is good)

#include <LiquidCrystal.h> 

int buttonPin = 7; 
int buttonState = 0;
int S = 30; // count seconds 
int M = 0; // count minutes
int H = 0; // count hours
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // pins connected to LCD

void setup()
{
 lcd.begin(16,2);//set up the LCD's number of columns and rows
 pinMode(buttonPin, INPUT);
}
void loop()
{
 buttonState = digitalRead(buttonPin);
 lcd.setCursor(1,0); 
 lcd.print ("Sosire in:");
 lcd.setCursor(6,1);
 lcd.print(":");
 lcd.setCursor(9,1);
 lcd.print(":");
 
 S--;
 delay(1000);
  
 if(S<0)
 {
 M--;
 S=59;
 }
 if(M<0)
 {
 H--;
 M=59;
 }
 if(H<0) { H=0; M=0; S=30; } if(M>9)
 {
 lcd.setCursor(7,1);
 lcd.print(M);
 }
 else
 {
 lcd.setCursor(7,1);
 lcd.print("0"); 
 lcd.setCursor(8,1);
 lcd.print(M);
 lcd.setCursor(9,1);
 lcd.print(":");
 }
  
 if(S>9)
 {
 lcd.setCursor(10,1);
 lcd.print(S);
 }
 else
 {
 lcd.setCursor(10,1);
 lcd.print("0"); 
 lcd.setCursor(11,1);
 lcd.print(S);
 lcd.setCursor(12,1);
 lcd.print(" ");
 }
  
 if(H>9)
 {
 lcd.setCursor(4,1);
 lcd.print (H);
 }
 else
 {
 lcd.setCursor(4,1);
 lcd.print("0"); 
 lcd.setCursor(5,1);
 lcd.print(H);
 lcd.setCursor(6,1);
 lcd.print(":");
 }
 if(S==0)
 {
  lcd.clear();
  lcd.print("Este in statie");
  delay(5000);
  lcd.clear();
 }

}

I have an Arduino project to do, which requires a countdown timer(which I've already done). I connected a push button, and when I press that button I need it to increase my countdown timer by +10 seconds.

Can anyone help me with adding the code for this button?

Here is the code so far(I declared the button, but I don't know if it's any good):

#include <LiquidCrystal.h>

int buttonPin = 7;
int buttonState = 0;
int seconds = 30; // count seconds
int minutes = 0; // count minutes
int hours = 0; // count hours
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // pins connected to LCD

void setup()
{
  lcd.begin(16, 2); //set up the LCD's number of columns and rows
  pinMode(buttonPin, INPUT);
}
void loop()
{
  buttonState = digitalRead(buttonPin);
  lcd.setCursor(1, 0);
  lcd.print ("Sosire in:");
  lcd.setCursor(6, 1);
  lcd.print(":");
  lcd.setCursor(9, 1);
  lcd.print(":");

  seconds--;
  delay(1000);

 if (seconds < 0)
  {
    minutes--;
    seconds = 59;
  }
 if (minutes < 0)
  {
    hours--;
    minutes = 59;
  }
 if (hours < 0)
  { 
    hours = 0;
    minutes = 0;
    seconds = 30;
  } 
 if (minutes > 9)
  {
    lcd.setCursor(7, 1);
    lcd.print(minutes);
  }
 else
  {
    lcd.setCursor(7, 1);
    lcd.print("0");
    lcd.setCursor(8, 1);
    lcd.print(minutes);
    lcd.setCursor(9, 1);
    lcd.print(":");
  }

 if (seconds > 9)
  {
    lcd.setCursor(10, 1);
    lcd.print(seconds);
  }
 else
  {
    lcd.setCursor(10, 1);
    lcd.print("0");
    lcd.setCursor(11, 1);
    lcd.print(seconds);
    lcd.setCursor(12, 1);
    lcd.print(" ");
  }

 if (hours > 9)
  {
    lcd.setCursor(4, 1);
    lcd.print(hours);
  }
 else
  {
    lcd.setCursor(4, 1);
    lcd.print("0");
    lcd.setCursor(5, 1);
    lcd.print(hours);
    lcd.setCursor(6, 1);
    lcd.print(":");
  }
 if (seconds == 0)
  {
    lcd.clear();
    lcd.print("Este in statie");
    delay(5000);
    lcd.clear();
  }

}
added 368 characters in body
Source Link
Michel Keijzers
  • 13k
  • 7
  • 43
  • 59

#include <LiquidCrystal.h>

int buttonPin = 7; int buttonState = 0; int S = 30; // count seconds int M = 0; // count minutes int H = 0; // count hours const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; //initialize the library with the numbers of the interface pins LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // pins connected to LCD

void setup() { lcd.begin(16,2);//set up the LCD's number of columns and rows pinMode(buttonPin, INPUT); } void loop() { buttonState = digitalRead(buttonPin); lcd.setCursor(1,0); lcd.print ("Sosire in:"); lcd.setCursor(6,1); lcd.print(":"); lcd.setCursor(9,1); lcd.print(":");

S--; delay(1000);

if(S<0) { M--; S=59; } if(M<0) { H--; M=59; } if(H<0) { H=0; M=0; S=30; } if(M>9) { lcd.setCursor(7,1); lcd.print(M); } else { lcd.setCursor(7,1); lcd.print("0"); lcd.setCursor(8,1); lcd.print(M); lcd.setCursor(9,1); lcd.print(":"); }

if(S>9) { lcd.setCursor(10,1); lcd.print(S); } else { lcd.setCursor(10,1); lcd.print("0"); lcd.setCursor(11,1); lcd.print(S); lcd.setCursor(12,1); lcd.print(" "); }

if(H>9) { lcd.setCursor(4,1); lcd.print (H); } else { lcd.setCursor(4,1); lcd.print("0"); lcd.setCursor(5,1); lcd.print(H); lcd.setCursor(6,1); lcd.print(":"); } if(S==0) { lcd.clear(); lcd.print("Este in statie"); delay(5000); lcd.clear(); }

}

#include <LiquidCrystal.h> 

int buttonPin = 7; 
int buttonState = 0;
int S = 30; // count seconds 
int M = 0; // count minutes
int H = 0; // count hours
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // pins connected to LCD

void setup()
{
 lcd.begin(16,2);//set up the LCD's number of columns and rows
 pinMode(buttonPin, INPUT);
}
void loop()
{
 buttonState = digitalRead(buttonPin);
 lcd.setCursor(1,0); 
 lcd.print ("Sosire in:");
 lcd.setCursor(6,1);
 lcd.print(":");
 lcd.setCursor(9,1);
 lcd.print(":");
 
 S--;
 delay(1000);
  
 if(S<0)
 {
 M--;
 S=59;
 }
 if(M<0)
 {
 H--;
 M=59;
 }
 if(H<0) { H=0; M=0; S=30; } if(M>9)
 {
 lcd.setCursor(7,1);
 lcd.print(M);
 }
 else
 {
 lcd.setCursor(7,1);
 lcd.print("0"); 
 lcd.setCursor(8,1);
 lcd.print(M);
 lcd.setCursor(9,1);
 lcd.print(":");
 }
  
 if(S>9)
 {
 lcd.setCursor(10,1);
 lcd.print(S);
 }
 else
 {
 lcd.setCursor(10,1);
 lcd.print("0"); 
 lcd.setCursor(11,1);
 lcd.print(S);
 lcd.setCursor(12,1);
 lcd.print(" ");
 }
  
 if(H>9)
 {
 lcd.setCursor(4,1);
 lcd.print (H);
 }
 else
 {
 lcd.setCursor(4,1);
 lcd.print("0"); 
 lcd.setCursor(5,1);
 lcd.print(H);
 lcd.setCursor(6,1);
 lcd.print(":");
 }
 if(S==0)
 {
  lcd.clear();
  lcd.print("Este in statie");
  delay(5000);
  lcd.clear();
 }

}

#include <LiquidCrystal.h>

int buttonPin = 7; int buttonState = 0; int S = 30; // count seconds int M = 0; // count minutes int H = 0; // count hours const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; //initialize the library with the numbers of the interface pins LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // pins connected to LCD

void setup() { lcd.begin(16,2);//set up the LCD's number of columns and rows pinMode(buttonPin, INPUT); } void loop() { buttonState = digitalRead(buttonPin); lcd.setCursor(1,0); lcd.print ("Sosire in:"); lcd.setCursor(6,1); lcd.print(":"); lcd.setCursor(9,1); lcd.print(":");

S--; delay(1000);

if(S<0) { M--; S=59; } if(M<0) { H--; M=59; } if(H<0) { H=0; M=0; S=30; } if(M>9) { lcd.setCursor(7,1); lcd.print(M); } else { lcd.setCursor(7,1); lcd.print("0"); lcd.setCursor(8,1); lcd.print(M); lcd.setCursor(9,1); lcd.print(":"); }

if(S>9) { lcd.setCursor(10,1); lcd.print(S); } else { lcd.setCursor(10,1); lcd.print("0"); lcd.setCursor(11,1); lcd.print(S); lcd.setCursor(12,1); lcd.print(" "); }

if(H>9) { lcd.setCursor(4,1); lcd.print (H); } else { lcd.setCursor(4,1); lcd.print("0"); lcd.setCursor(5,1); lcd.print(H); lcd.setCursor(6,1); lcd.print(":"); } if(S==0) { lcd.clear(); lcd.print("Este in statie"); delay(5000); lcd.clear(); }

}

#include <LiquidCrystal.h> 

int buttonPin = 7; 
int buttonState = 0;
int S = 30; // count seconds 
int M = 0; // count minutes
int H = 0; // count hours
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // pins connected to LCD

void setup()
{
 lcd.begin(16,2);//set up the LCD's number of columns and rows
 pinMode(buttonPin, INPUT);
}
void loop()
{
 buttonState = digitalRead(buttonPin);
 lcd.setCursor(1,0); 
 lcd.print ("Sosire in:");
 lcd.setCursor(6,1);
 lcd.print(":");
 lcd.setCursor(9,1);
 lcd.print(":");
 
 S--;
 delay(1000);
  
 if(S<0)
 {
 M--;
 S=59;
 }
 if(M<0)
 {
 H--;
 M=59;
 }
 if(H<0) { H=0; M=0; S=30; } if(M>9)
 {
 lcd.setCursor(7,1);
 lcd.print(M);
 }
 else
 {
 lcd.setCursor(7,1);
 lcd.print("0"); 
 lcd.setCursor(8,1);
 lcd.print(M);
 lcd.setCursor(9,1);
 lcd.print(":");
 }
  
 if(S>9)
 {
 lcd.setCursor(10,1);
 lcd.print(S);
 }
 else
 {
 lcd.setCursor(10,1);
 lcd.print("0"); 
 lcd.setCursor(11,1);
 lcd.print(S);
 lcd.setCursor(12,1);
 lcd.print(" ");
 }
  
 if(H>9)
 {
 lcd.setCursor(4,1);
 lcd.print (H);
 }
 else
 {
 lcd.setCursor(4,1);
 lcd.print("0"); 
 lcd.setCursor(5,1);
 lcd.print(H);
 lcd.setCursor(6,1);
 lcd.print(":");
 }
 if(S==0)
 {
  lcd.clear();
  lcd.print("Este in statie");
  delay(5000);
  lcd.clear();
 }

}
Source Link

Arduino Timer with increase time button

i have a project to do , with arduino , to make an countdown timer (i make that already) .I connect a push button , and i want when press the buton to increase time with 10+ seconds. Cand anyone help me with the code for the button?

there is the code:(i declared the button, i don't know if is good)

#include <LiquidCrystal.h>

int buttonPin = 7; int buttonState = 0; int S = 30; // count seconds int M = 0; // count minutes int H = 0; // count hours const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; //initialize the library with the numbers of the interface pins LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // pins connected to LCD

void setup() { lcd.begin(16,2);//set up the LCD's number of columns and rows pinMode(buttonPin, INPUT); } void loop() { buttonState = digitalRead(buttonPin); lcd.setCursor(1,0); lcd.print ("Sosire in:"); lcd.setCursor(6,1); lcd.print(":"); lcd.setCursor(9,1); lcd.print(":");

S--; delay(1000);

if(S<0) { M--; S=59; } if(M<0) { H--; M=59; } if(H<0) { H=0; M=0; S=30; } if(M>9) { lcd.setCursor(7,1); lcd.print(M); } else { lcd.setCursor(7,1); lcd.print("0"); lcd.setCursor(8,1); lcd.print(M); lcd.setCursor(9,1); lcd.print(":"); }

if(S>9) { lcd.setCursor(10,1); lcd.print(S); } else { lcd.setCursor(10,1); lcd.print("0"); lcd.setCursor(11,1); lcd.print(S); lcd.setCursor(12,1); lcd.print(" "); }

if(H>9) { lcd.setCursor(4,1); lcd.print (H); } else { lcd.setCursor(4,1); lcd.print("0"); lcd.setCursor(5,1); lcd.print(H); lcd.setCursor(6,1); lcd.print(":"); } if(S==0) { lcd.clear(); lcd.print("Este in statie"); delay(5000); lcd.clear(); }

}