def __init__(self, pwm0, pwm1, pwm2, pwm3): """ """ self.mux = MCP230XX(0x20, 16, 1) for pin in range(0, 15): self.mux.config(pin, OUT) # this can be: # BOARD -> Board numbering scheme. The pin numbers follow the pin numbers on header P1. # BCM -> Broadcom chip-specific pin numbers. # GPIO.setmode(GPIO.BCM) setmode(BCM) # Pi cover uses BCM pin numbers, GPIO.BCM = 11 setup([pwm0, pwm1, pwm2, pwm3], OUT) # GPIO.OUT = 0 freq = 100.0 # Hz self.motor0 = PWM(pwm0, freq) self.motor1 = PWM(pwm1, freq) self.motor2 = PWM(pwm2, freq) self.motor3 = PWM(pwm3, freq) self.motor0.start(0) self.motor1.start(0) self.motor2.start(0) self.motor3.start(0)
def __init__(self, controller, pwm_pin, dir_pin): self.MC = controller if (pwm_pin < 0) or (pwm_pin > 15): raise NameError('PWM pin must be between 0 and 15 inclusive') self.pwm_pin = pwm_pin self.dir_pin = dir_pin GPIO.setwarnings(False) setup(dir_pin, OUT)
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_sensor(): '''Setup the environment mode BCM using TRIGGER as output using ECHO as input ''' setmode(BCM) setup(PIN_TRIGGER, OUT) setup(PIN_ECHO, IN)
def __init__(self, controller, pwm_pin, sleep_pin, dir_pin): self.MC = controller if (pwm_pin < 0) or (pwm_pin > 15): raise NameError('PWM pin must be between 0 and 15 inclusive') self.pwm_pin = pwm_pin self.sleep_pin = sleep_pin setup(sleep_pin, OUT) self.dir_pin = dir_pin setup(dir_pin, OUT)
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_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 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)
def __init__(self): setmode(BCM) setup(ELEMENT_GPIO_PIN, OUT, initial=LOW)
from picamera import PiCamera from picamera.array import PiRGBArray from steering import turn, kill from RPi.GPIO import IN, setmode, setup, BCM, add_event_detect, BOTH, input from breaking import dobrake import threading #ser = Serial('/dev/ttyACM0', 115200) camera = PiCamera() stream = PiRGBArray(camera) brake_pin = 12 half = pi / 2 #braking = False mph = 0 setmode(BCM) setup(brake_pin, IN) #mh = Adafruit_MotorHAT() # throttle = mh.getStepper(200, 1) # 200 steps/rev, port (1 or 2) # throttle.setSpeed(40) # 40 RPM steps = 30 # def cruise(): # global steps # throttle.step(steps, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.DOUBLE) #Cruise Control: pulses throttle while speed <2 mph #thr = threading.Thread(target = cruise) braked = False
from RPi.GPIO import setup, OUT, PWM, output, LOW, HIGH, cleanup, setmode, BCM from wsgiref.simple_server import make_server from pyramid.config import Configurator from pyramid.response import Response __author__ = 'root' setmode(BCM) setup(17, OUT) setup(20, OUT) setup(22, OUT) setup(5, OUT) setup(6, OUT) setup(13, OUT) isForward = None isBackward = None def default_response(): return Response('<font size=400><center>' '<a href=/move/f>forward</a><br><br>' '<a href=/move/l>left</a> ' '<a href=/move/s>stop</a> ' '<a href=/move/r>right</a><br><br>' '<a href=/move/b>backward</a></center></font>') def right(duty=100): output(5, HIGH) output(6, LOW) p2.ChangeDutyCycle(float(duty))
def off(): setup(7, IN)
#!/usr/bin/env python import os from pytz import timezone from subprocess import Popen, PIPE from datetime import datetime from time import sleep, strftime from RPi.GPIO import BCM, IN, setup, setmode, input setmode(BCM) setup(18, IN) class Adafruit_CharLCD(object): # commands LCD_CLEARDISPLAY = 0x01 LCD_RETURNHOME = 0x02 LCD_ENTRYMODESET = 0x04 LCD_DISPLAYCONTROL = 0x08 LCD_CURSORSHIFT = 0x10 LCD_FUNCTIONSET = 0x20 LCD_SETCGRAMADDR = 0x40 LCD_SETDDRAMADDR = 0x80 # flags for display entry mode LCD_ENTRYRIGHT = 0x00 LCD_ENTRYLEFT = 0x02 LCD_ENTRYSHIFTINCREMENT = 0x01 LCD_ENTRYSHIFTDECREMENT = 0x00
from RPi.GPIO import setmode, setup, output, BCM, OUT, HIGH, LOW # imports functions from the RPi.GPIO library from time import sleep setmode(BCM) # pins are called by the number on the pi ledRED = 17 ledGREEN = 16 # red led = pin 17 # green led = pin 16 setup(ledRED, OUT) setup(ledGREEN, OUT) # sets led pins as outputs count = 0 # counter starts at 0 while count < 10: # until each led has blinked 10 times output(ledRED, HIGH) output(ledGREEN, LOW) # turns the red led on and green one off sleep(1) output(ledRED, LOW) output(ledGREEN, HIGH) # turns the red led off and green one on sleep(1) count = count + 1 # adds one to the counter
''' import RPi.GPIO from RPi.GPIO import cleanup from RPi.GPIO import output from RPi.GPIO import setup from RPi.GPIO import setmode from RPi.GPIO import BCM from RPi.GPIO import HIGH from RPi.GPIO import LOW from RPi.GPIO import OUT import time from time import sleep DELAY = 1 PIN_LED = 18 if __name__ == '__main__': setmode(BCM) setup(PIN_LED, OUT) while True: try: output(PIN_LED, HIGH) sleep(DELAY) output(PIN_LED, LOW) sleep(DELAY) except (KeyboardInterrupt, SystemExit) as e: cleanup()
from RPi.GPIO import setup, setmode, output, BCM, OUT, LOW, HIGH, setwarnings import json with open("/home/pi/TeerApp/TeerApp/config.json", 'r') as f: pins = json.load(f).values() setmode(BCM) setwarnings(False) setup(pins, OUT) output(pins, LOW)
def on(): setup(7, OUT) output(7, True)
def __init__(self): setmode(BCM) setup(STATUS_GPIO_PIN, OUT, initial=LOW)
def getRequestedTemp(): return (json.loads(urlopen(Request(requestedTemperature, **requestOpts)).read().decode("utf-8")))["tempF"] def setRequestedTemp(f): urlopen( Request(url=requestedTemperature, method="PUT", data=json.dumps({"tempF": f}).encode("utf-8"), **requestOpts) ) PIN_KNOB_A = 1 PIN_KNOB_B = 4 PIN_BUTTON = 0 setmode(BCM) setup(PIN_KNOB_A, IN, PUD_UP) setup(PIN_KNOB_B, IN, PUD_UP) setup(PIN_BUTTON, IN, PUD_UP) print("reading knob and button, writing to %s" % requestedTemperature) prev = None prevButton = 0 buttonHold = 0 step = 0.02 while True: a, b = pinInput(PIN_KNOB_A), pinInput(PIN_KNOB_B) button = not pinInput(PIN_BUTTON) pos = (b * 2) + (a ^ b) if prev is None: prev = pos
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)
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)
import requests import json from RPi.GPIO import setmode, IN, OUT, BCM, setup, add_event_detect, RISING import pygame setmode(BCM) PLAYER1_CHANNEL = 18 PLAYER2_CHANNEL = 4 BUTTON_COOLDOWN = 1200 setup(PLAYER1_CHANNEL, IN) setup(PLAYER2_CHANNEL, IN) pygame.mixer.init() sound = pygame.mixer.Sound('ping.ogg') def player_scored(player_number): print("Player {} scored!".format(player_number)) requests.post( 'http://localhost:3000/scores', data=json.dumps({'player': player_number}), headers={'content-type': 'application/json'} ) sound.play() add_event_detect(PLAYER1_CHANNEL, RISING, callback=lambda _: player_scored(1), bouncetime=BUTTON_COOLDOWN) add_event_detect(PLAYER2_CHANNEL, RISING, callback=lambda _: player_scored(2), bouncetime=BUTTON_COOLDOWN)
from RPi.GPIO import cleanup, setmode, setup, output, BOARD, OUT from time import sleep setmode(BOARD) setup(7, OUT) def on(): output(7, True) def off(): output(7, False) def blink(n=5, s=.5): for i in range(n): on() sleep(s) off() sleep(s) To_Morse = dict({"A": ".-", "B": "-...", "C": "-.-.", "D": "-..", "E": ".", "F": "..-.", "G": "--.", "H": "....", "I": "..", "J": ".---", "K": "-.-", "L": ".-..", "M": "--", "N": "-.", "O": "---", "P": ".--.", "Q": "--.-", "R": ".-.", "S": "...", "T": "-", "U": "..-", "V": "...-", "W": ".--", "X": "-..-", "Y": "-.--", "Z": "--..", "1": ".----", "2": "..---", "3": "...--", "4": "....-", "5": "-....", "6": "--...", "7": "---..", "8": "----.", "9": "----.", "0": "-----"}) def getMorse(inputText): nuString = "" for i in inputText: if i == " ": nuString = nuString + To_Morse[i.upper()] + "|" else: nuString = nuString + " " return nuString def parseOneZero(string): pass
def __init__(self): """Initialise GPIO pins.""" setmode(BOARD) setup(ULN2003.OUTPUT_PINS, OUT, initial=LOW)
def __init_rasp_config (self) : setmode (BCM) setup (PIN_SIG, OUT) output (PIN_SIG, LOW)