help with a 'if button is pressed' problem

ok... i'm working on a binary clock project, and i'd like to increment my time when the user presses a momentary on button. Below is the code:

int minutes[] = {8, 9, 10, 11, 12, 13};
int hours[] = {5, 6, 7, 15, 14};
int hours_p;
int minutes_p;
int seconds_p;
int remainder;
int led_value;
int pot = 5;
int secondLed = 2;
int potPose;

int minutebutton = 2;
int hourbutton = 3;
int setbutton = 4;
int buzzer = 3;

void setup(){
Serial.begin(9600);
pinMode(minutes[0], OUTPUT);
pinMode(minutes[1], OUTPUT);
pinMode(minutes[2], OUTPUT);
pinMode(minutes[3], OUTPUT);
pinMode(minutes[4], OUTPUT);
pinMode(minutes[5], OUTPUT);

pinMode(hours[0], OUTPUT);
pinMode(hours[1], OUTPUT);
pinMode(hours[2], OUTPUT);
pinMode(hours[3], OUTPUT);
pinMode(hours[4], OUTPUT);
pinMode(hours[5], OUTPUT);

pinMode(secondLed, OUTPUT);

potPose = 0;

hours_p = 0;
minutes_p = 0;
seconds_p = 0;
}
void loop(){

//*****************************************************************************
//Binary math for hours then minutes
//*****************************************************************************
// Display hours:
remainder = hours_p;
for(int i = 0; i < 5; i++) // repeat four all five hour-LEDs
{
led_value = 16/round(pow(2,i)); // first LED = 16, second = 8, third = 4 etc.

if(remainder/led_value == 1){
digitalWrite(hours*, HIGH);}*

  • else{*
    _ digitalWrite(hours*, LOW);}_
    _
    // the remainder of the hours is saved for*_
    * // the next LED that is displaying a lower value*
    * remainder=remainder%led_value;
    _
    }_
    _
    // Display minutes:_
    remainder = minutes_p;
    _
    for(int i = 0; i < 6; i++) // repeat for all six minute-LEDs*_
    * {*
    * led_value = 32/round(pow(2,i)); // first 32, then 16, then 8 etc.*

* if(remainder/led_value == 1){
_ digitalWrite(minutes, HIGH);}
else{
digitalWrite(minutes, LOW);}*_

* // the remainder of the hours is saved for*
* // the next LED that is displaying a lower value*
* remainder=remainder%led_value;
_ }
//*****************************************************************************
//delay w/ hour and minute watch*

//
potPose = analogRead(pot);
delay(potPose);
seconds_p++;
* //Blink second light*
digitalWrite(secondLed, HIGH);
delay(10);
digitalWrite(secondLed, LOW);
//

* //check for 60 seconds, 60 minutes, 24 hours*
//
if (seconds_p == 60) {seconds_p = 0; minutes_p++;}
if (minutes_p == 60) {minutes_p = 0; hours_p++;}
if (hours_p == 24) {hours_p = 0;}
//

* //serial feedback*
//*****************************************************************************
Serial.println(potPose);
* Serial.println(seconds_p);
Serial.println(hours_p);
Serial.println(minutes_p);*

* Serial.println("");
}*

*ok. so theres the code. *
potPose = analogRead(pot);
delay(potPose);
seconds_p++;
is where i'm thinking some sort of fast loop that checks to see if a button is pushed, and to increment time accordingly. Use the pot still to maintain a 'true' second, as apparently the arduino is a bit unreliable that way.
problem is i'm at a loss as to how to formulate a worthy statement(s) that can allow me to set the time._

delay relies on millis(). You won't make your clock more accurate by using delay instead of millis.

Where's the code to read the button press?

theres the problem, there is none. i know the arduino can do interrupts, but i haven't a clue how, and furthermore, a clue how to do it efficently!

I wouldn't mind going to millis... can you reset the value? i know it 'crashes' after 50 days, aparently.

alternatively, i was thinking of a while loop that just 'scans' the pin for a value higher than 500, (pin is 0v unti lbutton pushed), and if it were, to increment the respective value.

Digital pins return 0 or 1. If you wait for a 500, you'll have a long wait. The loop function is called in an endless loop. If you check for a button press on each pass, and don't use delays, you'll be checking the pin state millions of times per second. Plenty fast to catch even the briefest button press.

You don't want to use a while loop to wait for a button press. Nothing would happen until the button WAS pressed.

The millis function doesn't crash after 49+ days. It simply rolls over to 0 again.

ok... i've gotten this far by reading examples and then interperting them and subsequently understanding them. however, i haven't seen an example of a digital input read yet. can you provide me with something that at least resembles what i'm looking for here? i hate to ask other people to look things up, but i don't even know what to search for.

const int buttonPin = 12;

void setup()
{
  pinMode(buttonPin, INPUT);
  digitalWrite(buttonPin, HIGH); // Turn on pull-up resistor
}

void loop()
{
   if(digitalRead(buttonPin) == LOW)
   {
      // Button is pressed
   }
   else
   {
      // Button is not pressed
   }
}

awesome...

now... i need to 'watch' for that pin changing state, should i do that in a loop that loops x amount of times (per second). my thought is if the code detects a button push, to increment the number, and reset the seconds. if this incrementation would increase the number past 60 or 24, to reset to zero, without advancing the next time scale (minutes to hours, etc).

i need to 'watch' for that pin changing state, should i do that in a loop

Not just a loop. The loop.

The loop function is called in an endless loop, millions (potentially) of times per second.

If you want to increment (or decrement) time WHILE the button is pressed, rather than IF the button is pressed, that's a whole different story.

ok... so whats a good way to interface with the millis() value. i assume there's not a way to reset it? thats what i would WANT to do every time the minute increments, that way i can just start the count up over each time a button is pushed or the clock resolves 60 seconds.

There is a way to reset it, but I don't use it, so I can't help you there. But, does your watch reset? Does your clock? You want to do things when the value returned by millis changes by a certain amount. It isn't necessary to reset to 0 to know when the required amount of time has elapsed.