updated locations and started documenting classes.
This commit is contained in:
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
@@ -0,0 +1,17 @@
|
|||||||
|
### Buzzer class
|
||||||
|
To give a demonstration on how classes in c++/arduino work, i decided to code something easy 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 is done by using private variables and public functions that call to the private variables.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
In this case the buzzer pin and Button pin are given with the new object.
|
||||||
|
|
||||||
|
This class uses public and private acces keys.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
@@ -0,0 +1,30 @@
|
|||||||
|
class BuzzerPin{
|
||||||
|
private:
|
||||||
|
int buzzerPin;
|
||||||
|
int button;
|
||||||
|
public:
|
||||||
|
BuzzerPin(int bp, int but){
|
||||||
|
buzzerPin = bp;
|
||||||
|
button = but;
|
||||||
|
pinMode(button, INPUT);
|
||||||
|
pinMode(buzzerPin, OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void activate(){
|
||||||
|
if(digitalRead(button) == HIGH){
|
||||||
|
digitalWrite(buzzerPin, HIGH);
|
||||||
|
}else{
|
||||||
|
digitalWrite(buzzerPin, LOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BuzzerPin buzzerOne(12, 20);
|
||||||
|
|
||||||
|
void setup(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
buzzerOne.activate();
|
||||||
|
}
|
Reference in New Issue
Block a user