I don't understand why this won't work???

im trying to look at an input on pin 3 and if its HIGH then hour++

Its for a binary clock. I didn't show the render code because it works and it just adds clutter. Also i know its not neat, Im just testing. and im new :slight_smile:

int second=0, minute=0, hour=1; 
int mUnit = 0;
int hUnit = 0;
int sUnit = 0;
int TempReading;
int TempSensorPin = 0;
int TempSwitch = 1;
int HourUp = 3;
int MinuteUp = 2;
int FinalTemp10;
int Display = 1;
int FinalTemp;
int Column,Row;

int TimeSwitchVal = 0;

int Column6 = 13;
int Column5 = 12;
int Column4 = 11;
int Column3 = 10;
int Column2 = 9;
int Column1 = 8;

int Row1 = 7;
int Row2 = 6;
int Row4 = 5;
int Row8 = 4;

void setup() {
  Serial.begin(9600);
  pinMode(Column6, OUTPUT);
  pinMode(Column5, OUTPUT);
  pinMode(Column4, OUTPUT);
  pinMode(Column3, OUTPUT);
  pinMode(Column2, OUTPUT);
  pinMode(Column1, OUTPUT);

  pinMode(Row1, OUTPUT);
  pinMode(Row2, OUTPUT);
  pinMode(Row4, OUTPUT);
  pinMode(Row8, OUTPUT);
  pinMode(HourUp, INPUT); 
  pinMode(2, INPUT);
  pinMode(1, INPUT);
  pinMode(0, INPUT);
}

void loop() {
  tick();
  RenderTime();
 /* 
  if(Display == 1){
    RenderTime();
  }
  if(Display == 2){
    RenderTemp();
  }
  */
}

void Reset(){
  delayMicroseconds(200);
  digitalWrite(Column6, HIGH);
  digitalWrite(Column5, HIGH);
  digitalWrite(Column4, HIGH);
  digitalWrite(Column3, HIGH);
  digitalWrite(Column2, HIGH);
  digitalWrite(Column1, HIGH);

  digitalWrite(Row1, LOW);
  digitalWrite(Row2, LOW);
  digitalWrite(Row4, LOW);
  digitalWrite(Row8, LOW);
}
void CheckTempButtons() {
  //TempSwitchVal = digitalRead(TempSwitch);
 // if(digitalRead(TempSwitchVal) == HIGH)
  {
  //  Display = 2;
  }
//  else
  {
  //  Display = 1;
  }
}

void CheckTimeButtons() {
  TimeSwitchVal = digitalRead(HourUp);
  if(TimeSwitchVal == HIGH)
  {
    hour++;
  }
  else{
    hour++;
  }
}

void print(){
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);
  Serial.print(FinalTemp); 
  Serial.print(" degrees C");
  
  Serial.println(TimeSwitchVal);
}

void tick(){
  static unsigned long lastTick = 0;
  if (millis() - lastTick >= 1000) {
    lastTick = millis();
    second++;
    print();
    CalcTemp();
    CheckTempButtons();
  }
  sUnit = second%10;
  mUnit = minute%10; 
  hUnit = hour%10;

  if (second >= 60) {
    minute++;
    second = 0;
  }

  if (minute >= 60) {
    hour++;
    minute = 0;
  }
  if (hour >= 24) {
    hour=1;
  }
}
void CalcTemp(){
  TempReading = analogRead(TempSensorPin);
  float voltage = TempReading * 5.0;
  voltage /= 1024.0;
  float TempC = (voltage - 0.5) * 100;
  FinalTemp = (int) TempC;
  FinalTemp10 = FinalTemp % 10;
}

you dont call CheckTimeButtons() in the main loop that I can see

You also need to debounce your buttons, check in the playground for details.

Mark

Wouldn't having the arduino check the buttons once a second already be debounceing unless you reaction time is worse then one second?????

Not really but it will basically be relying on luck to detect a button press. It will only detect a button press if, coincidentally, the user presses the button at the same moment the Arduino checks it. At the very least the user will generally have to hold the button for at least one second to ensure a reading.

Read it every loop and debounce it. This will read it fast and often enough that it will seem like it is always checking the button.