I want to control a rc car with an arduino. To control it i use C#. When i want to drive forward i press the UP-key on my Computer and a Character will be sendet out over XBEE. The arduino recive it and activate the Motor. That works fine but i have a problem to put the output of the arduino LOW when i release the button on my computer. I don´t want to send out another char. when I release the Button.
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.Ports;
namespace RC_car_1
{
public partial class Form1 : Form
{
SerialPort port;
String w = "w", s = "s", l = "l", r = "r";
public Form1()
{
InitializeComponent();
port = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);
port.Open();
I had implementet that before. When i released the button another char was sendet out and set the output LOW. That worked fine. The problem was when i came out of the Range from the Xbee the char from releasing the button didn´t arrive and the car never stopped. So what i want is that the arduino code set the output LOW when i release the butten, that means when no chars arrive to arduino.
How does the Arduino code know when you have released the key?
Please use the # icon on the editors toolbar when posting code.
You can go back and edit your previous posts to achieve the same effect.
If you want the car to stop if it doesn't receive any input, you should add some code on the Arduino to detect the lack of input -> something like this:
// global variable declarations
unsigned long previousMillis = 0;
unsigned long interval = 100; // 1/10 second
at the begining of your loop add
unsigned long currentMillis = Millis();
after
if (Serial.available() > 0)
{
buffer=Serial.read()
add this
previousMillis = currentMillis;
then after the if statement closes
if(currentMillis - previousMillis > interval) {
//code to stop the car
}
this will cause the car to stop if it doesn't receive input for interval ms