Serial.readbytes()

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
bhuvaneshnick
 
Posts: 20
Joined: Wed Jan 01, 2014 1:23 am

Serial.readbytes()

Post by bhuvaneshnick »

Code: Select all

void setup()
{
  Serial.begin(9600);
}
void loop()
{
  if(Serial.available())
  {
    char a=Serial.readBytes(char,6)
    Serial.println(a);
  }
my idea is to read upto 6 bytes so i used 6(char,6) and to store buffer in character so declared as char(char,6).serial.readuntil function return character stored in buffer so assigned that to char

but i am getting error:"primary expression missing before char"

maybe this due to my poor understanding of that function help me please

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Serial.readbytes()

Post by adafruit_support_rick »

Code: Select all

void setup()
{
  Serial.begin(9600);
}
void loop()
{
  if(Serial.available())
  {
    char a[7];         //define an array of size 6 + room for 1 terminal null
    int count;
    count = Serial.readBytes(a,6)    //read up to 6 bytes into array a, return number of bytes read
    a[count] = 0;    //append terminal null
    Serial.println(a);       //print array a
  }

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”