-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputs.h
115 lines (93 loc) · 2.05 KB
/
inputs.h
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef INPUTS_H
#define INPUTS_H
#include <pico/stdlib.h>
#include <hardware/adc.h>
#include "util.h"
#define FREQ_PIN 27
#define DUTY_PIN 26
#define SEL_PIN 28
#define SCROLL_PIN 29
class Inputs
{
private:
int selState = 0;
int scrollState = 0;
int lastSelState = 0;
int lastScrollState = 0;
int selReading = 0;
int scrollReading = 0;
unsigned long last_sel_debounce_time = 0;
unsigned long last_scroll_debounce_time = 0;
unsigned long debounce_delay = 50;
public:
void init_pots();
void init_buttons();
uint16_t read_dutycycle();
uint16_t read_frequency();
bool select();
bool scroll();
void updateButtons();
};
void Inputs::init_pots()
{
adc_init();
adc_gpio_init(FREQ_PIN);
adc_gpio_init(DUTY_PIN);
}
void Inputs::init_buttons()
{
gpio_init(SEL_PIN);
gpio_init(SCROLL_PIN);
gpio_set_dir(SEL_PIN, GPIO_IN);
gpio_set_dir(SCROLL_PIN, GPIO_IN);
}
uint16_t Inputs::read_dutycycle()
{
adc_select_input(0);
uint16_t output = adc_read();
return output;
}
uint16_t Inputs::read_frequency()
{
adc_select_input(1);
uint16_t output = adc_read();
return output;
}
bool Inputs::select()
{
selReading = gpio_get(SEL_PIN);
if (selReading != lastSelState)
last_sel_debounce_time = millis();
if ((millis() - last_sel_debounce_time) > debounce_delay)
{
if (selReading != selState)
{
selState = selReading;
if (selState == 0)
return true;
}
}
return false;
}
bool Inputs::scroll()
{
scrollReading = gpio_get(SCROLL_PIN);
if (scrollReading != lastScrollState)
last_scroll_debounce_time = millis();
if ((millis() - last_scroll_debounce_time) > debounce_delay)
{
if (scrollReading != scrollState)
{
scrollState = scrollReading;
if (scrollState == 0)
return true;
}
}
return false;
}
void Inputs::updateButtons()
{
lastScrollState = scrollReading;
lastSelState = selReading;
}
#endif