2 using System.Collections.Generic;
 
   3 using System.ComponentModel;
 
   8 using System.Windows.Forms;
 
  12     public partial class LEDMixer : Form
 
  14         private const int LIGHT_MAX = 0x1F;
 
  18             InitializeComponent();
 
  21         private void LEDMixer_Load(object sender, EventArgs e)
 
  23             for (int i = 1; i <= 99; i++)
 
  24                 cbPort.Items.Add("COM" + i.ToString());
 
  26             cbPort.SelectedIndex = 0;
 
  28             tbRed.Maximum = LIGHT_MAX;
 
  29             tbGreen.Maximum = LIGHT_MAX;
 
  30             tbBlue.Maximum = LIGHT_MAX;
 
  33         private void tbRed_Scroll(object sender, EventArgs e)
 
  35             NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);
 
  38         private void tbGreen_Scroll(object sender, EventArgs e)
 
  40             NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);
 
  43         private void tbBlue_Scroll(object sender, EventArgs e)
 
  45             NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);
 
  48         private void NotifyLight(int Red, int Green, int Blue)
 
  50             byte[] buffer = new byte[3];
 
  51             buffer[0] = (byte)(0x80 | (Red & LIGHT_MAX));
 
  52             buffer[1] = (byte)(0x40 | (Green & LIGHT_MAX));
 
  53             buffer[2] = (byte)(0x20 | (Blue & LIGHT_MAX));
 
  57                 serSerialPort.PortName = cbPort.Text;
 
  59                 serSerialPort.Write(buffer, 0, buffer.Length);
 
  60                 serSerialPort.Close();
 
  68         private void cbPort_SelectedIndexChanged(object sender, EventArgs e)
 
  70             NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);