I have a local variable named "loopInterval" used only at two places in my programm. (see below)
As long as I need to modify the variable elsewhere, I moved it at the beginning of my sketch in order to make it global.
Well, just "moving" this declaration makes my sketch not to run anymore… (or very randomnly)
Did I do anything wrong ?
The total sketch is in in attachment,
I did my best (as a begginer) and I would be SO happy if any of you could give m some advices about this code.
I also got the feeling my sketch comes instable (after beeing uploaded) when it reaches the 17k (out of 32 available).
Sometimes simply adding a char to a String makes it (un)able to run again…
ex :
zeClient.println("Got :"+url); NOT OK
zeClient.println("Got_ :"+url); OK ! (just added an "_")
What is the purpose of initializing url to "100"? Of initializing ledMode to "20"?
Serial.println("interupt");
You should NOT be calling Serial.print() in an interrupt service routine. Interrupts are disabled while the ISR is running, and Serial.print() needs interrupts functioning in order to work.
Well, just "moving" this declaration makes my sketch not to run anymore… (or very randomnly)
Did I do anything wrong ?
The first part is hard to believe. The answer to the question is yes. Several things, in fact. The first was to not remove all local variables of the same name. The second was to change the type of the global variable.
Having local variables and global variables of the same name is a recipe for disaster. Having local and global variables of the same name but different types is just plain stupid.
So when you declare a String, yo do not need to specify any length, right ?
String url String();
url = "abcdef";
Interruptions : OK, got it. I wont use serial.println anymore in this particular case !
Moved variable : Sorry the code I zipped was not the one I was using,
The variable was moved (CUT-Pasted, not Copy-Pasted)… So it was really unique (and global).
And I did change the type "int" to "unsigned long" just to be sure I could write :
(because the other variables were "unsigned long", but I guess "int" would work to right ?)
Having local variables and global variables of the same name is a recipe for disaster. Having local and global variables of the same name but different types is just plain stupid.
Agree that same names with or without different types is not a good idea. Whether or not it is "stupid" depends a lot on the experience of the programmer. Referring to something a beginner does as stupid is neither productive nor helpful..
If you're ok, i'll post the next version so you can have a look at it…
You need to post it, with more details about what "it doesn't work" means. The code does something. Describe what it does. You want it to do something (presumably different). Describe what that is.