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._