-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpin.py
36 lines (29 loc) · 801 Bytes
/
pin.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
import os
if os.getenv("GAME_ENV") == "dev":
import gpio_mock as GPIO
else:
from RPi import GPIO
from enum import Enum
class PinNumbering(Enum):
BCM = GPIO.BCM
BOARD = GPIO.BOARD
class PinMode(Enum):
OUT = GPIO.OUT
IN = GPIO.IN
class Pin:
@classmethod
def setmode(cls, mode:PinNumbering):
if mode == PinNumbering.BCM:
GPIO.setmode(GPIO.BCM)
else:
GPIO.setmode(GPIO.BOARD)
def __init__(self, number:int, mode:PinMode):
self.number = number
if mode == PinMode.OUT:
GPIO.setup(self.number, GPIO.OUT)
else:
GPIO.setup(self.number, GPIO.IN)
def high(self):
GPIO.output(self.number, GPIO.HIGH)
def low(self):
GPIO.output(self.number, GPIO.LOW)