lib Modulove
Library for building custom scripts for Modulove modules.
Loading...
Searching...
No Matches
digital_input.h
Go to the documentation of this file.
1
11#ifndef DIGITAL_INPUT_H
12#define DIGITAL_INPUT_H
13
14#include <Arduino.h>
15
16namespace modulove {
17
19 public:
22 STATE_UNCHANGED,
23 STATE_RISING,
24 STATE_FALLING,
25 };
26
27 DigitalInput() {}
28 ~DigitalInput() {}
29
35 void Init(uint8_t cv_pin) {
36 pinMode(cv_pin, INPUT);
37 cv_pin_ = cv_pin;
38 }
39
44 void Process() {
45 old_read_ = read_;
46 read_ = digitalRead(cv_pin_);
47
48 // Determine current clock input state.
49 state_ = STATE_UNCHANGED;
50 if (old_read_ == 0 && read_ == 1) {
51 state_ = STATE_RISING;
52 on_ = true;
53 } else if (old_read_ == 1 && read_ == 0) {
54 state_ = STATE_FALLING;
55 on_ = false;
56 }
57 }
58
64 inline InputState State() { return state_; }
65
72 inline bool On() { return on_; }
73
80 inline bool Read() { return digitalRead(cv_pin_); }
81
82 private:
83 uint8_t cv_pin_;
84 uint8_t read_;
85 uint8_t old_read_;
86 InputState state_;
87 bool on_;
88};
89
90} // namespace modulove
91
92#endif
Definition digital_input.h:18
InputState State()
Get the current input state of the digital input.
Definition digital_input.h:64
void Init(uint8_t cv_pin)
Initializes a CV Input object.
Definition digital_input.h:35
InputState
Enum constants for clk input rising/falling state.
Definition digital_input.h:21
bool On()
Current cv state represented as a bool.
Definition digital_input.h:72
bool Read()
Read live pin state as a bool.
Definition digital_input.h:80
void Process()
Read the state of the cv input.
Definition digital_input.h:44