本文整理汇总了Python中wiringpi.pinMode函数的典型用法代码示例。如果您正苦于以下问题:Python pinMode函数的具体用法?Python pinMode怎么用?Python pinMode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pinMode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configureHardware
def configureHardware(postMotionEvent, postButtonClickEvent):
wiringpi.wiringPiSetupGpio()
# PIR motion detector
def reportMotion():
if wiringpi.digitalRead(BCM_PIR) == 1:
postMotionEvent()
wiringpi.pinMode(BCM_PIR, wiringpi.GPIO.INPUT)
wiringpi.pullUpDnControl(BCM_PIR, wiringpi.GPIO.PUD_OFF)
wiringpi.wiringPiISR(BCM_PIR, wiringpi.GPIO.INT_EDGE_BOTH, reportMotion)
# Display buttons
for btnNum, bcmPin in (
(1, BCM_BTN_1),
(2, BCM_BTN_2),
(3, BCM_BTN_3),
):
@debounce(0.02)
def reportClick(_bcmPin=bcmPin, _btnNum=btnNum):
if wiringpi.digitalRead(_bcmPin) == 0:
postButtonClickEvent(_btnNum)
wiringpi.pinMode(bcmPin, wiringpi.GPIO.INPUT)
wiringpi.pullUpDnControl(bcmPin, wiringpi.GPIO.PUD_UP)
wiringpi.wiringPiISR(bcmPin, wiringpi.GPIO.INT_EDGE_BOTH, reportClick)
# Servos
wiringpi.pinMode(BCM_SERVO_ACTIVATION, wiringpi.GPIO.OUTPUT)
wiringpi.pinMode(BCM_SERVO_SPRING, wiringpi.GPIO.OUTPUT)
wiringpi.pinMode(BCM_SERVO_HOLDER, wiringpi.GPIO.OUTPUT)
示例2: scanQ
def scanQ(self):
# steps (1) and (2) before reading GPIOs
self.__preRead()
# (3) scan rows for pushed key/button
rowHi=1
while rowHi==1:
for i in range(len(self.row)):
tmpRead=wiringpi.digitalRead(self.row[i])
if tmpRead==0:
rowHi=0
rowVal=i
# (4) after finding which key/button from the row scans, convert columns to input
for j in range(len(self.col)):
wiringpi.pinMode(self.col[j],INPUT)
# (5) switch the i-th row found from scan to output
wiringpi.pinMode(self.row[rowVal],OUTPUT)
wiringpi.digitalWrite(self.row[rowVal],HIGH)
# (6) scan columns for still-pushed key/button
colLo=0
while colLo==0:
for j in range(len(self.col)):
tmpRead=wiringpi.digitalRead(self.col[j])
if tmpRead==1:
colLo=1
colVal=j
# reinitialize used GPIOs
self.__postRead()
# (7) return the symbol of pressed key from keyPad mapping
return self.keyPad[rowVal][colVal]
示例3: _switch
def _switch(self, switch):
self.bit = [142, 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, 136, 128, 0, 0, 0]
for t in range(5):
if self.system_code[t]:
self.bit[t] = 136
x = 1
for i in range(1, 6):
if self.unit_code & x > 0:
self.bit[4 + i] = 136
x = x << 1
if switch == wiringpi.HIGH:
self.bit[10] = 136
self.bit[11] = 142
bangs = []
for y in range(16):
x = 128
for i in range(1, 9):
b = (self.bit[y] & x > 0) and wiringpi.HIGH or wiringpi.LOW
bangs.append(b)
x = x >> 1
wiringpi.wiringPiSetupSys()
wiringpi.pinMode(self.pin, wiringpi.OUTPUT)
wiringpi.digitalWrite(self.pin, wiringpi.LOW)
for z in range(self.repeat):
for b in bangs:
wiringpi.digitalWrite(self.pin, b)
time.sleep(self.pulselength / 1000000.0)
示例4: main
def main():
delay = 1E-2 # seconds
# set up pins
wiringpi.wiringPiSetup()
for pin in pinsA:
wiringpi.pinMode( pin, 1 )
for pin in pinsB:
wiringpi.pinMode( pin, 1 )
for pin in pinsOut:
wiringpi.pinMode( pin, 0 )
wiringpi.pinMode( isSignedPin, 1 )
wiringpi.pinMode( isSupportedPin, 0 )
numFails = testUnsigned(delay)
numFails += testSigned(delay)
# magic for coloured printing from https://pythonadventures.wordpress.com/2011/03/16/print-colored-text-in-terminal/
colorred = "\033[01;31m{0}\033[00m"
colorgrn = "\033[1;36m{0}\033[00m"
if numFails > 0:
print colorred.format("%d tests were failed" % numFails)
else:
print colorgrn.format("All tests passed")
示例5: __init__
def __init__(self, dev=(0,0),speed=5000000, brightness=256, contrast=CONTRAST):
self.spi = spidev.SpiDev()
self.speed = speed
self.dev = dev
self.spi.open(self.dev[0],self.dev[1])
self.spi.max_speed_hz=self.speed
# Set pin directions.
self.dc = DC
self.rst = RST
wiringpi.wiringPiSetup()
for pin in [self.dc, self.rst]:
# pin=self.dc
wiringpi.pinMode(pin, 1)
self.contrast=contrast
self.brightness=brightness
# Toggle RST low to reset.
wiringpi.digitalWrite(self.rst, OFF)
time.sleep(0.100)
wiringpi.digitalWrite(self.rst, ON)
# Extended mode, bias, vop, basic mode, non-inverted display.
wiringpi.digitalWrite(self.dc, OFF)
self.spi.writebytes([0x21, 0x14, self.contrast, 0x20, 0x0c])
示例6: fan
def fan(self, status, waitTime=0):
time.sleep(waitTime)
if status:
wiringpi.pinMode(PIN_FAN, ON)
else:
wiringpi.pinMode(PIN_FAN, OFF)
示例7: __init__
def __init__(self):
threading.Thread.__init__(self)
self.watchdog = Watchdog()
self.watchdog.daemon = True
self.watchdog.start()
time.sleep(1)
self.setup = settings.setup
self.quit = False
for i in range(0, 7): #Set GPIO pins to output
wp.pinMode(i, 1)
self.setup = settings.setup
self.dutycycles = [0, 0, 0, 0, 0, 0]
channels = ['1', '2', '3', '4', '5', '6']
# Setup up extra status for the diode relay status
diode_channels = ['diode' + number for number in channels]
self.diode_channel_last = {name: None for name in diode_channels}
# Setup sockets
self.livesocket = LiveSocket(self.setup + '-bakeout', channels + diode_channels)
self.livesocket.start()
self.pullsocket = DateDataPullSocket(self.setup + '-bakeout', channels, timeouts=None)
self.pullsocket.start()
self.pushsocket = DataPushSocket(self.setup + '-push_control', action='enqueue')
self.pushsocket.start()
示例8: main
def main():
#all needs to run automatically
port0 = '/dev/ttyUSB0'
port1 = '/dev/ttyUSB1'
port2 = '/dev/ttyUSB2'
##
th_cl1 = TestThread(port1, './original_data/data1208.csv')
th_cl1 = TestThread(port1, './original_data/data1208.csv')
#th_cl1.start()
#th_cl2.start()
f = open('./original_data/data1209.csv', 'w')
##
servo_pin = 18
param = sys.argv
set_degree = int(param[1])
print(set_degree)
wiringpi.wiringPiSetupGpio()
wiringpi.pinMode(servo_pin, 2)
wiringpi.pwmSetMode(0)
wiringpi.pwmSetRange(1024)
wiringpi.pwmSetClock(375)
while True:
try:
ser = serial.Serial(port0, 38400, timeout=10) # 10s-timeout baudrate=38400
ser.write(b'<RM,>??\r\n') # send command (CR+LF)
line = ser.readline()
line = str(datetime.datetime.now()) + str(",") + line.decode('utf-8')
line = line.split(',')
velocity = float(line[2])
temp = float(line[5])
print('CPU_temperature' + '/' + line[0] + ',' + line[2] + ','
+ line[3] + ',' + line[4] + ',' + line[5])
f.write(line[0] + ',' + line[2] + ','
+ line[3] + ',' + line[4] + ',' + line[5] + "\n")
if temp >= 35.0:
# print('too hot')
wiringpi.pwmWrite(servo_pin, set_degree + 5)
# LED(11, True)
else:
# print('oh.. cool')
# move_deg = int (81+41/90*set_degree)
wiringpi.pwmWrite(servo_pin, set_degree)
# LED(11, False)
time.sleep(5)
except IndexError:
pass
示例9: __init__
def __init__(self, pin, name, pwmCountUpFrequency, pwmCycleRange):
# このservoが接続されるGPIO番号
# GPIO12またはGPIO18のみサポートされる(GPIO12と13は同じ内容、GPIO18と19は同じ内容となる)
self.pin = pin
self.name = name
self.pwmCountUpFrequency = pwmCountUpFrequency
self.pwmCycleRange = pwmCycleRange
# ピン設定
wiringpi.pinMode(pin, wiringpi.PWM_OUTPUT)
# see: http://qiita.com/locatw/items/f15fd9df40153bbb4d27
# PWMのカウンタ周期:19.2[MHz]/clock=19.2∗10^6/400=48[KHz]≒0.0208[ms]
self.pwmFrequency = float(SG90Direct.PRI_PWM_BASE_CLOCK_FREQUENCY / self.pwmCountUpFrequency)
# PWM周波数:19.2[MHz]/clock/range=19.2∗106/400/1024=46.875[Hz]≒21.3[ms]
self.pwmCycleSec = 1.0 / self.pwmFrequency * self.pwmCycleRange
# 48[KHz]∗0.5[ms]=48000[Hz]∗0.0005[s]=24
self.minPmwValue = int(self.pwmFrequency * SG90Direct.MIN_ANGLE_SEC)
# 48[KHz]∗2.4[ms]=48000[Hz]∗0.0024[s]=115.2≒115
self.maxPmwValue = int(self.pwmFrequency * SG90Direct.MAX_ANGLE_SEC)
self.deltaPmwValue = self.maxPmwValue - self.minPmwValue
print 'pin: ' + str(self.pin) + ', pwmCountUpFrequency: ' + str(self.pwmCountUpFrequency) + 'Hz, pwmCycleRange: ' + str(self.pwmCycleRange)
print 'pwmFrequency: ' + ('%.3f' % self.pwmFrequency) + ' Hz(' + ('%.6f' % (1.0 / self.pwmFrequency)) + ' sec), pwmCycleSec: ' + ('%.6f' % self.pwmCycleSec)
print 'reference pwmCycleSec: ' + str(SG90Direct.REFERENCE_PWM_1CYCLE_SEC)
print 'minPmwValue: ' + str(self.minPmwValue) + ', maxPmwValue: ' + str(self.maxPmwValue) + ', deltaPmwValue: ' + str(self.deltaPmwValue)
示例10: main
def main():
if wp.wiringPiSetup() == -1:
print ("Unable to start wiringPi")
sys.exit(1)
if wp.wiringPiSPISetup(SPI_CHANNEL, SPI_SPEED) == -1:
print ("wiringPiSPISetup Failed")
sys.exit(1)
wp.pinMode(CS_MCP3208, wp.OUTPUT)
while 1:
t = time.time()
vt = read_adc(0)
R = (10000*vt)/(5-vt)
vt = 5*R/(R+10000)
temp = -0.3167*(vt**6) + 4.5437*(vt**5) - 24.916*(vt**4) + 63.398*(vt**3) - 67.737*vt*vt - 13.24*vt + 98.432
vh = read_adc(1)
humidity = (((vh/5.0)-0.16)/0.0062)/(1.0546-0.00216*temp)
print('{} Temp={}C, Humid={}%'.format(t, temp, humidity))
data = 'rasptest temp={},hum={} {:d}'.format(temp, humidity, int(t * (10**9)))
print("Send data to DB")
r = requests.post('http://192.168.1.231:8086/write', auth=('mydb', 'O7Bf3CkiaK6Ou8eqYttU'), params={'db': 'mydb'}, data=data)
print("Return status: {}", r.status_code)
time.sleep(30)
示例11: run
def run(self):
motionFirstDetectedTime = None
SLEEP_TIME = 0.5
# Set up the GPIO input for motion detection
PIR_PIN = 18
wiringpi.wiringPiSetupSys()
wiringpi.pinMode(PIR_PIN, wiringpi.INPUT)
# Loop through and detect motion
while True:
if wiringpi.digitalRead(PIR_PIN):
if motionFirstDetectedTime is None:
motionFirstDetectedTime = datetime.now()
print('Motion detected at: ' + str(motionFirstDetectedTime))
# Do we need to send out a notification?
now = datetime.now()
if (motionFirstDetectedTime is not None) and (now - motionFirstDetectedTime) > timedelta (minutes = 1):
print('Sending out notification now!')
motiondate = datetime.strftime(motionFirstDetectedTime, '%Y-%m-%d %H:%M:%S')
msg = self.message + ': ' + motiondate
self._send_email(msg)
# reset state
motionFirstDetectedTime = None
time.sleep(SLEEP_TIME)
示例12: __init__
def __init__(self, config):
import wiringpi
Unlocker.__init__(self, config)
# PIN numbers follow P1 header BCM GPIO numbering, see https://projects.drogon.net/raspberry-pi/wiringpi/pins/
# Local copy of the P1 in repo mapping see gpio_vs_wiringpi_numbering_scheme.png.
wiringpi.wiringPiSetupGpio()
self.lockPin = self.config.getint("UnlockerWiringPi", "lock_pin")
wiringpi.pinMode(self.lockPin, wiringpi.OUTPUT) #output
示例13: ensure_button_setup
def ensure_button_setup():
import wiringpi
ensure_wiringpi_setup()
for button_pin in button_pins:
wiringpi.pinMode(button_pin, wiringpi.INPUT)
wiringpi.wiringPiISR(button_pin, wiringpi.INT_EDGE_BOTH, GPIO_callback)
示例14: triggerRemote
def triggerRemote():
if PI_SETUP:
wiringpi.pinMode(CAMERA_PIN, 1)
wiringpi.digitalWrite(CAMERA_PIN, 1)
utilities.wait(0.1)
wiringpi.digitalWrite(CAMERA_PIN, 0)
else:
print "Can't trigger remote, not pi"
示例15: __init__
def __init__(self):
wiringpi.wiringPiSetupGpio()
wiringpi.pinMode(self.PIN_PWM, wiringpi.GPIO.PWM_OUTPUT)
wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
wiringpi.pwmSetClock(375)
wiringpi.pwmWrite(self.PIN_PWM, self.FRONT)