Help needed with simple sketch

Here is the sketch:

// compiles OK with IDE 1.8.12, but does not work with ESP32 dev board (set to defaults) or with a UNO
// expected to print "Send lower case a, b,c,...m" to serial monitor using function in the loop
void setup() // ******************************************************* start of setup
{
  Serial.begin(9600); // does not work at other baud rates or other serial ports or serial cables
  Serial.println("ready"); // just to let humans know that * something * has happened
  //Serial.println("Send lower case a, b,c,...m"); // prints as expected here
}
void loop() // ******************************************************* start of loop
{
  test;
}

void test()  // changing the name does not change the outcome
{
  Serial.println("Send lower case a, b,c,...m"); // sometimes prints ?⸮V⸮⸮5 or usually prints nothing
  Serial.print("print"); // prints nothing
  //Serial.write("write"); // compile error  processing.app.SerialException: Error opening serial port 'COM6'
  delay(500);  // various delays do not change the outcome - nothing printed in the loop
}

Any and all help or suggestions are appreciated, thanks.

void loop() // ******************************************************* start of loop
{
  test(); // brackets are important!
}

This is what I get when I compile your sketch for a Nano.

C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_627208\sketch_apr08a.ino: In function 'void loop()':

C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_627208\sketch_apr08a.ino:11:7: warning: statement is a reference, not call, to function 'test' [-Waddress]

   test;

       ^

C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_627208\sketch_apr08a.ino:11:7: warning: statement has no effect [-Wunused-value]

So it does not compile OK :wink:

Change your loop() to

void loop() // ******************************************************* start of loop
{
  test();
}

To see the warnings as I got them, go to file -> preferences and set compiler warnings to all and compile again.

Thanks to all of the above.
Brackets are indeed important !!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.