question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Push button to run motors?

See original GitHub issue
  • ev3dev version: PASTE THE OUTPUT OF uname -r HERE
  • ev3dev-lang-python version: INSERT ALL VERSIONS GIVEN BY dpkg-query -l python3-ev3dev* HERE

when I run this program it doesnt quite do what I want. I mostly just want it to run the motor when I push the touch sensor. This is the program I’m running.

#!/usr/bin/env python3
from ev3dev.brickpi3 import *

from ev3dev2.motor import LargeMotor, OUTPUT_A, OUTPUT_B, SpeedPercent, MoveTank
from ev3dev2.sensor import INPUT_1
from ev3dev2.sensor.lego import TouchSensor
from ev3dev2.led import Leds

ts = TouchSensor(INPUT_1)
m = LargeMotor(OUTPUT_B)

while True:
    if ts.value() == 0:
      m.stop(stop_action="brake")
    else:
      m.run_forever(speed_sp=180)   # equivalent to power=20 in EV3-G

When I run the program it just turns the motor but when I unplug the touch sensor the motor stops. I guess I still haven’t been able to find a way to simply touch the touch sensor and have it turn the motor.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
dwalton76commented, Nov 11, 2018

It seems like it would run as long as you are holding down the touch sensor. Add a “break” after the run_forever() call so that you drop out of that while True loop.

0reactions
happyFox1982commented, Dec 30, 2018

try this code, and find the differences:

     import ev3dev.ev3 as ev3
     import time

     print('I am ready!')

      l = ev3.LargeMotor('outA')
      r = ev3.LargeMotor('outD')
      ts = ev3.TouchSensor()

       while ts.is_pressed==False :
        continue

       ev3.Sound.speak('I shall run!').wait()

       l.run_timed(time_sp=3000, speed_sp=700)
       r.run_timed(time_sp=4000, speed_sp=700)
Read more comments on GitHub >

github_iconTop Results From Across the Web

BVPOW Motor Start Stop Push Button Motor On Off Switch ...
BVPOW Motor Start Stop Push Button Motor On Off Switch with Surface Waterproof Dustproof Box Mount KAO-5H 10A AC 220/380V ; Qty:1 ;...
Read more >
Switches and Pushbuttons – Basic Motor Control
Pushbuttons are momentary contacts that come available as either normally open (NO) or normally closed (NC) contacts , although many pushbuttons come with...
Read more >
Servo Motor + Push Button + Arduino : 5 Steps - Instructables
1. Arduino or any Arduino-compatible microcontroller Servo motor Push button switch 10k Ohm Resistor - brown-black-orange 2. 1a The Black wire connects pin 1 of the switch...
Read more >
Motor control with Push button - Tinkercad
Motor control with Push button ... Design is visible in our gallery and to anyone with the link. This is a remix of...
Read more >
All About Push Button Starts - Car and Driver
A push button start key fob is a button that allows drivers to start their engine by pressing it. That said, you won't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found