Setting DS1302 with buttons

Hi there,

I'm getting stuck at my second Arduino project. I've been searching these forums and internet for a few days now, but haven't found an easy solution for this:
I've got an Arduino Uno, 16x2 LCD display, TMP36 sensor, and DS1302 RTC. At this moment the LCD shows Time and Temp on the forst row, and day and date at the second row. I Am searching for a way to adjust only the time with a few buttons. That could be increase and decrease minutes, or increase minutes and hours. At this moment this is the code I hacked together:
(By the way, working with the "estimates" for the TMP36 gives a fairly stable result. :slight_smile: :slight_smile: )

// DS1302_LCD (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// A quick demo of how to use my DS1302-library to make a quick
// clock using a DS1302 and a 16x2 LCD.
//
// I assume you know how to connect the DS1302 and LCD.
// DS1302:  CE pin    -> Arduino Digital 2
//          I/O pin   -> Arduino Digital 3
//          SCLK pin  -> Arduino Digital 4
// LCD:     DB7       -> Arduino Digital 6
//          DB6       -> Arduino Digital 7
//          DB5       -> Arduino Digital 8
//          DB4       -> Arduino Digital 9
//          E         -> Arduino Digital 10
//          RS        -> Arduino Digital 11

#include <LiquidCrystal.h>
#include <DS1302.h>

// Init the DS1302
DS1302 rtc(6, 5, 4);

// Init the LCD
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

float lastEstimate = 0;      // previous result

void setup()
{
  // Set the clock to run-mode, and disable the write protection
  rtc.halt(false);
  rtc.writeProtect(false);
  
  // Setup LCD to 16x2 characters
  lcd.begin(16, 2);

  // The following lines can be commented out to use the values already stored in the DS1302
 // rtc.setDOW(FRIDAY);        // Set Day-of-Week to FRIDAY
 //rtc.setTime(15, 22, 0);     // Set the time to 12:00:00 (24hr format)
 // rtc.setDate(6, 8, 2010);   // Set the date to August 6th, 2010

  // use pins A0 and A2 to power the TMP36 sensor:
   pinMode(A0, OUTPUT);
  pinMode(A2, OUTPUT);
  // set A0 low, and A2 high:
  digitalWrite(A0, LOW);
  digitalWrite(A2, HIGH);

}


void loop()
{
  // Display time centered on the upper line
  lcd.setCursor(0, 0);
  lcd.print(rtc.getTimeStr());
  
  // Display abbreviated Day-of-Week in the lower left corner
  lcd.setCursor(0, 1);
  lcd.print(rtc.getDOWStr(FORMAT_SHORT));
  
  // Display date in the lower right corner
  lcd.setCursor(6, 1);
  lcd.print(rtc.getDateStr());
  
// read the sensor:
  int sensorVal = analogRead(A1);
  // convert to voltage:
  float voltage = 5.0 * sensorVal / 1024.0;
  // convert to degrees celsius:
  float temperature = (voltage - 0.5) * 100;
  // read the trim pot:
  float trimPotValue = analogRead(A3)/1023.0;
  
  // filter the sensor's result:
  float currentEstimate = filter(temperature, trimPotValue, lastEstimate);
  // print the result:
  lcd.print("               C");
  lcd.setCursor(11, 0);
  lcd.print(currentEstimate);
  // save the current result for future use:
  lastEstimate = currentEstimate;
  delay (1000);
}


// filter the current result using a weighted average filter:
float filter(float rawValue, float weight, float lastValue) {
  // run the filter:
  float result = weight * rawValue + (1.0-weight)*lastValue;
  // return the result:
  return result;


  // Wait one second before repeating :)
  delay (1000);
}