SE-TP2/code/Barrier.cpp

45 lines
837 B
C++

#include <Servo.h>
enum BarrierState {OPEN, CLOSED};
class Barrier {
private:
Servo servo;
int pin;
BarrierState state = CLOSED;
public:
int open_time_seconds;
Barrier(int pin, int open_time_seconds = 3){
this->pin = pin;
this->close();
this->open_time_seconds = open_time_seconds;
}
void configure_pins(){
this->servo.attach(pin);
}
void open(){
this->state = OPEN;
this->servo.write(0);
}
void close(){
this->state = CLOSED;
this->servo.write(90);
}
bool is_open() const {
return this->state == OPEN;
}
bool is_closed() const {
return this->state == CLOSED;
}
};