Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ERROR con--> USB.read(); too few parameters
05-05-2014, 02:44 AM,
#1
ERROR con--> USB.read(); too few parameters
Hola acabo de comenzar con pingüino, y necesito ayuda, he encontrado un codigo que me permite encender/apagar leds a través de mensajes por USB, pero el IDE no me deja compilar la linea received_char = USB.read(); me dice too few parameters, buscando una solucion vi los ejemplos que vienen con el IDE y tampoco me deja, porfavor alguien que pueda ayudarme o darme otra opcion para hacer esto.
Estoy utilizando
- bootloader Bootloader_v4.14_18f4550_X20MHz
- IDE x4-easy-rev959

el codigo es:

char received_char;
char i;

void setup()
{
for (i=0 ;i<8 ;i++){
pinMode(i,OUTPUT);
digitalWrite(i,LOW);
}
}

void loop()
{
if (USB.available())
{
received_char = USB.read();

if (received_char == 'A') digitalWrite(0,HIGH);
if (received_char == 'B') digitalWrite(1,HIGH);
if (received_char == 'C') digitalWrite(2,HIGH);
if (received_char == 'D') digitalWrite(3,HIGH);

if (received_char == 'a') digitalWrite(0,LOW);
if (received_char == 'b') digitalWrite(1,LOW);
if (received_char == 'c') digitalWrite(2,LOW);
if (received_char == 'd') digitalWrite(3,LOW);
}
}
Reply
05-05-2014, 08:46 AM, (This post was last modified: 06-05-2014, 10:04 AM by gtcbreizh.)
#2
RE: ERROR con--> USB.read(); too few parameters
Sorry ! The USB library has been updated and the examples in examples/USB/usb have not been.
Here is your updated example. I tested it, it works !
char received_char;
char i;

Code:
void setup()
{
for (i=0 ;i<8 ;i++){
pinMode(i,OUTPUT);
digitalWrite(i,LOW);
}
}

void loop()
{
if (USB.available())
{
USB.read(&received_char); // the parameter is now a pointer with &

if (received_char == 'A') digitalWrite(0,HIGH);
if (received_char == 'B') digitalWrite(1,HIGH);
if (received_char == 'C') digitalWrite(2,HIGH);
if (received_char == 'D') digitalWrite(3,HIGH);

if (received_char == 'a') digitalWrite(0,LOW);
if (received_char == 'b') digitalWrite(1,LOW);
if (received_char == 'c') digitalWrite(2,LOW);
if (received_char == 'd') digitalWrite(3,LOW);
}
}

I add that the complete syntax for "read" is
receivedbyte =USB.read(buffer); // buffer is a pointer
with :
u8 receivedbyte; // number of bytes available in buffer[]
u8 buffer[64];

Look at the examples in examples/USB/Bulk, they are more complete.
BULK.read is identical to USB.read.
Hasta pronto
André

[Edited to remove unnecessary quotation of previous post]
Reply
11-05-2014, 05:46 AM,
#3
RE: ERROR con--> USB.read(); too few parameters
muchas gracias
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)