-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputs.py
38 lines (27 loc) · 1.33 KB
/
inputs.py
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
import digitalio
import analogio
import extramath as umath
class sw: #confirmed as fully working
def __init__(self, pin): #pin must be board.GP##
self.sw = digitalio.DigitalInOut(pin)
self.sw.switch_to_input(pull=digitalio.Pull.DOWN)
def read(self):
return self.sw.value
class pot: #IN TESTING PROCESS - NONFUNCTIONAL
def __init__(self, pin, trim_min=0, trim_max=65535): #pin must be board.GP##
self.trim_min = trim_min
self.trim_max = trim_max
self.pot = analogio.AnalogIn(pin)
self.applyTrim = lambda inputVal: umath.Map(inputVal, self.trim_min, self.trim_max, 0, 65535)
self.clamp_u16 = lambda inputVal: umath.clamp(inputVal, 0, 65535)
def read_u16(self):
return self.clamp_u16(self.applyTrim(self.pot.value))
def percent(self, rounding=False):
self.value = umath.clamp(umath.Map(self.pot.value, self.trim_min, self.trim_max, 0, 100), 0, 100)
if rounding:
self.value = round(self.value)
return self.value
def unitInterval(self):
return umath.clamp(umath.Map(self.pot.value, self.trim_min, self.trim_max, 0, 1), 0, 1)
def joy(self):
return umath.clamp(umath.Map(self.pot.value, self.trim_min, self.trim_max, 0, 2) - 1, -1, 1)