Intel® FPGA University Program
University Program Material, Education Boards, and Laboratory Exercises
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.

VGA color change question

Altera_Forum
Honored Contributor II
761 Views

This module is a large green rectangle with two smaller rectangles inside called right product and left product. What I want to do is click on the small rectangles and have them change to another color. The clicking will be done with another module that calls a PS/2 mouse. I can just link the color change to a button on the DE2 board and then call in the mouse code later. Here is what I want to say: if there is no button push, stay red. If there is a button click turn blue. A push in the right direction would be appreciated. Thank you.  

 

module vga(CLOCK_50, VGA_HS, VGA_VS, VGA_R, VGA_G, VGA_B, VGA_CLK, VGA_BLANK, VGA_SYNC, KEY); 

// module vga input and output signals 

 

// Cyclone II system clock is 50 MHz 

input CLOCK_50; 

 

// VGA signals 

output[9:0] VGA_R, VGA_G, VGA_B; 

output VGA_HS, VGA_VS, VGA_CLK, VGA_BLANK, VGA_SYNC; 

 

input[3:0] KEY; 

 

// Define signals necessary to instantiate the vga_controller module 

wire clock_25; //A derived 25MHz clock  

wire displaying; 

wire[9:0] v_pos; 

wire[9:0] h_pos; 

wire v_blank, h_blank; 

wire[7:0] v_early, h_early; 

reg[3:0] r, g, b; 

 

 

// Create one hardware instance of a vga controller 

vga_controller vga_i(CLOCK_50, VGA_HS, VGA_VS, VGA_R, VGA_G, VGA_B, VGA_CLK, VGA_BLANK, VGA_SYNC, 

clock_25, r, g, b, displaying, v_pos, h_pos, v_blank, h_blank, v_early, h_early); 

 

/* This always block controls the colors of each individual pixel on the vga. 

* v_pos is the vertical position pixel coordinate being drawn (a row) 

* h_pos is the horizontal position pixel coordinate being drawn (a column) 

* The always block is activated whenever the v_pos or h_pos signal is changed by the  

* vga_controller. 

*/ 

always @(v_pos, h_pos) 

begin 

 

{r, g, b} = 0;//set screen to black 

 

if(h_pos >= 325 && h_pos <= 525 && v_pos >= 200 && v_pos <= 400)//bottom 2/3 of the venting machine 

{r,g,b} = {4'b0000,4'b1111,4'b0000}; 

 

if( h_pos >= 325 && h_pos <=345 && v_pos >= 100 && v_pos <= 199)//upper 1/3 of the vending machine, left side 

{r, g, b} = {4'b0000, 4'b1111, 4'b0000}; 

 

if( h_pos >= 505 && h_pos <=525 && v_pos >= 100 && v_pos <= 199)//uppper 1/3 of the vending machine, right side 

{r, g, b} = {4'b0000, 4'b1111, 4'b0000}; 

 

if( h_pos >= 325 && h_pos <=525 && v_pos >= 85 && v_pos <= 99)//top of vending machine 

{r, g, b} = {4'b0000, 4'b1111, 4'b0000};  

 

if( h_pos >= 405 && h_pos <=445 && v_pos >= 100 && v_pos <= 199) //center line dividing the rt and lf products 

{r, g, b} = {4'b0000, 4'b1111, 4'b0000};  

 

if( h_pos >= 346 && h_pos <=404 && v_pos >= 100 && v_pos <= 199)//left product 

{r, g, b} = {4'b1110, 4'b0000, 4'b0000};  

 

if( h_pos >= 446 && h_pos <=504 && v_pos >= 100 && v_pos <= 199)//right product 

{r, g, b} = {4'b1010, 4'b1010, 4'b0100};  

 

 

end 

 

endmodule
0 Kudos
0 Replies
Reply