how do I buffer serial to receive words instead of single characters?
hi everyone,
i'm having trouble code.. here's background: i've linked bluetooth phone, , want able send messages arduino. however, when type send word, sends out characters individually. i'm trying write code buffer characters , print when type period. here's code:
any tips? btw, i'm using 46 because think equals "." yeah? =)
i'm having trouble code.. here's background: i've linked bluetooth phone, , want able send messages arduino. however, when type send word, sends out characters individually. i'm trying write code buffer characters , print when type period. here's code:
any tips? btw, i'm using 46 because think equals "." yeah? =)
code: [select]
const int sens_pin = a0;
const int led_pin = 13;
int sensorvalue = 0;
int x = 0;
int words[100];
boolean toggle = true;
void setup()
{
serial.begin(9600);
pinmode(13, output);
pinmode(2, output);
pinmode(3, output);
digitalwrite(2, low);
digitalwrite(3, high);
}
void loop()
{
inputbuffer();
}
void inputbuffer()
{
if (serial.available())
{
words[x] = serial.read();
if(words[x] = 46)
{
int i;
serial.print("got: ");
(i = 0; < x; i++)
{
serial.print(words[i]);
}
serial.println("");
}
serial.print(words[x]);
digitalwrite(led_pin, toggle); // toggle led
toggle = !toggle;
x = x+1;
}
}
quote
btw, i'm using 46 because think equals "."
then, why not use '.'?
code: [select]
int words[100];one not read ints serial port. 1 not read words serial port.
code: [select]
void loop()
{
inputbuffer();
}could maybe add few more useless blank lines?
code: [select]
if(words[x] = 46)assigning 46 words
- succeed, test true. ==?
the words array should have better name. type should char. after each character added, null needs added after (but don't increment index again).code: [select](i = 0; < x; i++)
{
serial.print(words[i]);
}
if null terminated array, , right size/type, wouldn't need loop print it.
at point, might idea reset 0.
Arduino Forum > Using Arduino > Programming Questions > how do I buffer serial to receive words instead of single characters?
arduino
Comments
Post a Comment