module second_digit #(parameter int unsigned CYCLES_PER_SECOND = 50000000) (
    input logic CLOCK_50,
    input logic [9:0] SW,
    output logic [6:0] HEX0
);
    logic [25:0] interval;
    logic [3:0] digit;
    logic [1:0] controls_meta;
    logic [1:0] controls;

    // SW8 resets the count. SW9 freezes the elapsed fraction of a second.
    always_ff @(posedge CLOCK_50) begin
        controls_meta <= SW[9:8];
        controls <= controls_meta;
        if (controls[0]) begin
            interval <= 0;
            digit <= 0;
        end else if (!controls[1]) begin
            // TODO: count CLOCK_50 edges, emit one tick and wrap 9 to 0.
            interval <= interval;
            digit <= digit;
        end
    end

    always_comb begin
        case (digit)
            4'd0: HEX0 = 7'h40;
            4'd1: HEX0 = 7'h79;
            4'd2: HEX0 = 7'h24;
            4'd3: HEX0 = 7'h30;
            4'd4: HEX0 = 7'h19;
            4'd5: HEX0 = 7'h12;
            4'd6: HEX0 = 7'h02;
            4'd7: HEX0 = 7'h78;
            4'd8: HEX0 = 7'h00;
            4'd9: HEX0 = 7'h10;
            default: HEX0 = 7'h7f;
        endcase
    end
endmodule
