Trouble with code that works on Uno but not on Micro

Hi Everyone,
Relative newbie here with a problem I have not been able to find an answer for. The code below for an analog meter clock works perfectly using an Uno but returns incorrect time values to the serial window when running on a Micro. When on the Uno, I see time values of 12:24:15, 12:24:16, 12:24:17, etc which are correct. When running on the Micro, I see time values in the serial window of 12:24:0, 12:25:0, 12:26:0, etc. The RTC is a DS3231 ChronoDot. Does anyone have any suggestions? The code is below.

Thanks,
Jeff

/*
 Analog Volt Meter Clock
  
 Credits:
  Instructables Link: http://www.instructables.com/id/Analog-VU-meter-and-Clock-Arduino-Powered/ 
  Original Author:  Adam Welch http://admw.uk/ib
 _______________________________________________________________________________________________
 Wiring for Arduino Uno is as follows:
 
 - Positive power to RAW
 - Negative power to GND
 
 - Buttons - Up to Digital 2 
           - Down to Digital 3
 
 - DS3231 RTC  - SDA to Analog 4
               - SCL to Analog 5
               - VCC to 5V
               - GND to Ground
 
 - On-Board LED Digital 13
 - Hour Analog Meter to Digital 11 (PWM)
 - Minute Analog Meter to Digital 10 (PWM)
 - Second Analog Meter to Digital 9 (PWM)
_________________________________________________________________________________________________
_________________________________________________________________________________________________
 Wiring for Arduino Micro is as follows:
 
 - Positive power to VIN
 - Negative power to GND
 
 - Buttons - Up to Digital 7 
           - Down to Digital 8
 
 - DS3231 RTC  - SDA to Digital 2
               - SCL to Digital 3
               - VCC to 5V
               - GND to Ground
 
 - On-Board LED Digital 13
 - Hour Analog Meter to Digital 11 (PWM)
 - Minute Analog Meter to Digital 10 (PWM)
 - Second Analog Meter to Digital 9 (PWM)
_________________________________________________________________________________________________
    
  NOTE:  Because all meters are slightly different, the PWM values 
  need to be adjusted based on your design. Feel free to use 
  this code, but you will have to change some values because 
  it is set to work specifically with my meters.
   
  Check the PWM correction values in hrPWM() !!
 */
 
#include "Wire.h"
#define DS3231_ADDRESS 0x68 //104
byte zero = 0x00; //workaround for issue #527
 
int upButton = 7;      // up push button to adjust time (pin 7)
int downButton = 8;    // down push button to adjust time (pin 8)
 
int hours = 0;
int minutes = 0;
int seconds = 0;
int lastMinute = 0;
 
 
int LEDPin = 13;       // On-board LED pin 13
int hourMeter = 11;    // Hour meter is attached to pin 11
int minMeter = 10;     // Minute meter is attached to pin 10
int secMeter = 9;      // Second meter is attached to pin 9
 
void setup(){
  Wire.begin();
  Serial.begin(9600);   //View time in serial monitor

  //If you need to set the DS3231RTC to the correct time, uncomment the setDateTime(); line and configure 
  //the setDateTime loop at the bottom of this sketch. Remember to comment out this line again afterwards!
   
  //setDateTime(); 
   
  // Initialize Outputs
  
  pinMode(hourMeter, OUTPUT);
  pinMode(minMeter, OUTPUT);
  pinMode(secMeter, OUTPUT);
  pinMode(LEDPin, OUTPUT);
   
  // Test meters on startup
  
  digitalWrite(hourMeter, HIGH);
  digitalWrite(minMeter, HIGH);
  digitalWrite(secMeter, HIGH);
  digitalWrite(LEDPin, HIGH);
  delay (5000);
  digitalWrite(hourMeter, LOW);
  digitalWrite(minMeter, LOW);
  digitalWrite(secMeter, LOW);
  digitalWrite(LEDPin, LOW);
  delay(5000);
}
 
void loop(){
  printDate();
  delay(1000);
  
 //Setting the time with buttons
 
  if (digitalRead(downButton) == HIGH){ 
    byte second = 0;
    byte minute = minutes; // Don't get confused: minute is not the same as minutes
    byte hour = hours;     // Don't get confused: hour is not the same as hours
    if (minutes > 0){ 
      --minute; 
    }
    else{
      minute = 59;
    if (hours > 0){ 
      -- hour;
    }
    else{
      hour = 23;
    }
  }
  Wire.beginTransmission(DS3231_ADDRESS);
  Wire.write(zero); //stop Oscillator
   
  Wire.write(decToBcd(second));
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));
  
  Wire.write(zero); //start 
   
  Wire.endTransmission();
  }
  
  if (digitalRead(upButton) == HIGH){ 
    byte second = 0; 
    byte minute = minutes; // Don't get confused: minute is not the same as minutes
    byte hour = hours;     // Don't get confused: hour is not the same as hours
    if (minutes < 59){ 
      ++minute; 
    }
    else{
      minute = 0;
    if (hours < 23){ 
      ++ hour;
    }
    else{
      hour = 0;
    }
  }
  Wire.beginTransmission(DS3231_ADDRESS);
  Wire.write(zero); //stop Oscillator
   
  Wire.write(decToBcd(second));
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));
  
  Wire.write(zero); //start 
   
  Wire.endTransmission();
  }

}

// Convert decimal number to binary number
  byte decToBcd(byte val){
  return ( (val/10*16) + (val%10) );
}
 
// Convert binary number to decimal number
  byte bcdToDec(byte val)  {
  return ( (val/16*10) + (val%16) );
}
 
void printDate(){
 
  // Reset the register pointer
  Wire.beginTransmission(DS3231_ADDRESS);
  Wire.write(zero);
  Wire.endTransmission();
 
  Wire.requestFrom(DS3231_ADDRESS, 7);
   
  seconds = bcdToDec(Wire.read());
  minutes = bcdToDec(Wire.read());
  hours = bcdToDec(Wire.read() & 0b111111); //24 hour time
 
  //print the date
  Serial.print(hours);     // Un-comment to view time in serial monitor  
  Serial.print(":");       //
  Serial.print(minutes); // Don't forget to un-comment 'Serial.begin' in 'void setup' above
  Serial.print(":");       //
  Serial.println(seconds); // 
 
  hrPWM();  //Call the hrPWM loop to display correct hours
  minPWM(); //Call the minPWM loop to display correct minutes
  secPWM(); //Call the secPWM loop to display correct seconds
  
}
 
void hrPWM()
{
      /* Specific meter levels for each hour 
         You will likely have to adjust these values.
         Play around with the values until you get what you want
         or you could attach a potentiometer to a spare input and 
         adjust the levels and read them over a serial connection.
      */ 
   
      if (hours == 0){
     analogWrite(hourMeter, 0); // adjust hour meter level
      }
      if (hours == 1 || hours == 13){
     analogWrite(hourMeter, 23); // adjust hour meter level
      }
      if (hours == 2 || hours == 14){
     analogWrite(hourMeter, 46); // adjust hour meter level
      }
       if (hours == 3 || hours == 15){
     analogWrite(hourMeter, 70); // adjust hour meter level
      }
      if (hours == 4 || hours == 16){
     analogWrite(hourMeter, 92); // adjust hour meter level
      }
       if (hours == 5 || hours == 17){
     analogWrite(hourMeter, 113); // adjust hour meter level
      }
      if (hours == 6 || hours == 18){
     analogWrite(hourMeter, 134); // adjust hour meter level
      }
      if (hours == 7 || hours == 19){
     analogWrite(hourMeter, 154); // adjust hour meter level
      }
      if (hours == 8 || hours == 20){
     analogWrite(hourMeter, 174); // adjust hour meter level
      }
       if (hours == 9 || hours == 21){
     analogWrite(hourMeter, 192); // adjust hour meter level
      }
      if (hours == 10 || hours == 22){
     analogWrite(hourMeter, 210); // adjust hour meter level
      }
       if (hours == 11 || hours == 23){
     analogWrite(hourMeter, 230); // adjust hour meter level
      }
       if (hours == 12){
     analogWrite(hourMeter, 250); // adjust hour meter level
      }
}
 
void minPWM()
{
  analogWrite(minMeter, minutes * 4.25);   // 255 divided by 60 is 4.25
}
 
void secPWM()
{
  analogWrite(secMeter, seconds * 4.25);   // 255 divided by 60 is 4.25 
}
 
void setDateTime(){
 
  byte second =      0; //0-59
  byte minute =      39; //0-59
  byte hour =        19; //0-23
  byte weekDay =     3; //1-7
  byte monthDay =    13; //1-31
  byte month =       1; //1-12
  byte year  =       16; //0-99
 
  Wire.beginTransmission(DS3231_ADDRESS);
  Wire.write(zero); //stop Oscillator
 
  Wire.write(decToBcd(second));
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));
  Wire.write(decToBcd(weekDay));
  Wire.write(decToBcd(monthDay));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));
 
  Wire.write(zero); //start 
 
  Wire.endTransmission();
 
}

The SDA and SCL pins on the Micro do not correspond to A4 and A5.

Hi John,
Thanks for the reply. Yes, on the Micro the SDA and SCL are on D2 and D3. I have that noted in the code comments. I do have those hooked up correctly, just not getting the right information back.

Thanks,
Jeff

Looks like your 'up' button is stuck HIGH. How is it wired? Did you put in a pull-down resistor?

Hi John,
You got me pointed in the right direction! I found the problem. I had a faulty pull-down resistor on the up button. It was not taking the pin completely to ground so it was actually floating causing the code to think the button was pushed. I changed the code to make the button input to active low and added new pull-up resistors and it took right off!

Thanks much!
Jeff