Push button timer and LCD readout sketch needed

I have looked around for a sketch to play with but can not really find what I am looking for.

I would like to have a button that when pushed, switches from the main screen to a countdown timer of, oh, say 15 minutes to deactivate a relay(s). Every time the button is pushed, from the first time, it adds 15 minutes. I would then like to see the progress/countdown on the screen. After the timer reaches 0, it will resume its regular function of running things on my reef tank and show the main screen again.

Is this something easy to do? Does anyone have an idea of some example code or has the ability to whip up something? I am barley comfortable with setting up an LCD screen.

Im not lazy, but, besides "toggling" on/off a LED, thats about all I can do. Heck, I cant even find that! I am dumber than a Rottweiler and should not even have an Arduino in my hand as I doubt I will get much further than the clock, but, I like to hack away at things and refuse to lay down. I would, however, like to as least have something working this week, other than a clock, and, rather than by next year. So, if you have some ideas, please share, thanks.

start with getting your LCD to display using the Hello World! example in the IDE:

the rest is easy....

Oh, I already have it to where I have made my print screen sketches in the void setup, cleared, have a title on the screen and the temp, time and date at the bottom of my 20x4 with the void loop list. I can even maneuver between parallel and SPI screens with not to much of a problem.

The problem is, i can NOT "write" code. I can only take what is available to me and manipulate that. It either works or I start from the beginning. I don't really have the time to learn coding, barley enough to manipulate what I can find, which still looks greek to me. Sure, I may "get it" one day but I will be dead by then and it wont do me much good. It took me a month to deal with the clock and like 20 sketches I found. Still dont know squat about coding, just what I can do and can not do with the sketches I have. I really dont want to wait another month just to toggle a LED (which will be a set of relays eventually). I don't mind taking a sketch and working with it, but, no way in the world I could program it. Whats easy for some, just doesn't work for others.

Links to working sketches would be fine also.

I don't really have the time to learn coding, barley enough to manipulate what I can find,

We are here to help, not do it for you. Might be better to pop open a beer and do some learning.

1ArduinoFan:
Oh, I already have it to where I have made my print screen sketches in the void setup, cleared, have a title on the screen and the temp, time and date at the bottom of my 20x4 with the void loop list. I can even maneuver between parallel and SPI screens with not to much of a problem.

The problem is, i can NOT "write" code. I can only take what is available to me and manipulate that. It either works or I start from the beginning. I don't really have the time to learn coding, barley enough to manipulate what I can find, which still looks greek to me. Sure, I may "get it" one day but I will be dead by then and it wont do me much good. It took me a month to deal with the clock and like 20 sketches I found. Still dont know squat about coding, just what I can do and can not do with the sketches I have. I really dont want to wait another month just to toggle a LED (which will be a set of relays eventually). I don't mind taking a sketch and working with it, but, no way in the world I could program it. Whats easy for some, just doesn't work for others.

Links to working sketches would be fine also.

post your LCD sketch that works...

steinie44:

I don't really have the time to learn coding, barley enough to manipulate what I can find,

We are here to help, not do it for you. Might be better to pop open a beer and do some learning.

And what if I just cant do it? Not everyone can rebuild an automatic transmission. They may, if they are lucky, able to change the oil and maybe adjust a band it thats an option, but, to pull all the bolts out to remove it, pull the front pump ass and replace the clutch plates and seals? Maybe you expect said person to be able to construct a nuclear bomb also? Some cant do it, I dont care HOW many beers they drink. I am sure everyone can push a bomb out of a plane after they already get it, get my point? I even asked for some links and I would try to reverse engineer it. I wasn't just asking for someone to "just" do it ALL for me. I do appreciate the pep talk though. Besides, the more beer I drink, the less I seem to understand.

Code update: Noticed my AM hours were not showing. I had to go through the script to figure out what was wrong. Not sure what it was, but, more cutting and copying seemed to fix it.

//V1 - original release

#include <Wire.h>
#include <DS3231.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR      0x27 // I2C address of PCF8574A
#define BACKLIGHT_PIN 3
#define En_pin        2
#define Rw_pin        1
#define Rs_pin        0
#define D4_pin        4
#define D5_pin        5
#define D6_pin        6
#define D7_pin        7

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin, BACKLIGHT_PIN, POSITIVE);
 //////////////Create the DS3231 object///////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////
DS3231 RTC;

int seconds; 
int minutes; 
int hours;
int adjHours;

int dayOfWeek;
int dayOfMonth;
int month;
int year;

int tempC;
int tempF;

void setup(){
    Serial.begin(9600);
    Wire.begin();
     // RTC.begin();
     ////////////// force time setting //////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////
  
     /* seconds = 00;
     minutes = 52;
     hours = 23; //in 24 hour mode
     dayOfWeek = 3; //1 is Sunday
     dayOfMonth = 19;
     month = 8;
     year = 14;
     initChrono();//just set the time once on your RTC
     */
  
     //////////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////////

    lcd.begin(20, 4); // tells Arduino the LCD dimensions

    lcd.setCursor(0,0);
    lcd.print("    ***WHOOPS***");  
    lcd.setCursor ( 0, 1 );        // go to the 2nd line
    lcd.print(" !!Error Detected!!");
    lcd.setCursor ( 0, 2 );        // go to the third line
    lcd.print(" > Resetting Unit <");
    lcd.setCursor ( 0, 3 );        // go to the fourth line
    lcd.print("  Please stand by.");
    lcd.noBlink();
    delay(2000);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(" Chris's Reef Tank");
    lcd.setCursor(18,1);
    lcd.print("v3");
}

void loop() {

  ////////////poll the DS3231 for the date and time////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////
  get_time(); 
  get_date();

  tempC = RTC.getTemperature();
  tempF = (tempC * 1.8) + 32.0; // Convert Celcius to Fahrenheit
  
 

  Serial.print("adj hours:");
  Serial.print(adjHours);
  Serial.println(" ");
  Serial.print("mins:");
  Serial.print(minutes);
  Serial.println(" ");

    ////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////

    //first line - TIME
    //pass RTC values into a new variable - this way one variable stores
   // time in 24 hour mode and another that can be converted to 12 hour
   // mode time is monitored 'in the background' in 24 hour mode using the RTC,
    // but is displayed in an adjusted 12-hr format

   ////////////convert to 12 hr mode for display////////////////////////////////////
   ////////////////////////////////////////////////////////////////////////////////
  lcd.setCursor(0,3);  
   
 if (hours < 1)
{
 adjHours = 12;
}
 if ((hours > 12) && (hours < 24)) {
 adjHours = hours - 12;
}
 if (adjHours <10) {
 lcd.print(" ");
 lcd.print(adjHours);
} 
 else 
{
 lcd.print(adjHours);
}
{
 lcd.print(":");
}
//display minutes
 if(minutes < 10)
{
 lcd.print("0");
}
 lcd.print(minutes);{
 /* lcd.print(":");

 //display seconds
 if(seconds < 10) {
 lcd.print("0");*/
}
 //  lcd.print(seconds);*/

 ///////////////////Display AM/PM//////////////////////////////////////
 /////////////////////////////////////////////////////////////////////
 if(hours < 12) {
 lcd.print("am");
} 
 else {
 lcd.print("pm");
}
 lcd.setCursor(7, 2);
 lcd.print(" ");
 lcd.print(tempF);
 lcd.print("F");
   
 lcd.setCursor(12, 3);
 /////////////////////Display month////////////////////////////////
 /////////////////////////////////////////////////////////////////
 if(month < 10){
 lcd.print("0");
}  
 lcd.print(month);
 lcd.print("/");
 if(dayOfMonth < 10) {
 lcd.print("0"); 
}
 lcd.print(dayOfMonth); 
 lcd.print("/"); 
 ////////////////////display year///////////////////////////////////////
 //////////////////////////////////////////////////////////////////////
  if(year < 10){
  lcd.print("0");
} 
  lcd.print(year); 

  delay(200);
}
 ///////////DS3231 RTC interface////////////////////////////////////
 //////////////////////////////////////////////////////////////////
void initChrono()
{
  set_time();
  set_date();
}

void set_date()
{
  Wire.beginTransmission(104);
  Wire.write(3);
  Wire.write(decToBcd(dayOfWeek));
  Wire.write(decToBcd(dayOfMonth));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));
  Wire.endTransmission();
}

void get_date()
{
  Wire.beginTransmission(104); 
  Wire.write(3);//set register to 3 (day)
  Wire.endTransmission();
  Wire.requestFrom(104, 4); //get 5 bytes(day,date,month,year,control);
  dayOfWeek   = bcdToDec(Wire.read());
  dayOfMonth  = bcdToDec(Wire.read());
  month = bcdToDec(Wire.read());
  year  = bcdToDec(Wire.read());
}

void zeroSeconds() {
  Wire.beginTransmission(104);
  Wire.write(0);
  Wire.write(decToBcd(seconds));
  Wire.endTransmission();
}

void set_time()
{
  Wire.beginTransmission(104);
  Wire.write(0);
  Wire.write(decToBcd(seconds));
  Wire.write(decToBcd(minutes));
  Wire.write(decToBcd(hours));
  Wire.endTransmission();
}

void get_time()
{
  Wire.beginTransmission(104); 
  Wire.write(0);//set register to 0
  Wire.endTransmission();
  Wire.requestFrom(104, 3);//get 3 bytes (seconds,minutes,hours);
  seconds = bcdToDec(Wire.read() & 0x7f);
  minutes = bcdToDec(Wire.read());
  hours = bcdToDec(Wire.read() & 0x3f);
}

///////////////////////////////////////////////////////////////////////

byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}

byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}

No reply's? Looks like someone can tell me to figure it out on my own but when I retort, you all get butt hurt. Nothing like a board with a pos fan base. Well, skaru you all then, I will do it on my own. Feel free to take your self righteous god complex and stick it!

No you were not or you would have a while back.

No butt hurt here. Not like I have been helped or spoken to, so, no loss, ehy? Easy enough to figure on my own, its just time I was hoping to shorten. Thanks anyways.

skaru= as on south park when Eric Carlton says screw you. he says it in a ska ru yu fashion.

Carry on you ignoring..........

What kind of countdown you are thinking about? Only minutes? Minutes and seconds? Or you don't care about it?

1ArduinoFan:
skaru= as on south park when Eric Carlton says screw you. he says it in a ska ru yu fashion.

How to use this forum

Be polite

Not everyone can rebuild an automatic transmission. They may, if they are lucky, able to change the oil and maybe adjust a band it thats an option, but, to pull all the bolts out to remove it, pull the front pump ass and replace the clutch plates and seals?

Strange analogy.

I've never owned a vehicle with automatic transmission, so my opportunities to dismantle, let alone rebuild, one have been severely restricted (my choice).
However, I am aware of the existence of professionals who will, for a financial consideration, perform the required operations for me.
There are also others who will, if I show willing and/or another financial consideration, teach me how to perform the required operations for myself.

(My silence on this thread so far has been due to ignorance of the existence of the thread, until it was reported)

And how do you know how much I have tried? I have spent every waking hour + for 4 weeks trying to figure this out. I have ignored my health, ignored my pets and my loved ones and havnt been doing a lot of work at work to get this project finished. Then, someone telsl me to drink a beer and figure it out? What kind of people are on this board with their holier than thou attitude if this is a board to help people, for free, not financial consideration? If they are gonna be jerks, they need to stay off the board, especially if they can not handle the backlash they get from rude comments they make/start.

try this:

  • move the update of the LCD screen to a function.
    create another function that displays your countdown timer
    create a state machine that changes states on a button press
    Put the time display function into STATE == 0
    Put the countdown timer into STATE = 1

when the timer expires, have it call an end of timer function and return to STATE == 0

that should work.

If you are more call try to answer my previous questions:

luisilva:
What kind of countdown you are thinking about? Only minutes? Minutes and seconds? Or you don't care about it?

1ArduinoFan:
What kind of people are on this board with their holier than thou attitude if this is a board to help people, for free, not financial consideration?

I think you're missing a major key word there: help. People here are more than willing to help others. You didn't ask for help with the project you asked for someone to post code that does what you want, be it from an example or a sketch that they "whipped up" for you. Maybe that's your definition of help, but that's not the case around here. It looks like nobody has an example sketch that fits your needs. Since you're can't "write code", it looks like you're at an impasse.

1ArduinoFan:
What kind of people are on this board with their holier than thou attitude if this is a board to help people, for free, not financial consideration? If they are gonna be jerks, they need to stay off the board ...

I'm getting a bit tired of this. Your posts are mainly insults. Stick to technical issues or I will delete the entire thread.

This is a sub-forum for programming questions, not "how to program". I'm moving this to Project Guidance, and if I get any more of these insulting remarks, it will then move to the Trash.