VLCB
Loading...
Searching...
No Matches
Switch.h
Go to the documentation of this file.
1// Copyright (C) Sven Rosvall (sven@rosvall.ie)
2// This file is part of VLCB-Arduino project on https://github.com/SvenRosvall/VLCB-Arduino
3// Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
4// The full licence can be found at: http://creativecommons.org/licenses/by-nc-sa/4.0/
5
6#pragma once
7
8#ifndef DEBUG_SERIAL
9#define DEBUG_SERIAL Serial
10#endif
11
12#include <Arduino.h> // for definition of byte datatype
13
14namespace VLCB
15{
16
17// non-blocking switch class
18
19class Switch
20{
21public:
22 explicit Switch(byte pin, byte pressedState = LOW);
23 Switch();
24 void setPin(byte pin, byte mode);
25 void run();
26 void reset();
27 bool stateChanged();
28 bool getState();
29 bool isPressed();
30 unsigned long getCurrentStateDuration();
31 unsigned long getLastStateDuration();
32 unsigned long getLastStateChangeTime();
34
35protected:
36 byte readPin();
37 byte _pin;
42 unsigned long _lastStateChangeTime;
43 unsigned long _lastStateDuration;
44 unsigned long _prevReleaseTime;
45 unsigned long _prevStateDuration;
46};
47
48}
bool stateChanged()
Definition Switch.cpp:105
unsigned long _lastStateChangeTime
Definition Switch.h:42
unsigned long getCurrentStateDuration()
Definition Switch.cpp:126
void setPin(byte pin, byte mode)
Definition Switch.cpp:31
unsigned long _lastStateDuration
Definition Switch.h:43
Switch()
a class to encapsulate a physical pushbutton switch, with non-blocking processing
Definition Switch.cpp:15
void run()
Definition Switch.cpp:60
byte _pressedState
Definition Switch.h:38
void resetCurrentDuration()
Definition Switch.cpp:147
bool isPressed()
Definition Switch.cpp:119
byte _lastState
Definition Switch.h:40
bool getState()
Definition Switch.cpp:112
Switch(byte pin, byte pressedState=LOW)
Definition Switch.cpp:19
byte _stateChanged
Definition Switch.h:41
unsigned long _prevStateDuration
Definition Switch.h:45
byte _pin
Definition Switch.h:37
unsigned long getLastStateDuration()
Definition Switch.cpp:133
byte _currentState
Definition Switch.h:39
unsigned long getLastStateChangeTime()
Definition Switch.cpp:140
byte readPin()
Definition Switch.cpp:55
unsigned long _prevReleaseTime
Definition Switch.h:44
void reset()
Definition Switch.cpp:45
Definition AbstractEventTeachingService.cpp:13