title: c# program to control and arduino rc car
body: <p>so I have made a c# program to control my RC car through a serial port and when I press the button to make the car move forward it keeps going when I un press the button. So in short I want to control the buttons with the arrow keys and when I press the key it should go forward then when I let it go it should stop. Thanks in advance for your help. And you can probably tell I am a newbie.</p>
  
  <p>picture of program:
    <a href="http://i.stack.imgur.com/yV8wa.jpg" rel="nofollow">http://i.stack.imgur.com/yV8wa.jpg</a></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using System.IO;
  using System.IO.Ports;
  using System.Threading;
  
  
  namespace CSharpEasySerial
  {
      public partial class frmSerial : Form
      {
  
      public static System.IO.Ports.SerialPort serialPort1;
      private delegate void LineReceivedEvent(string line);
  
      public frmSerial()
      {
          InitializeComponent();
      }
  
      private void btnConnect_Click(object sender, EventArgs e)
      {
          try
          {
              System.ComponentModel.IContainer components = new System.ComponentModel.Container();
              serialPort1 = new System.IO.Ports.SerialPort(components); // Creating the new object.
              serialPort1.PortName = "COM" + numCom.Value.ToString(); // Setting what port number.
              serialPort1.BaudRate = 9600; // Setting baudrate.
              serialPort1.DtrEnable = true; // Enable the Data Terminal Ready 
              serialPort1.Open(); // Open the port for use.
              btnConnect.Text = "Connected.";
              btnConnect.Enabled = false;
              numCom.Enabled = false;
              serialPort1.Write(new byte[] { 0x08 }, 0, 1);
          }
          catch
          {
              MessageBox.Show("Not Found. Try Again","Error");
          }
      }
  
      private void btnSend_Click(object sender, EventArgs e)
      {
          // Sends the text as a byte.
          serialPort1.Write(new byte[] { Convert.ToByte(txtDatasend.Text) }, 0, 1);
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          serialPort1.Write(new byte[] { 0x00 }, 0, 1);
          serialPort1.Write(new byte[] { 0x02 }, 0, 1);
      }
  </code></pre>