Solved Please explain why this code for displaying analog inputs dose not work

///

int analogPin1 = A0; 
int analogPin2 = A1;
int analogPin3 = A2;
int val = 0;  
int hal = 0;
int pal = 0;
void setup() {
  Serial.begin(9600);          
}

void loop() {
  val = analogRead(analogPin1);  
 hal = analogRead(analogPin2);  
  pal = analogRead(analogPin3);  
  Serial.print(pal,val,hal); }

///

Where have you seen code like this before?

Please remember to use code tags when posting code.

(BTW, there is no reason pal, hal, val should have global scope.)

Serial.print(pal,val,hal);

Wrong syntax for Serial.print()
Print each variable separately

Serial.print(pal);
Serial.print(val);
Serial.print(hal);

You might want some linefeeds between each variable too.

this is just some code i got from an tutorial that I modified for multiple inputs it worked just did not display all three inputs separately then i looked around and found that you can use multiple int in a display from this post Display multiple analog inputs over USB - #6 by system but this did not work for some reason

i had originally tried this but it would give an output like this
1
5
6
6
5
and all the input were combined into one string
where i was looking for this
1 5 6
o 5 6
1 4 8

Read the forum guidelines to see how to properly post code and some hints on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

This example will write a string with comma separated values (CSV). I introduced a delay so that the serial port is not flooded.
Note that the code is posted in code tags and formatted with the IDE autoformat tool.

int analogPin1 = A0;
int analogPin2 = A1;
int analogPin3 = A2;
int val = 0;
int hal = 0;
int pal = 0;
void setup()
{
   Serial.begin(9600);
}

void loop()
{
   static unsigned long timer = 0;
   unsigned long interval = 100;
   if (millis() - timer >= interval)
   {
      timer = millis();
      val = analogRead(analogPin1);
      hal = analogRead(analogPin2);
      pal = analogRead(analogPin3);
      Serial.print(pal);
      Serial.print(',');
      Serial.print(val);
      Serial.print(',');
      Serial.println(hal);
   }
}

btw i am using version 1.8.19 of Arduino because i have an old board

Could you link that code, please?

here is the error mesage it gave me

C:\Users\mvfed\Documents\Arduino\sketch_jan03a\sketch_jan03a.ino: In function 'void loop()':
sketch_jan03a:17:27: error: no matching function for call to 'HardwareSerial::print(int&, int&, int&)'
   Serial.print(pal,val,hal);
                           ^
In file included from C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Stream.h:26:0,
                 from C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/HardwareSerial.h:29,
                 from C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:233,
                 from sketch\sketch_jan03a.ino.cpp:1:
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:65:12: note: candidate: size_t Print::print(const __FlashStringHelper*)
     size_t print(const __FlashStringHelper *);
            ^~~~~
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:65:12: note:   candidate expects 1 argument, 3 provided
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:66:12: note: candidate: size_t Print::print(const String&)
     size_t print(const String &);
            ^~~~~
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:66:12: note:   candidate expects 1 argument, 3 provided
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:67:12: note: candidate: size_t Print::print(const char*)
     size_t print(const char[]);
            ^~~~~
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:67:12: note:   candidate expects 1 argument, 3 provided
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:68:12: note: candidate: size_t Print::print(char)
     size_t print(char);
            ^~~~~
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:68:12: note:   candidate expects 1 argument, 3 provided
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:69:12: note: candidate: size_t Print::print(unsigned char, int)
     size_t print(unsigned char, int = DEC);
            ^~~~~
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:69:12: note:   candidate expects 2 arguments, 3 provided
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:70:12: note: candidate: size_t Print::print(int, int)
     size_t print(int, int = DEC);
            ^~~~~
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:70:12: note:   candidate expects 2 arguments, 3 provided
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:71:12: note: candidate: size_t Print::print(unsigned int, int)
     size_t print(unsigned int, int = DEC);
            ^~~~~
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:71:12: note:   candidate expects 2 arguments, 3 provided
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:72:12: note: candidate: size_t Print::print(long int, int)
     size_t print(long, int = DEC);
            ^~~~~
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:72:12: note:   candidate expects 2 arguments, 3 provided
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:73:12: note: candidate: size_t Print::print(long unsigned int, int)
     size_t print(unsigned long, int = DEC);
            ^~~~~
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:73:12: note:   candidate expects 2 arguments, 3 provided
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:74:12: note: candidate: size_t Print::print(double, int)
     size_t print(double, int = 2);
            ^~~~~
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:74:12: note:   candidate expects 2 arguments, 3 provided
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:75:12: note: candidate: size_t Print::print(const Printable&)
     size_t print(const Printable&);
            ^~~~~
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:75:12: note:   candidate expects 1 argument, 3 provided
exit status 1
no matching function for call to 'HardwareSerial::print(int&, int&, int&)'

No, I meant can we have a link for the modified code that worked.

Code that doesn't compile cannot run, so cannot be said to "not work"

i had code that already did that and did not work for the output i wanted

int analogPin1 = A0;
int analogPin2 = A1;
int analogPin3 = A2;
int val = 0; 
int hal = 0;
int pal = 0;
void setup() {
  Serial.begin(9600);           
}

void loop() {
  val = analogRead(analogPin1);  
  Serial.println(val);          
 hal = analogRead(analogPin2); 
  Serial.println(hal);   
  pal = analogRead(analogPin3);  
  Serial.println(pal); }  

the reading of the other numbers acts as the delay I'm trying to display the three outputs in three different strings

println prints each value on a new line.
Try printing a space between values, using simply print

this is the modified code

int analogPin1 = A0;
int analogPin2 = A1;
int analogPin3 = A2;
int val = 0; 
int hal = 0;
int pal = 0;
void setup() {
  Serial.begin(9600);           
}

void loop() {
  val = analogRead(analogPin1);  
  Serial.println(val);          
 hal = analogRead(analogPin2); 
  Serial.println(hal);   
  pal = analogRead(analogPin3);  
  Serial.println(pal); }  

it runs on the version im runing

Great.

Please mark the topic "solved"

the code i refrenced dosen't work in that it displays in not the way i want it to

thanks for the help

See reply #13