Rename module from motor_passo to spectrometer

This commit is contained in:
2023-10-29 20:56:03 -03:00
parent 02051ebda7
commit 00633508f0
15 changed files with 11 additions and 11 deletions

35
spectrometer/encoder.py Normal file
View File

@@ -0,0 +1,35 @@
import RPi.GPIO as gpio
from dataclasses import dataclass
@dataclass
class Encoder:
pin_a: int
pin_b: int
_curr_steps: int = 0
def setup(self):
if not gpio.getmode():
gpio.setmode(gpio.BCM)
gpio.setup(self.pin_a, gpio.IN)
gpio.setup(self.pin_b, gpio.IN)
gpio.add_event_detect(self.pin_a,
gpio.RISING,
callback=self._event_detect)
gpio.add_event_detect(self.pin_b,
gpio.RISING,
callback=self._event_detect)
def _event_detect(self, pin):
a = gpio.input(self.pin_a)
b = gpio.input(self.pin_b)
if a ^ b:
self._curr_steps += 1 if a else -1
@property
def angle(self) -> float:
return self._curr_steps / 5000 * 360