No responding to button command
ivan-marroquin opened this issue · 2 comments
ivan-marroquin commented
- ev3dev version: PASTE THE OUTPUT OF
uname -r
: 4.14.117-ev3dev-2.3.4-ev3 - ev3dev-lang-python version: INSERT ALL VERSIONS GIVEN BY
dpkg-query -l {python3,micropython}-ev3dev*
ii python3-ev3dev 1.2.0 all Python language bindings for ev3dev
In the Python script below, I would like the robot to play a wav file and stop moving when the left button is pressed. For some reason, the command to check when the left button is pressed doesn't work properly. To stop the script, I must press the backspace button.
Thanks for your help and suggestions. Below, you will find the script:
#!/usr/bin/env python3
import logging
from ev3dev2.motor import MoveTank, OUTPUT_B, OUTPUT_C
from ev3dev2.button import Button
from ev3dev2.sound import Sound
from ev3dev2.sensor.lego import InfraredSensor
from ev3dev2.led import Leds
from time import sleep
import sys
btn= Button()
tank_pair= MoveTank(left_motor_port= OUTPUT_B, right_motor_port= OUTPUT_C)
infra_sensor= InfraredSensor()
leds= Leds()
sound= Sound()
sound.speak('Hello Doctor Marroquin', volume= 200)
sound.play_file('/home/robot/sounds/Activate.wav', volume= 100)
while (True):
if (btn.check_buttons(buttons= ['left'])):
sound.play_file('/home/robot/sounds/Fanfare.wav', volume= 100)
sys.exit()
tank_pair.on_for_seconds(left_speed= -50, right_speed= -50, seconds= 10)
if (infra_sensor.proximity < 80 * 0.7):
leds.set_color('LEFT', 'RED')
leds.set_color('RIGHT', 'RED')
else:
leds.set_color('LEFT', 'GREEN')
leds.set_color('RIGHT', 'GREEN')
WasabiFan commented
Are you holding the button for at least ten seconds? The "if" at the beginning of your loop runs once per loop iteration, and since you run the motors for ten seconds, you have to hold it long enough to make sure it's being held at the time your loop checks for pressed buttons.
ivan-marroquin commented