I want to move with joystick a blue dot while red dot is randomly falling, but if I press joystick, blue dot doesn't show or move.
(我想用操纵杆移动一个蓝点,而红色点随机下落,但是如果按操纵杆,则蓝点不会显示或移动。)
I use raspberry Pi 3 and Sense hat(led metrix and joystick) (我使用树莓派3和Sense帽子(led metrix和操纵杆))
Here is my code: (it's for rasberry pi and Sense hat)
(这是我的代码:(用于rasberry pi和Sense hat))
x = 0
y = 7
while True:
x1 = randint(0,7)
y1 = 0
start_number = 1
for i in range(start_number,1000, 1):
print(i)
sense.set_pixel(x1, y1, (255, 58, 0))
y1 = y1 + 1
sleep(1)
sense.clear()
if y1 > 7:
y1 = 0
x1 = randint(0,7)
for event in sense.stick.get_events():
sense.set_pixel(x, y, (77, 195, 255))
#Check if the joystick was pressed
if event.action == "pressed":
# Check which direction
if event.direction == "up" and x > 0:
x = x - 1
sense.clear()
elif event.direction == "down" and x < 7:
x = x + 1
sense.clear()
elif event.direction == "left" and y < 7:
y = y + 1
sense.clear()
elif event.direction == "right" and y > 0:
y = y - 1
sense.clear()
elif event.direction == "middle":
sense.set_pixel(x - x, y - y, (77, 195, 255))
sense.clear()
ask by Tom hala translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…