-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPIOManager.cpp
More file actions
42 lines (36 loc) · 1.06 KB
/
Copy pathGPIOManager.cpp
File metadata and controls
42 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "GPIOManager.h"
GPIOManager::GPIOManager(int buttonPin)
// : buttonPin(buttonPin), buttonPressed(false)
{
this->buttonPin = buttonPin;
buttonPressed = false;
}
void GPIOManager::setup()
{
pinMode(buttonPin, INPUT_PULLUP);
pinMode(switchPin, OUTPUT);
pinMode(boostPin, OUTPUT);
digitalWrite(switchPin, LOW);
digitalWrite(boostPin, HIGH);
}
void GPIOManager::checkButtonStatus()
{
// read the state of the button
int buttonState = digitalRead(buttonPin);
// if the button is pressed and the flag is not set
if (buttonState == LOW && !buttonPressed) {
buttonPressed = true; // set the flag
// do something here (e.g. turn on an LED, send a message)
Serial.printf("Button Pressed \n");
digitalWrite(switchPin, LOW);
}
// if the button is not pressed and the flag is set
else if (buttonState == HIGH && buttonPressed) {
buttonPressed = false; // clear the flag
digitalWrite(switchPin, HIGH);
}
}
bool GPIOManager::getButtonPressed()
{
return buttonPressed;
}