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

From Medien Wiki
Line 115: Line 115:
==Organizing classes in separate files==
==Organizing classes in separate files==


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“.


----BILD----
: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 I suggest the name motorControl.h.


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


:3.
:The first line of your code should be:


''
:'#include „Arduino.h“'
#include „Arduino.h“
''


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


This line „links“ the file to the Arduino-specific features.
:4.
Now we can include the code of our class.
: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.
4)
:Include the following line in the top of your main file
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
 
 
''
#include „MotorControl.h“
''
 
 
and write the rest of your program as usual.


:'#include "MotorControl.h“'


:and write the rest of your program as usual.


==More details on the concept==
==More details on the concept==