Lorsque je compile ce code, celui-ci m'indique une erreur de type "too few arguments to function 'int intround(const float&)'" Je ne vois pas pourquoi car je l'ai déclaré qu'une seule fois. Pouvez-vous m'expliquer d'où peut venir cet erreur?
Merci.
#include "lcd4d.h"
static char messagetext[LCD4D_WIDTH]="";
boolean force_lcd_update=false;
//return for string conversion routines
static char conv[8];
#define BUFFLEN 30
static char cmd_buff[BUFFLEN];
static int buff_index=0;
static unsigned long previous_millis_lcd=0;
#define degHotend0()// degHotend(0)
static int olddegHotEnd0=0;
static int oldtargetHotEnd0=0;
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
//lcd4d_init();
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()>0)
{
char letter = Serial.read();
Serial.println(letter);
if(letter == '1')
{
digitalWrite(13,HIGH);
Serial.println("The LED is ON");
}
else if (letter == '0')
{
digitalWrite(13,LOW);
Serial.println("The LED is OFF");
}
}
}
int intround (const float &x)
{
return int(0.5+x);
}
void lcd4d_incoming()
{
while(MYSERIAL1.available()>0)
{
cmd_buff[buff_index]= (char) MYSERIAL1.read();
Serial.println(Serial.read());
Serial.println(cmd_buff[buff_index]);
if (cmd_buff[buff_index]=='\n')
{
cmd_buff[buff_index]= 0;
// parsecmd(cmd_buff,buff_index);
buff_index = 0;
} else
buff_index++;
if(buff_index >= BUFFLEN)
{
buff_index = BUFFLEN-1;
}
}
}
void lcd4d_force_update()
{
force_lcd_update=true;
}
void lcd4d_status(const char* message)
{
strncpy(messagetext,message,LCD4D_WIDTH);
messagetext[strlen(message)]=0;
}
void lcd4d_statuspgm(const char* message)
{
char ch=pgm_read_byte(message);
char *target=messagetext;
uint8_t cnt=0;
while(ch &&cnt<LCD4D_WIDTH)
{
*target=ch;
target++;
cnt++;
ch=pgm_read_byte(++message);
}
*target=0;
}
void lcd4d_status()
{
if(!force_lcd_update)
if((millis() - previous_millis_lcd) < LCD4D_UPDATE_INTERVAL)
return;
lcd4d_update();
previous_millis_lcd=millis();
}
void lcd4d_init()
{
MYSERIAL1.begin(115200);
SERIAL1_PROTOCOLPGM(MESSAGE_ID)
SERIAL1_PROTOCOLLNPGM(WELCOME_MSG)
}
void lcd4d_update() {
lcd4d_showStatus();
}
void zeroFill(int value)
{
if(value < 100)
SERIAL1_PROTOCOLPGM("0");
if(value < 10)
SERIAL1_PROTOCOLPGM("0");
}
void lcd4d_showStatus()
{
//HotEnd0
int tHotEnd0=intround (degHotend0());
if(tHotEnd0!=olddegHotEnd0 || force_lcd_update)
{
SERIAL1_PROTOCOLPGM(HOTEND0_ID)
zeroFill(tHotEnd0);
SERIAL1_PROTOCOLLN(tHotEnd0)
olddegHotEnd0=tHotEnd0;
}
int ttHotEnd0=intround(degTargetHotend0());
if(ttHotEnd0!=oldtargetHotEnd0 || force_lcd_update)
{
SERIAL1_PROTOCOLPGM(THOTEND0_ID)
if(ttHotEnd0==-272) // First time, force update
{
SERIAL1_PROTOCOLLN("000")
oldtargetHotEnd0=0;
}
else
{
zeroFill(ttHotEnd0);
SERIAL1_PROTOCOLLN(ttHotEnd0)
oldtargetHotEnd0=ttHotEnd0;
}
}
}
// convert float to string with +123.4 format
char *ftostr3(const float &x)
{
//sprintf(conv,"%5.1f",x);
int xx=x;
conv[0]=(xx/100)%10+'0';
conv[1]=(xx/10)%10+'0';
conv[2]=(xx)%10+'0';
conv[3]=0;
return conv;
}
char *itostr2(const uint8_t &x)
{
//sprintf(conv,"%5.1f",x);
int xx=x;
conv[0]=(xx/10)%10+'0';
conv[1]=(xx)%10+'0';
conv[2]=0;
return conv;
}
// convert float to string with +123.4 format
char *ftostr31(const float &x)
{
int xx=x*10;
conv[0]=(xx>=0)?'+':'-';
xx=abs(xx);
conv[1]=(xx/1000)%10+'0';
conv[2]=(xx/100)%10+'0';
conv[3]=(xx/10)%10+'0';
conv[4]='.';
conv[5]=(xx)%10+'0';
conv[6]=0;
return conv;
}
char *ftostr32(const float &x)
{
int xx=x*100;
conv[0]=(xx>=0)?'+':'-';
xx=abs(xx);
conv[1]=(xx/100)%10+'0';
conv[2]='.';
conv[3]=(xx/10)%10+'0';
conv[4]=(xx)%10+'0';
conv[6]=0;
return conv;
}
char *itostr31(const int &xx)
{
conv[0]=(xx>=0)?'+':'-';
conv[1]=(xx/1000)%10+'0';
conv[2]=(xx/100)%10+'0';
conv[3]=(xx/10)%10+'0';
conv[4]='.';
conv[5]=(xx)%10+'0';
conv[6]=0;
return conv;
}
char *itostr3(const int &xx)
{
conv[0]=(xx/100)%10+'0';
conv[1]=(xx/10)%10+'0';
conv[2]=(xx)%10+'0';
conv[3]=0;
return conv;
}
char *itostr4(const int &xx)
{
conv[0]=(xx/1000)%10+'0';
conv[1]=(xx/100)%10+'0';
conv[2]=(xx/10)%10+'0';
conv[3]=(xx)%10+'0';
conv[4]=0;
return conv;
}
// convert float to string with +1234.5 format
char *ftostr51(const float &x)
{
int xx=x*10;
conv[0]=(xx>=0)?'+':'-';
xx=abs(xx);
conv[1]=(xx/10000)%10+'0';
conv[2]=(xx/1000)%10+'0';
conv[3]=(xx/100)%10+'0';
conv[4]=(xx/10)%10+'0';
conv[5]='.';
conv[6]=(xx)%10+'0';
conv[7]=0;
return conv;
}
// convert float to string with +123.45 format
char *ftostr52(const float &x)
{
int xx=x*100;
conv[0]=(xx>=0)?'+':'-';
xx=abs(xx);
conv[1]=(xx/10000)%10+'0';
conv[2]=(xx/1000)%10+'0';
conv[3]=(xx/100)%10+'0';
conv[4]='.';
conv[5]=(xx/10)%10+'0';
conv[6]=(xx)%10+'0';
conv[7]=0;
return conv;
}
Facile: "to few arguments to function int intround()".
On ne peut pas le dire mieux: la fonction demande un argument, qui n'est pas fourni lors de tes appel à ta fonction.
Ligne 139, tu passes degHotend0() en argument. Or, ligne 16, il y a une macro pré-processeur qui fait correspondre degHotend0() à... rien. Donc ça revient à appeler une fonction vide.
Ligne 148, tu passes en argument quelque chose qui n'est défini ni comme fonction, ni comme variable, ni comme macro pré-processeur, ni dans ton fichier, ni dans le fichier inclus. Je pense que lorsque tu auras réglé le problème du premier appel à la fonction, ce deuxième appel générera lui aussi une erreur.
vince3011:
Ligne 148, tu passes en argument quelque chose qui n'est défini ni comme fonction, ni comme variable, ni comme macro pré-processeur, ni dans ton fichier, ni dans le fichier inclus. Je pense que lorsque tu auras réglé le problème du premier appel à la fonction, ce deuxième appel générera lui aussi une erreur.
Tu n'as pas d'autres informations sur l'erreur de compilation? Est-ce que tu as activé, dans les réglages, "afficher les résultats détaillés"? En principe ça pointe du doigt ce qui pose problème.
SERIAL:64: error: expected primary-expression before 'const'
lcd4d_status(const char* message);
^
SERIAL:66: error: expected primary-expression before 'const'
lcd4d_statuspgm(const char* message);
^
Error compiling for board Arduino/Genuino Mega or Mega 2560."
Là je ne sais pas trop quoi te dire. Je ne connais pas suffisamment les subtilités du C / C++ pour savoir si ça vient de la double définition de la fonction en dehors de la définition d'une classe (auquel cas quand tu décommente l'un, commente l'autre), si ça vient du passage de variable par pointeur constant (pas encore tout à fait bien compris le mécanisme, et je n'ai pas réussi à le faire fonctionner sur Arduino), ou si ça vient d'encore autre chose. D'où vient le code? Il n'y a pas des exemples avec?