const unsigned char SSD_LUT[] = {
  0b00111111, // 0
  0b00000110, // 1
  0b01011011, // 2
  0b01001111, // 3
  0b01100110, // 4
  0b01101101, // 5
  0b01111101, // 6
  0b00000111, // 7
  0b01111111, // 8
  0b01101111, // 9
  // DECIMAL FORMAT, SO THESE ARE NOT NECESSARY!
  // 0b01110111, // A
  // 0b01111100, // b
  // 0b00111001, // C
  // 0b01011110, // d
  // 0b01111001, // E
  // 0b01110001  // F
};
// As per the lab documentation for the PmodSSD
const int DELAY_IN_MILLISECONDS = 8;
// The first (tens) digit
const byte TENS_DIGIT_PIN = 39;
// The second (unit) digit
const byte UNIT_DIGIT_PIN = 37;
byte count = 0; // Where to start counting from
int startTime, endTime;
void setup() {
  // setting port A as output
  DDRA = 0b11111111;
  pinMode(37, OUTPUT);
  pinMode(39, OUTPUT);
}
void loop() {
  displayNumber(count);
  // "Manually" increment the number every second
  endTime = millis();
  if ((endTime - startTime) >= 1000) {
    if (count > 99) {
      count = 0;
    } else {
      count++;
    }
    startTime = endTime;
  }
}
void enableDigits(const uint8_t tens, const uint8_t unit) {
  digitalWrite(TENS_DIGIT_PIN, tens);
  digitalWrite(UNIT_DIGIT_PIN, unit);
}
void displayNumber(const byte NUMBER_TO_DISPLAY) {
  // Tens digit + remainder
  // "cz" in the lab documentation
  const byte DIGIT_TENS = NUMBER_TO_DISPLAY / 10;
  // "cu" in the lab documentation
  const byte DIGIT_UNITS = NUMBER_TO_DISPLAY % 10;
  
  PORTA = SSD_LUT[DIGIT_UNITS];
  // Turn off first (tens) digit
  enableDigits(HIGH, LOW);
  delay(DELAY_IN_MILLISECONDS);
  // TURN OFF BOTH DIGITS
  enableDigits(HIGH, HIGH);
  // Only display first digit if greater than zero
  if (DIGIT_TENS > 0) {
    PORTA = SSD_LUT[DIGIT_TENS];
    // Turn off second (unit) digit
    enableDigits(LOW, HIGH);
    
    delay(DELAY_IN_MILLISECONDS);    
    // TURN OFF BOTH DIGITS
    enableDigits(HIGH, HIGH);
  }
}