BitFlow

Colour mixer

An RGB LED is three LEDs in one: rgb[2] red, rgb[1] green, rgb[0] blue. Red and green together look yellow, all three look white.

With switch 3 off, let switches 0–2 pick the colour. With switch 3 on, step through the seven colours by itself, one every quarter second, skipping 0 (off).

lab.v
drag to turn · scroll to zoom

Loading the board…

Press Run on the board: your Verilog is turned into gates in this browser and runs here, cycle by cycle.

Goals

  • ○Switches 0–2 pick the colour
  • ○With switch 3 on, it steps through all 7 colours every 0.25 s
Hints
  1. Registers start at 0, so count colour 0..6 and show colour + 1: colour <= (colour == 6) ? 0 : colour + 1;
  2. assign rgb = sw[3] ? colour + 1 : sw[2:0];

Pin log

Run the design to see its outputs change.

Put it on a real board

  • The Sipeed Tang Nano 9K (Gowin GW1NR-9) has no switches or an RGB LED: those ports go to header pins, where you can wire them.
  • The clock is set to the board's 27 MHz, and its active-low buttons and LEDs are flipped for you.
Waveform