问题遇到的现象和发生背景
在用python编译树莓派驱动电机转动的代码里有如下代码,想请教下两处涉及到位运算 >> 和 & 的内容想表达什么意思
用代码块功能插入代码,请勿粘贴截图
在这里写上你的代码 :-)
import RPi.GPIO as GPIO
from time import sleep
MotorPin = (18, 23, 24, 25)
RPM = 15
steps = 2048
motor_speed = (60/RPM)/steps
def setup() :
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
for i in MotorPin:
GPIO.setup(i, GPIO.OUT)
def Motor_rotary(direction) :
if direction == 1:
for j in range(4):
for i in range(4):
GPIO.output(MotorPin[i], 0x99>>j & (0x08>>i))
sleep(motor_speed)
elif direction == 0:
for j in range(4):
for i in range(4):
GPIO.output(MotorPin[i], 0x99<<j & (0x80>>i))
sleep(motor_speed)
def Motor_loop() :
direction = input('1 stands for clockwise, 0 stands for anticlockwise')
while True:
Motor_rotary(direction)
def destroy():
for i in MotorPin:
GPIO.output(i, GPIO.LOW)
GPIO.cleanup()
if name == 'main' :
setup()
try:
Motor_loop()
except KeyboardInterrupt:
destroy()