I'm hoping someone can help supply me with some code / suedo-code for a project I'm working on. Although I have experience with arduino, I've done very little serial communication.
I need to get the arduino to respond to specific input over serial from a terminal window.
In the terminal window, I'll be typing a 1 - 4 digit number, followed by a carriage return.
Ultimately I'd like this four digit number saved as an Int on the arduino.
I'm guessing each byte would need to be buffered until the carriage return is detected, but I'm having trouble working out how to do this.
If anyone could help it would be most appreciated.
if ( Serial.available() > 0) { // if there are bytes waiting on the serial port
char inByte = Serial.read(); // read a byte
delay(10); // *** added to make it work ***
if (inByte == '*') { // if that byte is the desired character
int len = 5; // expected string is 6 bytes long
char inString[len]; // declare string variable
for (int i = 0; i < len; i++) {
inString[i] = Serial.read();
}
if ( strstr(inString, "reset") != NULL )
{
reset();
}
if ( strstr(inString, "fast") != NULL )
{
fast();
}
if ( strstr(inString, "slow") != NULL )
{
slow();
}
}
that works with commands , what you want to do is turn instring into a int.
You need use itoa`s mate , itoa converts a int to a string.