module stopper(CLOCK_50, KEY, LEDR);
	input 			CLOCK_50;
	input	[1:0]	KEY;
	output	[9:0]	LEDR;
	
	reg [9:0] 	shift_reg;
	reg [20:0] 	counter;
	reg			go;
	wire 		reset_n, enable, toggle_go;

	/* Glue logic */
	assign reset_n = KEY[1];
	assign enable =& counter; 

	/* Control FSM */
	pulse_FSM FSM(.Clock(CLOCK_50), .Resetn(reset_n), .i_pulse(~KEY[0]),
				  .o_pulse(toggle_go));
	
	always @(posedge CLOCK_50 or negedge reset_n)
	begin
		if (~reset_n)
		begin
			go <= 1'b0;
			counter <= 21'd0;
			shift_reg <= 10'd1;
		end
		else
		begin
			counter <= counter + 1'b1;
			if (go & enable)
			begin
				shift_reg[9:1] <= shift_reg[8:0];
				shift_reg[0] <= shift_reg[9];
			end
			if (toggle_go)
				go <= ~go;
		end
	end
	
	/* Show output on red LEDs. */
	assign LEDR = shift_reg;
endmodule

