X Y graph.

This program is drawing 2 horizontal lines with length proportional to input voltage on PA6 and PA7.

#include <LCD5110_Graph.h>

//LCD5110 myGLCD(8,9,10,12,11);
LCD5110 myGLCD(PA4, PA3, PA2, PA0, PA1);

extern unsigned char SmallFont[];
extern unsigned char TinyFont[];

int LDRpin = PA6;
int LDRpin2 = PA7;
int volt;
char lightString [4];
char lightString2 [4];

String str;
String str2;

int lightIntensity = 0;
int lightIntensity2 = 0;

void setup()
{

  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  randomSeed(analogRead(PB6));
  randomSeed(analogRead(PB7));
}

void loop()
{

  myGLCD.clrScr();
  myGLCD.update();

  lightIntensity = analogRead(LDRpin);
  lightIntensity2 = analogRead(LDRpin2);

  lightIntensity = map(lightIntensity, 0, 4095, 0, 100);
  lightIntensity2 = map(lightIntensity2, 0, 4095, 0, 100);

  str = String(lightIntensity) + "%";
  str2 = String(lightIntensity2) + "%";

  //str.toCharArray(lightString, 4);
  str.toCharArray(lightString, 6);
  str2.toCharArray(lightString2, 4);


  // high line
  myGLCD.print(lightString2, 2, 17);
  printBar();
  fillBar2(lightIntensity2);

  //low line
  myGLCD.print(lightString, 2, 32);
  printBar();
  fillBar(lightIntensity);
  myGLCD.update();
  delay(100);
}

void printBar()
{
  myGLCD.update();
}


//..............................................................
void fillBar(int percent) // X
{

  percent = map(percent, 0, 100, 2, 81);
  myGLCD.drawLine(2, 44, percent, 44);

}
void fillBar2(int volt) // Y ?
{
  volt = map(volt, 0, 100, 2, 81);
  myGLCD.drawLine(2, 40, volt, 40);
}

To make X -Y graph the code below dotted line need to be modify, my attempt gives this error.

void  printBar(  void fillBar(int percent), void fillBar2(int volt)  )

  {

  percent = map(percent, 0, 100, 2, 81);
  volt = map(volt, 0, 100, 2, 81);

 myGLCD.drawLine(2, 44, percent, volt); // x1 = 2, y1 = 44, x2 = percent, y2=volt;

  }

Arduino: 1.8.9 (Mac OS X), Board: “Generic STM32F103C series, STM32F103C8 (20k RAM. 64k Flash), STLink, 72Mhz (Normal), Smallest (default)”

/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino: In function ‘void loop()’:
nokia_xy_4:53:3: error: ‘fillBar2’ was not declared in this scope
fillBar2(lightIntensity2);
^~~~~~~~
nokia_xy_4:58:3: error: ‘fillBar’ was not declared in this scope
fillBar(lightIntensity);
^~~~~~~
/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino:58:3: note: suggested alternative: ‘printBar’
fillBar(lightIntensity);
^~~~~~~
printBar

This part of errors comes from modified part of code

/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino: In function ‘void printBar(void ()(int), void ()(int))’:
nokia_xy_4:92:3: error: ‘percent’ was not declared in this scope
percent = map(percent, 0, 100, 2, 81);
^~~~~~~
/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino:92:3: note: suggested alternative: ‘_reent’
percent = map(percent, 0, 100, 2, 81);
^~~~~~~
_reent
exit status 1
‘fillBar2’ was not declared in this scope

void printBar( void fillBar(int percent), void... What’s that?

This line is complete nonsense:

void  printBar(  void fillBar(int percent), void fillBar2(int volt)  )

Perhaps you meant:

void  printBar(int percent, int volt )

Maybe you intended to call those two functions?

void  printBar(int percent, int volt)
{
  fillBar(percent);
  fillBar2(volt);

I know it is incorrect
This shows which elements of code need proper arrangement

void  printBar (   fillBar(int percent),  fillBar2(int volt)  )

error

Arduino: 1.8.9 (Mac OS X), Board: "Generic STM32F103C series, STM32F103C8 (20k RAM. 64k Flash), STLink, 72Mhz (Normal), Smallest (default)"

nokia_xy_4:89:20: error: expected constructor, destructor, or type conversion before ';' token
void printBar ( fillBar(int percent), fillBar2(int volt) )
^
/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino: In function 'void loop()':
nokia_xy_4:53:3: error: 'fillBar2' was not declared in this scope
fillBar2(lightIntensity2);
^~~~~~~~
nokia_xy_4:58:3: error: 'fillBar' was not declared in this scope
fillBar(lightIntensity);
^~~~~~~
/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino:58:3: note: suggested alternative: 'printBar'
fillBar(lightIntensity);
^~~~~~~
printBar
/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino: At global scope:
nokia_xy_4:89:20: error: variable or field 'printBar' declared void
void printBar ( fillBar(int percent), fillBar2(int volt) )
^~~~~~~
nokia_xy_4:89:28: error: expected primary-expression before 'int'
void printBar ( fillBar(int percent), fillBar2(int volt) )
^~~
nokia_xy_4:89:20: error: 'fillBar' was not declared in this scope
void printBar ( fillBar(int percent), fillBar2(int volt) )
^~~~~~~
/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino:89:20: note: suggested alternative: 'printBar'
void printBar ( fillBar(int percent), fillBar2(int volt) )
^~~~~~~
printBar
nokia_xy_4:89:52: error: expected primary-expression before 'int'
void printBar ( fillBar(int percent), fillBar2(int volt) )
^~~
nokia_xy_4:89:43: error: 'fillBar2' was not declared in this scope
void printBar ( fillBar(int percent), fillBar2(int volt) )
^~~~~~~~
exit status 1
expected constructor, destructor, or type conversion before ';' token

But you’re not calling fillBar in printBar, so why pass the function pointer printBar?

It’s hard to tell what you are trying to do.

//void drawLine(int (fillBar(int percent)), int (fillBar2(int volt)) )
//void  printBar (   fillBar(int percent),  fillBar2(int volt)  )
//void  printBar(int percent, int volt )
void  printBar(  void fillBar(int percent), void fillBar2(int volt)  )
{
  percent = map(percent, 0, 100, 2, 81);
  volt = map(volt, 0, 100, 2, 81);
  fillBar(percent);
  fillBar2(volt);
  myGLCD.drawLine(2, 44, percent, volt); // x1 = 2, y1 = 44, x2 = percent, y2=volt;
}

error

/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino: In function 'void loop()':
nokia_xy_4:53:3: error: 'fillBar2' was not declared in this scope
fillBar2(lightIntensity2);
^~~~~~~~
nokia_xy_4:58:3: error: 'fillBar' was not declared in this scope
fillBar(lightIntensity);
^~~~~~~
/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino:58:3: note: suggested alternative: 'printBar'
fillBar(lightIntensity);
^~~~~~~
printBar
/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino: In function 'void printBar(void ()(int), void ()(int))':
nokia_xy_4:93:3: error: 'percent' was not declared in this scope
percent = map(percent, 0, 100, 2, 81);
^~~~~~~
/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino:93:3: note: suggested alternative: '_reent'
percent = map(percent, 0, 100, 2, 81);
^~~~~~~
_reent
exit status 1
'fillBar2' was not declared in this scope

You’ve already tried that and it failed, so why try it again?

This error comes from modified part of code, above this line error is from not modified part of code which is working OK in original version

.........................................................
printBar
/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino: In function 'void printBar(void ()(int), void ()(int))':
nokia_xy_4:93:3: error: 'percent' was not declared in this scope
percent = map(percent, 0, 100, 2, 81);
^~~~~~~
/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino:93:3: note: suggested alternative: '_reent'
percent = map(percent, 0, 100, 2, 81);
^~~~~~~
_reent
exit status 1
'fillBar2' was not declared in this scope

Slow down.
Stop throwing mud at the wall in the hope something will stick.

Please describe what you want to do, NOT how you think you should do it.

This is another approach and error

/////////////////////////////////////////////////
  //void  drawLine(  int percent, int volt   )
  //void  drawLine(  fillBar(int percent), fillBar2(int volt)  )
  void  drawLine( int fillBar,int percent,int fillBar2,int volt  )
  //////////////////////////////////////////////////
  {
  float x1, y1, x2, y2;

  x1 = 2;
  y1 = 40 ;

  x2 =   void fillBar(int percent) // X
  {
    percent = map(percent, 0, 100, 2, 81);
    myGLCD.drawLine(2, 44, percent, 44);

  }

  y2 = void fillBar2(int volt) // Y
  {
    volt = map(volt, 0, 100, 2, 81);
    myGLCD.drawLine(2, 40, volt, 40);
  }
    myGLCD.drawLine(x1, y1, x2, y2); // x1 = 2, y1 = 40, x2 = percent, y2=volt;
  }

error

/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino: In function ‘void loop()’:
nokia_xy_4:53:3: error: ‘fillBar2’ was not declared in this scope
fillBar2(lightIntensity2);
^~~~~~~~
nokia_xy_4:58:3: error: ‘fillBar’ was not declared in this scope
fillBar(lightIntensity);
^~~~~~~
/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino:58:3: note: suggested alternative: ‘printBar’
fillBar(lightIntensity);

…modified part of code
^~~~~~~
printBar
/Users/kor/Documents/Arduino/nokia_xy_4/nokia_xy_4.ino: In function ‘void drawLine(int, int, int, int)’:
nokia_xy_4:113:10: error: expected primary-expression before ‘void’
x2 = void fillBar(int percent) // X
^~~~
nokia_xy_4:120:8: error: expected primary-expression before ‘void’
y2 = void fillBar2(int volt) // Y
^~~~
exit status 1
‘fillBar2’ was not declared in this scope

OK, so “slow down” obviously means something different in your language.

Ask yourself " Why am I trying to assign the non-existent return value from a void function to a variable?"

Line
Left end = x1=2, y1= 40
Right end = x2 = percent, y2 = volt

What has that graph got to do with your problem involving “percent” and “lightintensity”?

I have 2 horizontal lines length of them depends to applied voltage

 myGLCD.drawLine(2, 44, percent, 44);
 myGLCD.drawLine(2, 40, volt, 40);

I need one line

  myGLCD.drawLine(2, 44, percent, volt);

as on the picture, left end = constant ,
right end = variable
X-axis = percent
Y-axis = v

TheMemberFormerlyKnownAsAWOL:
What has that graph got to do with your problem involving "percent" and "lightintensity"?

TheMemberFormerlyKnownAsAWOL:
What has that graph got to do with your problem involving "percent" and "lightintensity"?

That are the names from original code, should be changed to Ux and Uy

Here is code with proper names

#include <LCD5110_Graph.h>

//LCD5110 myGLCD(8,9,10,12,11);
LCD5110 myGLCD(PA4, PA3, PA2, PA0, PA1);

extern unsigned char SmallFont[];
extern unsigned char TinyFont[];

int LDRpin = PA6;
int LDRpin2 = PA7;
int volt;
char lightString [4];
char lightString2 [4];

String str;
String str2;

int lightIntensity = 0;
int lightIntensity2 = 0;
/////////////////////////////
int Ux = 0;
int Uy = 0;
///////////////////////
void setup()
{

  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  randomSeed(analogRead(PB6));
  randomSeed(analogRead(PB7));
}

void loop()
{

  myGLCD.clrScr();
  myGLCD.update();

  lightIntensity  = analogRead(LDRpin);
  lightIntensity2 = analogRead(LDRpin2);

  lightIntensity = map(lightIntensity, 0, 4095, 0, 100);
  lightIntensity2 = map(lightIntensity2, 0, 4095, 0, 100);
//////////////////////////////////
 Ux = analogRead(LDRpin);
Uy = analogRead(LDRpin2);

 Ux  = map(Ux, 0, 4095, 0, 100);
 Uy = map(Uy, 0, 4095, 0, 100);
/////////////////////////////////
  str = String(Ux) + "%";
  str2 = String(Uy) + "%";

  //str.toCharArray(lightString, 4);
  str.toCharArray(lightString, 6);
  str2.toCharArray(lightString2, 4);


  // high line
  myGLCD.print(lightString2, 2, 17);
  printBar();
  fillBar2(Uy);

  //low line
  myGLCD.print(lightString, 2, 32);
  printBar();
  fillBar(Ux);
  myGLCD.update();
  delay(100);
}

void printBar()
{
  myGLCD.update();
}


//..............................................................

  void fillBar(int percent) // X
  {
  percent = map(percent, 0, 100, 2, 81);
  myGLCD.drawLine(2, 44, percent, 44);

  }
  void fillBar2(int volt) // Y ?
  {
  volt = map(volt, 0, 100, 2, 81);
  myGLCD.drawLine(2, 40, volt, 40);
  }
  lightIntensity  = analogRead(LDRpin);
  lightIntensity2 = analogRead(LDRpin2);

  lightIntensity = map(lightIntensity, 0, 4095, 0, 100);
  lightIntensity2 = map(lightIntensity2, 0, 4095, 0, 100);
//////////////////////////////////
 Ux = analogRead(LDRpin);
Uy = analogRead(LDRpin2);

 Ux  = map(Ux, 0, 4095, 0, 100);
 Uy = map(Uy, 0, 4095, 0, 100);

I don’t understand this code - you will have almost the same values in lightIntensity and lightIntensity2 as you have in Ux and Uy.
Sometimes, they may even be identical.

Ux = voltage applied to PB6
Uy = voltage applied to PB7

That will be Lissajous Figures for DC voltages

tom321:
Ux = voltage applied to PB6
Uy = voltage applied to PB7

That will be Lissajous Figures for DC voltages

So what is the significance of the graph in reply #12?