我使用Raspberry Pi 3,我试图通过命令终端运行这个Python脚本:
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)
Motor1A = 16
Motor1B = 18
Motor1E = 22
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)
print "Turning motor on"
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)
sleep(2)
print "Stopping motor"
GPIO.output(Motor1E,GPIO.LOW)
GPIO.cleanup()
该文件名为" motor1.py"。它位于" / home / pi" 。目录
当我输入sudo python motor1.py
时,终端响应如下:
pi@raspberrypi:~ $ sudo python motor1.py
File "motor.py", line 1
Python 2.7.9 (default, Sep 17 2016, 20:26:04)
^
SyntaxError: invalid syntax
谁能告诉我为什么?非常感谢。
约翰尼