Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Variable not recognized in Arduino IDE

I get expected initializer before ‘myString’ even I defined it in setup

void setup() {
  // put your setup code here, to run once:
  String myString
}

void loop() 
  myString = "Hello"

  print myString + " World"
}

I don’t know what to try.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The variable myString is declared inside of the setup function, and when that function ends, the variable no longer ‘exists’ so to speak. it is ‘out of scope’ as the other commenter says.

You can either choose to declare it outside of any functions, (preferably near the top of the file), in the so called ‘global scope’, or inside the loop function, so called ‘local scope’.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading