Ambient Orb code

using 3 sliders and a picture box, super simple. Have to say though I forgot I could cast an int directly into a char and make that an ASCII value.


protected override void OnClosing(CancelEventArgs e)
{
if (serialPort.IsOpen)
serialPort.Close();

base.OnClosing(e);
}

private readonly double multOffset = (255/176);
private void changeColor(object sender, EventArgs e)
{
if (!serialPort.IsOpen)
{
serialPort.PortName = "COM4";
serialPort.Open();
}

writeBuffer("~D");
writeBuffer((char)tbRed.Value);
writeBuffer((char)tbGreen.Value);
writeBuffer((char)tbBlue.Value);

int red = Convert.ToInt16(tbRed.Value * multOffset);
int green = Convert.ToInt16(tbGreen.Value * multOffset);
int blue = Convert.ToInt16(tbBlue.Value * multOffset);

pictureBox1.BackColor = Color.FromArgb(red, green, blue);
}

private void writeBuffer(char buffer)
{
writeBuffer(buffer.ToString());
}

private void writeBuffer(string buffer)
{
byte[] bytes = ASCIIEncoding.Default.GetBytes(buffer);
serialPort.Write(bytes, 0, bytes.Length);
}

konk. Jun 23, 2007 @ 6:06 PM

# 
10k rpm ? i thought you were building a powerhouse. Anyway, my favorite cases of all time are cooler master cases. Check'em out.

Post a Comment

Please add 4 and 1 and type the answer here: