class documentation updated

This commit is contained in:
Bram Barbieri
2024-04-05 00:48:13 +02:00
parent 1d538bd3df
commit 44b16c168d

View File

@@ -1,17 +1,27 @@
### Buzzer class
To give a demonstration on how classes in c++/arduino work, i decided to code something easy and repeatable.
To provide a demonstration of how classes work in C++/Arduino, I decided to code something simple and repeatable.
This class is meant to assign a input and and output source for a button to activate a buzzer, and a buzzer to be activated by a button.
This class is intended to assign an input and output source for a button to activate a buzzer, and for a buzzer to be activated by a button. This is achieved by using private variables and public functions that access these variables.
This is done by using private variables and public functions that call to the private variables.
This class code allows the user to easily add new buzzers by simply creating an object and calling the appropriate function.
Inside of the class a constructor is made.
(in c++ this is the name of the class itself.)
every time the class is called uppon, the consctructor gets activated with the given data.
##### constructor
Inside the class, a constructor is defined. In C++, this constructor shares the same name as the class itself. Every time the class is called, the constructor is activated with the given data.
In this case the buzzer pin and Button pin are given with the new object.
##### Class functions
Within a class, functions can be defined. These functions can interact with the variables made inside the class. These functions can then be called outside the class to execute their action.
This class uses public and private acces keys.
In this case, the "activation" function is defined within the class and is used in the loop function. This function contains the if-statement that determines if the button is pressed and activates the buzzer pin accordingly.
##### Object Creation
After defining the class, an object needs to be made. This object will immediately trigger the constructor and ask for input variables. These given data points will be inserted into the private variables.
In this instance, the buzzer pin is set to 12 and the button pin to 20.
##### using the class
In the loop function, the new object is placed along with the function defined in the class to activate it. This function executes with the variable data provided in the constructor. Here, it checks if the specified pin is receiving a signal and then only outputs a signal to the buzzer when there is one.
##### Link to code
(https://gitlab.fdmci.hva.nl/propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-3/qaajeeqiinii59/-/blob/main/docs/LearningProcessBram/ArduinoExperience/classesArduino/buzzerclasses.ino?ref_type=heads)
The variables to determine the pins are st to private so these can't be alterd by any other means besides the ones assigned to it.