Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
18 views1 page

Buton Led 1

The document contains code for a Windows Forms application that controls an LED via a serial port. It initializes the serial port on form load, sends commands to turn the LED on or off with button clicks, and ensures the serial port is closed when the form is closing. The interface includes two buttons to control the LED and a label to display its status.

Uploaded by

seçkin acun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

Buton Led 1

The document contains code for a Windows Forms application that controls an LED via a serial port. It initializes the serial port on form load, sends commands to turn the LED on or off with button clicks, and ensures the serial port is closed when the form is closing. The interface includes two buttons to control the LED and a label to display its status.

Uploaded by

seçkin acun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

private void Form1_Load(object sender, EventArgs e)

{
serialPort1.PortName = "COM7";
serialPort1.BaudRate = 9600;
serialPort1.Open();
button2.Enabled = false;
}

private void button1_Click(object sender, EventArgs e)


{
serialPort1.Write("1");
label1.Text = "LED ON";
button1.Enabled = false;
button2.Enabled = true;
}

private void button2_Click(object sender, EventArgs e)


{
serialPort1.Write("0");
label1.Text = "LED OFF";
button1.Enabled = true;
button2.Enabled = false;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)


{
if (serialPort1.IsOpen == true)
{
serialPort1.Close();
}

You might also like