GMU:Functions and Classes (Arduino): Difference between revisions

From Medien Wiki
Line 117: Line 117:
We can improve our program structure by putting classes in separate files:
We can improve our program structure by putting classes in separate files:


:1.
:Click on the arrow in the right corner in order to add a new file.
:Select „new Tab“.


:[[File:NewTabARDU.jpg]]
1.
Click on the arrow in the right corner in order to add a new file.
Select „new Tab“.


:2.
[[File:NewTabARDU.jpg]]
:Enter a filename at the bottom of the window.
:It must end with .h – In our case it could be 'motorControl.h'.


:3.
2.
:The first line of your code should be:
Enter a filename at the bottom of the window.
It must end with .h – In our case it could be 'motorControl.h'.


:'#include „Arduino.h“'
3.
The first line of your code should be:


:This line 'links' the file to the Arduino–specific features.
'#include „Arduino.h“'
:Now we can include the code of our class.


:4.
This line 'links' the file to the Arduino–specific features.
:Go back to your main file.
Now we can include the code of our class.
:Now you have to 'link' the new file to your main file in order to use the features of our class.
:Include the following line in the top of your main file


:'#include "MotorControl.h“'
4.
Go back to your main file.
Now you have to 'link' the new file to your main file in order to use the features of our class.
Include the following line in the top of your main file


:and write the rest of your program as usual.
'#include "MotorControl.h“'
 
and write the rest of your program as usual.
<br>
<br>