forked from nickbild/usb_gpio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
34 lines (27 loc) · 1.04 KB
/
demo.py
File metadata and controls
34 lines (27 loc) · 1.04 KB
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
from usbgpio import USBgpio
import time
# Establish a serial connection to the device.
gpio = USBgpio('/dev/ttyUSB0', 115200)
time.sleep(1) # Important!!! --- Wichtig!!!
# Set GPIO pin as output
ledPIN = 13 # 13 is the onboard LED
gpio.set_output(ledPIN)
# Set GPIO pin as input
inputPIN = 3
gpio.set_input(inputPIN)
# Set servo pin & activate (attach) it
servoPIN = 8
gpio.servo_attach(servoPIN)
while True:
# Alternate between high and low voltage levels to blink an LED
# Toggle servo from 0° to 180°
gpio.digital_write(ledPIN, "HIGH") # LED on. Can also be "HIGH", "high", "High", "True", "true", "TRUE", True or 1
gpio.servo_write(servoPIN, 0) # Move servo to 0°
time.sleep(1)
gpio.digital_write(ledPIN, 0) # LED off Can also be "LOW", "low", "Low", "False", "false", "FALSE", False or 0
gpio.servo_write(servoPIN, 180) # Move servo to 180°
time.sleep(1)
# Read the value of a pin and print the result.
print(gpio.digital_read(inputPIN))
# Detach servo
gpio.servo_detach(servoPIN)