def setup_gpio(): setmode(BCM) setwarnings(False) for led in LEDS: setup(led, OUT) setup(BUTTON, IN, pull_up_down=PUD_UP) cleanup()
def setup_env() : '''set up the PINs Disabble warnings in case of pins already in use due to another program before ''' setwarnings (False) setmode (BCM) setup (PIN_LED, OUT) setup (PIN_TRIGGER, OUT) setup (PIN_ECHO, IN )
def setup_gpio(): setmode(BCM) setwarnings(False) for led in TOP_ROW + MIDDLE_ROW + BOTTOM_ROW: setup(led, OUT) setup(TOP_ADD_BUTTON, IN, pull_up_down=PUD_UP) setup(TOP_SUB_BUTTON, IN, pull_up_down=PUD_UP) setup(BOT_ADD_BUTTON, IN, pull_up_down=PUD_UP) setup(BOT_SUB_BUTTON, IN, pull_up_down=PUD_UP) cleanup()
def __init__(self, gpio, active=True, direction="OUT", state="LOW"): directions = {"IN": IN, "OUT": OUT} states = {"LOW": self.low, "HIGH": self.high} assert isinstance(gpio, int), gpio assert isinstance(active, bool), active assert direction in directions, direction assert state in states, state self.gpio = gpio self.active = active setwarnings(False) setmode(BCM) setup(self.gpio, directions[direction]) states[state]()
def setup_gpio(): setmode(BCM) setwarnings(False) for led in BIT_LEDS + [ONE_HUNDRED_LED, TWO_HUNDRED_LED]: setup(led, OUT) for segment in LSD + MSD: setup(segment, OUT) setup(BEEPER, OUT) setup(BUTTON, IN, pull_up_down=PUD_UP) cleanup() for segment in [0, 1, 2, 3, 4, 5]: output(LSD[segment], HIGH) output(MSD[segment], HIGH)
from RPi.GPIO import setmode, setwarnings, setup, output, BCM, HIGH, LOW, OUT, cleanup from time import sleep pins = [17, 27, 22, 23] setmode(BCM) setwarnings(False) for i in pins: setup(i, OUT) output(i, 0) c = [ [1,0,0,0], [1,1,0,0], [0,1,0,0], [0,1,1,0], [0,0,1,0], [0,0,1,1], [0,0,0,1], [1,0,0,1] ] for i in range(512): for i in range(8): for j in range(4): output(pins[j], c[i][j]) sleep(0.01)
from RPi.GPIO import cleanup, setmode, setup, output, BOARD, OUT, IN, setwarnings from time import sleep setmode(BOARD) setwarnings(False) setup(7, IN) def on(): setup(7, OUT) output(7, True) def off(): setup(7, IN) def blink(n = 5, s = .1): for i in range(n): on() sleep(s) off() sleep(s)