I've been programming microcontrolers with C language but I am new to Arduino.
Using the example codes I notice that there is no main function, only setup and loop...
Also, I've tried to create a variable inside the loop function, but the program didn't behave the way I expected. Although I didn't get any error message. I only worked when I put the variable outside the functions, making it a global variable.
Also, I've tried to create a variable inside the loop function, but the program didn't behave the way I expected. Although I didn't get any error message. I only worked when I put the variable outside the functions, making it a global variable.
CarlosEC:
Also, I've tried to create a variable inside the loop function, but the program didn't behave the way I expected. Although I didn't get any error message. I only worked when I put the variable outside the functions, making it a global variable.
CarlosEC:
I've been programming microcontrolers with C language but I am new to Arduino.
Using the example codes I notice that there is no main function, only setup and loop...
The "main()" function is in the Arduino core library.
So it is invisible, if you do not look up the source code of the core library.
But if you like, you can write your own "main()" function in an Arduino sketch and this will compile.
CarlosEC:
Also, I've tried to create a variable inside the loop function, but the program didn't behave the way I expected. Although I didn't get any error message.
The Arduino IDE shows no compiler "warnings", but only "errors". So everything you program that normally would show up a "warning" will show nothing at all in the Arduino IDE.
Variables declared outside of functions are "global" and variables declared inside of functions are "local". Nothing else as with plain C.
main() is omitted (actually, hidden away in the core) and replaced with setup()/loop() to emphasize some of the differences between programming a microcontroller and programming a more traditional computer. (In particular, loop() runs over and over again, so you don't have to explain what happens when main() exits.)