-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpio_work.py
38 lines (32 loc) · 1.2 KB
/
gpio_work.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
37
38
# Import standard Python time library.
import time
# Import GPIO and FT232H modules.
import Adafruit_GPIO as GPIO
import Adafruit_GPIO.FT232H as FT232H
# Temporarily disable the built-in FTDI serial driver on Mac & Linux platforms.
FT232H.use_FT232H()
# Create an FT232H object that grabs the first available FT232H device found.
ft232h = FT232H.FT232H()
# Configure digital inputs and outputs using the setup function.
# Note that pin numbers 0 to 15 map to pins D0 to D7 then C0 to C7 on the board.
ft232h.setup(7, GPIO.IN) # Make pin D7 a digital input.
ft232h.setup(8, GPIO.OUT) # Make pin C0 a digital output.
# Loop turning the LED on and off and reading the input state.
print 'Press Ctrl-C to quit.'
while True:
# Set pin C0 to a high level so the LED turns on.
#ft232h.output(8, GPIO.HIGH)
# Sleep for 1 second.
#time.sleep(1)
# Set pin C0 to a low level so the LED turns off.
#ft232h.output(8, GPIO.LOW)
# Sleep for 1 second.
#time.sleep(1)
# Read the input on pin D7 and print out if it's high or low.
level = ft232h.input(7)
if level == GPIO.LOW:
print '#2 Pin D7 is HIGH! Send C0 HIGH!'
ft232h.output(8, GPIO.HIGH)
else:
print '#2 Pin D7 is LOW! Send C0 LOW!'
ft232h.output(8, GPIO.LOW)