嗨大家好我是任何python脚本的新手。了解一些基础知识。我的问题是我有一个Rasberry Pi 2模型b。我试图控制一个8频道中继,就像这个视频https://www.youtube.com/watch?v=oaf_zQcrg7g中使用的那样。我试图按照相同的代码尝试让它至少点亮并切换一些继电器。代码是:
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
# init list with pin numbers
pinList = [2, 3, 4, 17, 27, 22, 10, 9]
# loop through pins and set mode and state to 'low'
for i in pinList:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.HIGH)
# time to sleep between operations in the main loop
SleepTimeL = 0.2
# main loop
try:
while True:
for i in pinList:
GPIO.output(i, GPIO.HIGH)
time.sleep(SleepTimeL);
GPIO.output(i, GPIO.LOW)
pinList.reverse()
for i in pinList:
GPIO.output(i, GPIO.HIGH)
time.sleep(SleepTimeL);
GPIO.output(i, GPIO.LOW)
pinList.reverse()
# End program cleanly with keyboard
except KeyboardInterrupt:
print " Quit"
# Reset GPIO settings
GPIO.cleanup()
# find more information on this script at
# http://youtu.be/oaf_zQcrg7g
我已经改变了输入以适应我使用的引脚(1-9)我没有使用过(1-9)而不是只是有人认为:)。
我得到的错误: 希望我做得对,使用后:
python test.py
错误是:
File "test.py", line 1 Python 3.4.2 (default, Oct 19 2014, 13:31:11)
SyntaxError: invalid syntax
非常感谢任何回应。