My function it does not work

Hi
look here my code and i can’t get the value for Prval = 100 on the glcd
please help

#include <glcd_Config.h>
#include <glcd.h>
#include “fonts/allFonts.h”
gText textArea;
String stringUNO,stringDOS;

int PosX;
int PosY;
int PrMax ;
int PrMin;
int PrVal;
int analogPin1 = A1;
int Fr=300;

void setup()
{
Serial.begin(9600);
GLCD.Init();
GLCD.SetDisplayMode(NON_INVERTED);
GLCD.ClearScreen();
GLCD.SelectFont(System5x7, BLACK); // font for the default text area
GLCD.DefineArea(90,8,110,8);
stringUNO = String(“PrVal.”);
stringDOS = String (“mb”);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
PosX=90;
PosY=0;
GLCD.GotoXY(PosX,PosY);
GLCD.print(stringUNO);
delay(500);
}

void loop()
{
digitalWrite(12, HIGH);
PosX=90;
PosY=8;
GLCD.GotoXY(PosX,PosY);
GLCD.EraseTextLine();
int Promedio ();// this function it does work
GLCD.print (PrVal);//
Serial.print (PrVal);//For debug only
Serial.print (Fr);//For debug only
delay(Fr);
PosX=115;
PosY=8;
GLCD.print(stringDOS);

digitalWrite(12, LOW);
delay(Fr);

}
int Promedio (){
PrVal=100;

return PrVal;
}

You need to declare your function earlier in you code. Try moving it before the loop() function.

elandd2011: My function it does not work

// declare it here, or move the function itself here
int Promedio();


void loop()
{
  digitalWrite(12, HIGH);
  PosX=90;
  PosY=8;
  GLCD.GotoXY(PosX,PosY);
  GLCD.EraseTextLine();

   // call it this way
   PrVal = Promedio();

  GLCD.print (PrVal);//
  Serial.print (PrVal);//For debug only
  Serial.print (Fr);//For debug only
  delay(Fr);
  PosX=115;
  PosY=8;
  GLCD.print(stringDOS);

  digitalWrite(12, LOW);
  delay(Fr);
   

}

whoa hold on, I thought Arduino generated function prototypes for you... https://github.com/arduino/Arduino/blob/master/app/src/processing/app/preproc/PdePreprocessor.java

frank26080115: whoa hold on, I thought Arduino generated function prototypes for you... https://github.com/arduino/Arduino/blob/master/app/src/processing/app/preproc/PdePreprocessor.java

This isn't valid syntax:

 GLCD.GotoXY(PosX,PosY);
  GLCD.EraseTextLine();
  int Promedio ();// this function it does work
  GLCD.print (PrVal);//
  Serial.print (PrVal);//For debug only

Either assign something or remove the int. eg.

int x = Promedio ();

or

Promedio ();

This isn't valid syntax:

It is perfectly valid syntax, otherwise, it wouldn't have compiled! It is simply a function prototype, not a call to the function.

Looks like you are right. ;)

Oh well, it "doesn't work" in the sense that it didn't call the function, like you said.

When people post that things "don't work" you often have to guess whether they mean "doesn't compile" or "doesn't do what I expect".

Agreed - my least favourite phrase is "it doesn't work".

Thx guys and you are right the real problem is it doesn`t do what i expect, but it compile well thx guys