data/full_repos/permissive/186615556/Main.v
 line:36: before: "integer"
1: b"%Error: data/full_repos/permissive/186615556/Main.v:364: Too many digits for 9 bit number: 9'b1111100111\n      if(MODULE_COUNTER == 9'b1111100111)\n                           ^~~~~~~~~~~~~\n%Error: Exiting due to 1 error(s)\n"
module Main(CLOCK_50, KEY, Data_in, Data_out);


input 		CLOCK_50;
input [1:0] KEY;

output reg Data_out;
input Data_in;


reg [LED_ADDRESS_WIDTH-1:0] 	address;


wire				hard_reset;
wire           reset_almost_done;
wire           led_almost_done;

wire 				data_request;
wire 				new_address;

wire [23:0]		Color_Data_Insert;


function integer log2;
input integer value;
begin
	value = value - 1;
	for (log2 = 0; value > 0; log2 = log2 + 1)
	 value = value >> 1;
end
endfunction













parameter 				AMOUNT_LEDS		= 36;
parameter 				SYSTEM_CLOCK	= 50_000_000;



localparam integer CYCLE_COUNT         = SYSTEM_CLOCK / 800000;
localparam integer RESET_COUNT         = 320 * CYCLE_COUNT;

localparam integer TH0_CYCLE_COUNT     = 0.32 * CYCLE_COUNT;
localparam integer TH1_CYCLE_COUNT     = 0.64 * CYCLE_COUNT;


localparam integer RESET_COUNTER_WIDTH = log2(RESET_COUNT);
localparam integer CLOCK_DIV_WIDTH     = log2(CYCLE_COUNT);
localparam integer LED_ADDRESS_WIDTH	= log2(AMOUNT_LEDS);

reg [CLOCK_DIV_WIDTH - 1:0]             clock_div;
reg [RESET_COUNTER_WIDTH - 1:0]         reset_counter;
reg [LED_ADDRESS_WIDTH - 1 :0]			 NEXT_LED;


reg [3:0] state;

localparam STATE_RESET    = 4'b0000;
localparam STATE_STATIC   = 4'b0001;
localparam STATE_PRE      = 4'b0010;
localparam STATE_TRANSMIT = 4'b0011;
localparam STATE_POST     = 4'b0100;
localparam STATE_RESTART  = 4'b0101;
localparam STATE_TIMER	  = 4'b0110;
localparam STATE_GRADIENT = 4'b0111;
localparam STATE_PICTURE  = 4'b1000;
localparam STATE_LINE	  = 4'b1001;
localparam STATE_FLOW	  = 4'b1010;


reg [1:0]	color;

localparam COLOR_G     = 2'b00;
localparam COLOR_R     = 2'b01;
localparam COLOR_B     = 2'b10;

reg [7:0]   green;						  
reg [7:0]   red;
reg [7:0]   blue;

reg [7:0]   current_byte;
reg [2:0]   current_bit;


wire [2:0]	MODE;

localparam STATIC    = 3'b000;
localparam GRADIENT  = 3'b001;
localparam PICTURE   = 3'b010;
localparam LINE		= 3'b011;
localparam FLOW		= 3'b100;



reg [23:0] 								Color_Data;
reg [5:0]								MODULE_COUNTER;
reg [LED_ADDRESS_WIDTH - 1 :0]	TOTAL_LEDS;
reg [21 :0] 							TIMER;
reg [1:0]								REVERSE_LED;
reg [1:0]								REVERSE_MODULE;
reg [1:0]								DIM_LED;
reg [1:0]								HALL_SWITCHED;
reg [3:0]								HALL_TIMER;


assign reset = !KEY[0];

assign reset_almost_done = (state == STATE_RESET) && (reset_counter == RESET_COUNT-1);
assign led_almost_done   = (state == STATE_POST)  && (color == COLOR_B) && (current_bit == 0) && (address != 0);

assign data_request = reset_almost_done || led_almost_done;
assign new_address  = (state == STATE_PRE) && (current_bit == 7);

assign MODE = PICTURE;


ROM1 rom(MODULE_COUNTER, CLOCK_50, Color_Data_Insert);

always @(posedge CLOCK_50)
begin
 if (reset) 
	begin

		state <= STATE_RESET;
		color <= COLOR_G;
		
		HALL_SWITCHED <= 0;
		TOTAL_LEDS <= 0;
		REVERSE_LED <= 0;
		REVERSE_MODULE <= 0;
		DIM_LED <= 0;
		NEXT_LED <= 0;
		Data_out <= 0;
		HALL_TIMER <= 0;
		
		address <= 0;
		reset_counter <= 0;
		current_bit <= 7;
		MODULE_COUNTER <= 0;
	 end 
 else 
	begin

		case (state)
			STATE_TIMER:
				begin
					if(TIMER == {20{1'b1}})
						begin
							state <= STATE_RESTART;
						end	
					else
						begin
							TIMER <= TIMER + 1;
						end	
				end
			STATE_RESTART:
				begin
						TIMER <= 0;
						state <= STATE_RESET;
						color <= COLOR_G;
						
						Data_out <= 0;
						address <= 0;
						reset_counter <= 0;
						current_bit <= 7;

						NEXT_LED <= 0;			
				end
			STATE_RESET:
				begin
					Data_out <= 0;
					if (reset_counter == RESET_COUNT - 1)
						begin
							reset_counter <= 0;
							
							case(MODE)
								STATIC:
									begin
										state <= STATE_STATIC;
									end
								GRADIENT:
									begin
										state <= STATE_GRADIENT;
									end
								PICTURE:
									begin
										state <= STATE_PICTURE;
									end
								LINE:
									begin
										state <= STATE_LINE;
									end
								FLOW:
									begin
										state <= STATE_FLOW;
									end	
							endcase		
						  end
					  else 
						  begin
							  reset_counter <= reset_counter + 1;
						  end
				end
			STATE_GRADIENT:
				begin
					if(NEXT_LED != TOTAL_LEDS)
						begin
							state <= STATE_PRE;
							color <= COLOR_G;
							
							red <= Color_Data[7:0];
							green <= Color_Data[15:8];
							blue <= Color_Data[23:16];
							
							NEXT_LED	<= NEXT_LED + 1;

							address <= address + 1;

							current_byte <= green;
							current_bit <= 7;
						end
					else
						begin
							if(REVERSE_LED == 0)
								begin
									if(TOTAL_LEDS == AMOUNT_LEDS)
										begin
											REVERSE_LED <= 1;
											DIM_LED <= 1;
										end
									else
										begin
											TOTAL_LEDS <= TOTAL_LEDS + 1;
											state <= STATE_TIMER;
										end
								end
							if(REVERSE_LED == 1)	
								begin	
									if(TOTAL_LEDS == 0 && MODULE_COUNTER == 6'b100101)
										begin
											REVERSE_MODULE <= 1;
											Color_Data <= Color_Data_Insert;
										end
									if(TOTAL_LEDS == 0 && MODULE_COUNTER == 0)
										begin
											REVERSE_MODULE <= 0;
											Color_Data <= Color_Data_Insert;
										end	
										
									if(TOTAL_LEDS == 0 && MODULE_COUNTER != 6'b100101 && REVERSE_MODULE == 0)
										begin
											MODULE_COUNTER <= MODULE_COUNTER + 1;
											Color_Data <= Color_Data_Insert;
										end
									if(TOTAL_LEDS == 0 && MODULE_COUNTER != 0 && REVERSE_MODULE == 1)
										begin
											MODULE_COUNTER <= MODULE_COUNTER - 1;
											Color_Data <= Color_Data_Insert;
										end
										
									if(TOTAL_LEDS == 0 && MODULE_COUNTER == 6'b100101)
										begin
											MODULE_COUNTER <= MODULE_COUNTER - 1;
										end
									if(TOTAL_LEDS == 0 && MODULE_COUNTER == 0)
										begin
											MODULE_COUNTER <= MODULE_COUNTER + 1;
										end	

									if(TOTAL_LEDS == 0)
										begin
											TOTAL_LEDS <= TOTAL_LEDS + 1;
											REVERSE_LED <= 0;
										end
										
									if(TOTAL_LEDS != 0)
										begin
											if(DIM_LED == 1)
												begin
													state <= STATE_TIMER;
													Color_Data <= 24'b000000000000000000000000;
													DIM_LED <= 0;
												end
											else
												begin
													state <= STATE_RESTART;
													Color_Data <= Color_Data_Insert;
													DIM_LED <= 1;
													TOTAL_LEDS  <= TOTAL_LEDS - 1;
												end
										end
								end
						end
				end
			STATE_STATIC:
				begin
					TOTAL_LEDS <= AMOUNT_LEDS;
					Color_Data	<= 24'b000000001111111100000000;
					
					if(NEXT_LED != TOTAL_LEDS)
						begin
							state <= STATE_PRE;
							color <= COLOR_G;
							
							red <= Color_Data[7:0];
							green <= Color_Data[15:8];
							blue <= Color_Data[23:16];
							
							NEXT_LED	<= NEXT_LED + 1;

							address <= address + 1;

							current_byte <= green;
							current_bit <= 7;
						end
				end
			STATE_PICTURE:
				begin
					TOTAL_LEDS <= AMOUNT_LEDS;
			
					if(Data_in == 1 && HALL_SWITCHED == 0)
					begin
						if(NEXT_LED != TOTAL_LEDS)
							begin
								state <= STATE_PRE;
								color <= COLOR_G;
								
								MODULE_COUNTER <= MODULE_COUNTER + 1;
								Color_Data <= Color_Data_Insert;
								
								red <= Color_Data[7:0];
								green <= Color_Data[15:8];
								blue <= Color_Data[23:16];
								
								NEXT_LED	<= NEXT_LED + 1;

								address <= address + 1;

								current_byte <= green;
								current_bit <= 7;
							end
							
						if(MODULE_COUNTER == 9'b1111100111)
						begin
							MODULE_COUNTER <= 0;
							Color_Data	<= Color_Data_Insert;
						end	
					end
					
					if(Data_in == 0 && HALL_SWITCHED == 1)
					begin
						if(NEXT_LED != TOTAL_LEDS)
							begin
								state <= STATE_PRE;
								color <= COLOR_G;
								
								Color_Data <= 24'b000000000000000000000000;
								
								red <= Color_Data[7:0];
								green <= Color_Data[15:8];
								blue <= Color_Data[23:16];
								
								NEXT_LED	<= NEXT_LED + 1;

								address <= address + 1;

								current_byte <= green;
								current_bit <= 7;
							end
						else
							begin
								state <= STATE_RESTART;
								HALL_SWITCHED <= 0;
							end	
					end
					
					if(Data_in == 0)
					begin
						HALL_SWITCHED <= 1;
					end
					
					if(Data_in == 1)
					begin
						HALL_SWITCHED <= 0;
					end
				end
			STATE_FLOW:
				begin	
					
					if(NEXT_LED == 0 && Data_in == 1 && HALL_SWITCHED == 0)
						begin
							HALL_SWITCHED <= 1;
							if(MODULE_COUNTER == 6'b100101)
								begin
									REVERSE_MODULE <= 1;
									MODULE_COUNTER <= MODULE_COUNTER - 1;
								end
							if(MODULE_COUNTER == 0)
								begin
									REVERSE_MODULE <= 0;
									MODULE_COUNTER <= MODULE_COUNTER + 1;
								end
							if(MODULE_COUNTER != 6'b100101 && REVERSE_MODULE == 0)
								begin
									MODULE_COUNTER <= MODULE_COUNTER + 1;
								end
							if(MODULE_COUNTER != 0 && REVERSE_MODULE == 1)
								begin
									MODULE_COUNTER <= MODULE_COUNTER - 1;
								end
						end
						
					if(Data_in == 0 && NEXT_LED == AMOUNT_LEDS)
						begin
							HALL_SWITCHED <= 0;
						end	
						
					TOTAL_LEDS <= AMOUNT_LEDS;	
					Color_Data	<= Color_Data_Insert;
					
					if(NEXT_LED != TOTAL_LEDS)
						begin
							state <= STATE_PRE;
							color <= COLOR_G;
							
							red <= Color_Data[7:0];
							green <= Color_Data[15:8];
							blue <= Color_Data[23:16];
							
							NEXT_LED	<= NEXT_LED + 1;

							address <= address + 1;

							current_byte <= green;
							current_bit <= 7;
						end
					else
						begin
							state <= STATE_RESTART;
						end	
				end
			STATE_LINE:
				begin
					TOTAL_LEDS <= AMOUNT_LEDS;
					
					if(NEXT_LED != TOTAL_LEDS)
						begin
							Color_Data <= 24'b000000000000000011111111;
							
							if(NEXT_LED >= 10 && NEXT_LED <= 23)
								begin
									Color_Data <= 24'b111111110000000000000000;
								end
							
							state <= STATE_PRE;
							color <= COLOR_G;
							
							red <= Color_Data[7:0];
							green <= Color_Data[15:8];
							blue <= Color_Data[23:16];
									
							NEXT_LED	<= NEXT_LED + 1;

							address <= address + 1;

							current_byte <= green;
							current_bit <= 7;
						end
				end
			STATE_PRE:
				begin
					state <= STATE_TRANSMIT;
					clock_div <= 0;
					Data_out <= 1;
				end
			STATE_TRANSMIT:
				begin
              if (current_byte[7] == 0 && clock_div >= TH0_CYCLE_COUNT) 
					begin
                 Data_out <= 0;
					end
              else if (current_byte[7] == 1 && clock_div >= TH1_CYCLE_COUNT) 
					begin
                 Data_out <= 0;
					end

              if (clock_div == CYCLE_COUNT-1)
					begin
						  state <= STATE_POST;
					end
              else 
					begin
						  clock_div <= clock_div + 1;
					end
				end
			STATE_POST: 
				begin
					if (current_bit != 0) 
						begin
						  current_byte <= {current_byte[6:0], 1'b0};
						  case (current_bit)
							  7: current_bit <= 6;
							  6: current_bit <= 5;
							  5: current_bit <= 4;
							  4: current_bit <= 3;
							  3: current_bit <= 2;
							  2: current_bit <= 1;
							  1: current_bit <= 0;
						  endcase
						  state <= STATE_PRE;
						end
					else 
						begin
						  case (color)
							  COLOR_G: 
								begin
								  state <= STATE_PRE;
								  color <= COLOR_R;
								  current_byte <= red;
								  current_bit <= 7;
								end
							  COLOR_R: 
								begin
								 state <= STATE_PRE;
								 color <= COLOR_B;
								 current_byte <= blue;
								 current_bit <= 7;
								end
							  COLOR_B: 
								begin
								 if (address == 0) 
									begin
										state <= STATE_RESET;
									end
								 else 
									begin
										case(MODE)
										STATIC:
											begin
												state <= STATE_STATIC;
											end
										GRADIENT:
											begin
												state <= STATE_GRADIENT;
											end
										PICTURE:
											begin
												state <= STATE_PICTURE;
											end
										LINE:
											begin
												state <= STATE_LINE;
											end
										FLOW:
											begin
												state <= STATE_FLOW;
											end	
									endcase	
									end	
								end	
							endcase
						end
				end
			default:
				begin
					state <= STATE_TIMER;
				end
		endcase
	end 
end

endmodule
module Main(CLOCK_50, KEY, Data_in, Data_out);



input 		CLOCK_50;
input [1:0] KEY;

output reg Data_out;
input Data_in;


reg [LED_ADDRESS_WIDTH-1:0] 	address;


wire				hard_reset;
wire           reset_almost_done;
wire           led_almost_done;

wire 				data_request;
wire 				new_address;

wire [23:0]		Color_Data_Insert;


function integer log2;
input integer value;
begin
	value = value - 1;
	for (log2 = 0; value > 0; log2 = log2 + 1)
	 value = value >> 1;
end
endfunction













parameter 				AMOUNT_LEDS		= 36;
parameter 				SYSTEM_CLOCK	= 50_000_000;



localparam integer CYCLE_COUNT         = SYSTEM_CLOCK / 800000;
localparam integer RESET_COUNT         = 320 * CYCLE_COUNT;

localparam integer TH0_CYCLE_COUNT     = 0.32 * CYCLE_COUNT;
localparam integer TH1_CYCLE_COUNT     = 0.64 * CYCLE_COUNT;


localparam integer RESET_COUNTER_WIDTH = log2(RESET_COUNT);
localparam integer CLOCK_DIV_WIDTH     = log2(CYCLE_COUNT);
localparam integer LED_ADDRESS_WIDTH	= log2(AMOUNT_LEDS);

reg [CLOCK_DIV_WIDTH - 1:0]             clock_div;
reg [RESET_COUNTER_WIDTH - 1:0]         reset_counter;
reg [LED_ADDRESS_WIDTH - 1 :0]			 NEXT_LED;


reg [3:0] state;

localparam STATE_RESET    = 4'b0000;
localparam STATE_STATIC   = 4'b0001;
localparam STATE_PRE      = 4'b0010;
localparam STATE_TRANSMIT = 4'b0011;
localparam STATE_POST     = 4'b0100;
localparam STATE_RESTART  = 4'b0101;
localparam STATE_TIMER	  = 4'b0110;
localparam STATE_GRADIENT = 4'b0111;
localparam STATE_PICTURE  = 4'b1000;
localparam STATE_LINE	  = 4'b1001;
localparam STATE_FLOW	  = 4'b1010;


reg [1:0]	color;

localparam COLOR_G     = 2'b00;
localparam COLOR_R     = 2'b01;
localparam COLOR_B     = 2'b10;

reg [7:0]   green;						  
reg [7:0]   red;
reg [7:0]   blue;

reg [7:0]   current_byte;
reg [2:0]   current_bit;


wire [2:0]	MODE;

localparam STATIC    = 3'b000;
localparam GRADIENT  = 3'b001;
localparam PICTURE   = 3'b010;
localparam LINE		= 3'b011;
localparam FLOW		= 3'b100;



reg [23:0] 								Color_Data;
reg [5:0]								MODULE_COUNTER;
reg [LED_ADDRESS_WIDTH - 1 :0]	TOTAL_LEDS;
reg [21 :0] 							TIMER;
reg [1:0]								REVERSE_LED;
reg [1:0]								REVERSE_MODULE;
reg [1:0]								DIM_LED;
reg [1:0]								HALL_SWITCHED;
reg [3:0]								HALL_TIMER;


assign reset = !KEY[0];

assign reset_almost_done = (state == STATE_RESET) && (reset_counter == RESET_COUNT-1);
assign led_almost_done   = (state == STATE_POST)  && (color == COLOR_B) && (current_bit == 0) && (address != 0);

assign data_request = reset_almost_done || led_almost_done;
assign new_address  = (state == STATE_PRE) && (current_bit == 7);

assign MODE = PICTURE;


ROM1 rom(MODULE_COUNTER, CLOCK_50, Color_Data_Insert);

always @(posedge CLOCK_50)
begin
 if (reset) 
	begin

		state <= STATE_RESET;
		color <= COLOR_G;
		
		HALL_SWITCHED <= 0;
		TOTAL_LEDS <= 0;
		REVERSE_LED <= 0;
		REVERSE_MODULE <= 0;
		DIM_LED <= 0;
		NEXT_LED <= 0;
		Data_out <= 0;
		HALL_TIMER <= 0;
		
		address <= 0;
		reset_counter <= 0;
		current_bit <= 7;
		MODULE_COUNTER <= 0;
	 end 
 else 
	begin

		case (state)
			STATE_TIMER:
				begin
					if(TIMER == {20{1'b1}})
						begin
							state <= STATE_RESTART;
						end	
					else
						begin
							TIMER <= TIMER + 1;
						end	
				end
			STATE_RESTART:
				begin
						TIMER <= 0;
						state <= STATE_RESET;
						color <= COLOR_G;
						
						Data_out <= 0;
						address <= 0;
						reset_counter <= 0;
						current_bit <= 7;

						NEXT_LED <= 0;			
				end
			STATE_RESET:
				begin
					Data_out <= 0;
					if (reset_counter == RESET_COUNT - 1)
						begin
							reset_counter <= 0;
							
							case(MODE)
								STATIC:
									begin
										state <= STATE_STATIC;
									end
								GRADIENT:
									begin
										state <= STATE_GRADIENT;
									end
								PICTURE:
									begin
										state <= STATE_PICTURE;
									end
								LINE:
									begin
										state <= STATE_LINE;
									end
								FLOW:
									begin
										state <= STATE_FLOW;
									end	
							endcase		
						  end
					  else 
						  begin
							  reset_counter <= reset_counter + 1;
						  end
				end
			STATE_GRADIENT:
				begin
					if(NEXT_LED != TOTAL_LEDS)
						begin
							state <= STATE_PRE;
							color <= COLOR_G;
							
							red <= Color_Data[7:0];
							green <= Color_Data[15:8];
							blue <= Color_Data[23:16];
							
							NEXT_LED	<= NEXT_LED + 1;

							address <= address + 1;

							current_byte <= green;
							current_bit <= 7;
						end
					else
						begin
							if(REVERSE_LED == 0)
								begin
									if(TOTAL_LEDS == AMOUNT_LEDS)
										begin
											REVERSE_LED <= 1;
											DIM_LED <= 1;
										end
									else
										begin
											TOTAL_LEDS <= TOTAL_LEDS + 1;
											state <= STATE_TIMER;
										end
								end
							if(REVERSE_LED == 1)	
								begin	
									if(TOTAL_LEDS == 0 && MODULE_COUNTER == 6'b100101)
										begin
											REVERSE_MODULE <= 1;
											Color_Data <= Color_Data_Insert;
										end
									if(TOTAL_LEDS == 0 && MODULE_COUNTER == 0)
										begin
											REVERSE_MODULE <= 0;
											Color_Data <= Color_Data_Insert;
										end	
										
									if(TOTAL_LEDS == 0 && MODULE_COUNTER != 6'b100101 && REVERSE_MODULE == 0)
										begin
											MODULE_COUNTER <= MODULE_COUNTER + 1;
											Color_Data <= Color_Data_Insert;
										end
									if(TOTAL_LEDS == 0 && MODULE_COUNTER != 0 && REVERSE_MODULE == 1)
										begin
											MODULE_COUNTER <= MODULE_COUNTER - 1;
											Color_Data <= Color_Data_Insert;
										end
										
									if(TOTAL_LEDS == 0 && MODULE_COUNTER == 6'b100101)
										begin
											MODULE_COUNTER <= MODULE_COUNTER - 1;
										end
									if(TOTAL_LEDS == 0 && MODULE_COUNTER == 0)
										begin
											MODULE_COUNTER <= MODULE_COUNTER + 1;
										end	

									if(TOTAL_LEDS == 0)
										begin
											TOTAL_LEDS <= TOTAL_LEDS + 1;
											REVERSE_LED <= 0;
										end
										
									if(TOTAL_LEDS != 0)
										begin
											if(DIM_LED == 1)
												begin
													state <= STATE_TIMER;
													Color_Data <= 24'b000000000000000000000000;
													DIM_LED <= 0;
												end
											else
												begin
													state <= STATE_RESTART;
													Color_Data <= Color_Data_Insert;
													DIM_LED <= 1;
													TOTAL_LEDS  <= TOTAL_LEDS - 1;
												end
										end
								end
						end
				end
			STATE_STATIC:
				begin
					TOTAL_LEDS <= AMOUNT_LEDS;
					Color_Data	<= 24'b000000001111111100000000;
					
					if(NEXT_LED != TOTAL_LEDS)
						begin
							state <= STATE_PRE;
							color <= COLOR_G;
							
							red <= Color_Data[7:0];
							green <= Color_Data[15:8];
							blue <= Color_Data[23:16];
							
							NEXT_LED	<= NEXT_LED + 1;

							address <= address + 1;

							current_byte <= green;
							current_bit <= 7;
						end
				end
			STATE_PICTURE:
				begin
					TOTAL_LEDS <= AMOUNT_LEDS;
			
					if(Data_in == 1 && HALL_SWITCHED == 0)
					begin
						if(NEXT_LED != TOTAL_LEDS)
							begin
								state <= STATE_PRE;
								color <= COLOR_G;
								
								MODULE_COUNTER <= MODULE_COUNTER + 1;
								Color_Data <= Color_Data_Insert;
								
								red <= Color_Data[7:0];
								green <= Color_Data[15:8];
								blue <= Color_Data[23:16];
								
								NEXT_LED	<= NEXT_LED + 1;

								address <= address + 1;

								current_byte <= green;
								current_bit <= 7;
							end
							
						if(MODULE_COUNTER == 9'b1111100111)
						begin
							MODULE_COUNTER <= 0;
							Color_Data	<= Color_Data_Insert;
						end	
					end
					
					if(Data_in == 0 && HALL_SWITCHED == 1)
					begin
						if(NEXT_LED != TOTAL_LEDS)
							begin
								state <= STATE_PRE;
								color <= COLOR_G;
								
								Color_Data <= 24'b000000000000000000000000;
								
								red <= Color_Data[7:0];
								green <= Color_Data[15:8];
								blue <= Color_Data[23:16];
								
								NEXT_LED	<= NEXT_LED + 1;

								address <= address + 1;

								current_byte <= green;
								current_bit <= 7;
							end
						else
							begin
								state <= STATE_RESTART;
								HALL_SWITCHED <= 0;
							end	
					end
					
					if(Data_in == 0)
					begin
						HALL_SWITCHED <= 1;
					end
					
					if(Data_in == 1)
					begin
						HALL_SWITCHED <= 0;
					end
				end
			STATE_FLOW:
				begin	
					
					if(NEXT_LED == 0 && Data_in == 1 && HALL_SWITCHED == 0)
						begin
							HALL_SWITCHED <= 1;
							if(MODULE_COUNTER == 6'b100101)
								begin
									REVERSE_MODULE <= 1;
									MODULE_COUNTER <= MODULE_COUNTER - 1;
								end
							if(MODULE_COUNTER == 0)
								begin
									REVERSE_MODULE <= 0;
									MODULE_COUNTER <= MODULE_COUNTER + 1;
								end
							if(MODULE_COUNTER != 6'b100101 && REVERSE_MODULE == 0)
								begin
									MODULE_COUNTER <= MODULE_COUNTER + 1;
								end
							if(MODULE_COUNTER != 0 && REVERSE_MODULE == 1)
								begin
									MODULE_COUNTER <= MODULE_COUNTER - 1;
								end
						end
						
					if(Data_in == 0 && NEXT_LED == AMOUNT_LEDS)
						begin
							HALL_SWITCHED <= 0;
						end	
						
					TOTAL_LEDS <= AMOUNT_LEDS;	
					Color_Data	<= Color_Data_Insert;
					
					if(NEXT_LED != TOTAL_LEDS)
						begin
							state <= STATE_PRE;
							color <= COLOR_G;
							
							red <= Color_Data[7:0];
							green <= Color_Data[15:8];
							blue <= Color_Data[23:16];
							
							NEXT_LED	<= NEXT_LED + 1;

							address <= address + 1;

							current_byte <= green;
							current_bit <= 7;
						end
					else
						begin
							state <= STATE_RESTART;
						end	
				end
			STATE_LINE:
				begin
					TOTAL_LEDS <= AMOUNT_LEDS;
					
					if(NEXT_LED != TOTAL_LEDS)
						begin
							Color_Data <= 24'b000000000000000011111111;
							
							if(NEXT_LED >= 10 && NEXT_LED <= 23)
								begin
									Color_Data <= 24'b111111110000000000000000;
								end
							
							state <= STATE_PRE;
							color <= COLOR_G;
							
							red <= Color_Data[7:0];
							green <= Color_Data[15:8];
							blue <= Color_Data[23:16];
									
							NEXT_LED	<= NEXT_LED + 1;

							address <= address + 1;

							current_byte <= green;
							current_bit <= 7;
						end
				end
			STATE_PRE:
				begin
					state <= STATE_TRANSMIT;
					clock_div <= 0;
					Data_out <= 1;
				end
			STATE_TRANSMIT:
				begin
              if (current_byte[7] == 0 && clock_div >= TH0_CYCLE_COUNT) 
					begin
                 Data_out <= 0;
					end
              else if (current_byte[7] == 1 && clock_div >= TH1_CYCLE_COUNT) 
					begin
                 Data_out <= 0;
					end

              if (clock_div == CYCLE_COUNT-1)
					begin
						  state <= STATE_POST;
					end
              else 
					begin
						  clock_div <= clock_div + 1;
					end
				end
			STATE_POST: 
				begin
					if (current_bit != 0) 
						begin
						  current_byte <= {current_byte[6:0], 1'b0};
						  case (current_bit)
							  7: current_bit <= 6;
							  6: current_bit <= 5;
							  5: current_bit <= 4;
							  4: current_bit <= 3;
							  3: current_bit <= 2;
							  2: current_bit <= 1;
							  1: current_bit <= 0;
						  endcase
						  state <= STATE_PRE;
						end
					else 
						begin
						  case (color)
							  COLOR_G: 
								begin
								  state <= STATE_PRE;
								  color <= COLOR_R;
								  current_byte <= red;
								  current_bit <= 7;
								end
							  COLOR_R: 
								begin
								 state <= STATE_PRE;
								 color <= COLOR_B;
								 current_byte <= blue;
								 current_bit <= 7;
								end
							  COLOR_B: 
								begin
								 if (address == 0) 
									begin
										state <= STATE_RESET;
									end
								 else 
									begin
										case(MODE)
										STATIC:
											begin
												state <= STATE_STATIC;
											end
										GRADIENT:
											begin
												state <= STATE_GRADIENT;
											end
										PICTURE:
											begin
												state <= STATE_PICTURE;
											end
										LINE:
											begin
												state <= STATE_LINE;
											end
										FLOW:
											begin
												state <= STATE_FLOW;
											end	
									endcase	
									end	
								end	
							endcase
						end
				end
			default:
				begin
					state <= STATE_TIMER;
				end
		endcase
	end 
end

endmodule