Answers.Body: <p>I found an answer. I read in a book that I can't fork in a loop. But I can do up to 4 separate threads. So I did 3 threads:</p>
  
  <ol>
  <li>Running/changing motors speed based on a variable "i" which is changed in other threads.</li>
  <li>Waiting for a touch sensor A being bumped and increasing var "i".</li>
  <li>Waiting for a touch sensor B being bumped and decreasing var "i".</li>
  </ol>
  
  <p><a href="https://i.sstatic.net/occ4n.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/occ4n.jpg" alt="3 threads"></a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-05T16:00:51.067Z
Answers.LastActivityDate: 2017-11-06T12:08:27.003Z
Answers.LastEditDate: 2017-11-06T12:08:27.003Z
Answers.UserDisplayName: Jacek U
Body: <p><a href="https://i.sstatic.net/hCrNz.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/hCrNz.jpg" alt="enter image description here"></a></p>
  
  <p>I'm trying do make simple program. Two motors, two touch sensors. Sensor one increases speed, sensor two decreases.</p>
  
  <p>The whole program works very well but only with one sensor. When I put some logic that has "Wait for sensor two" brick it just fools around.</p>
  
  <p>The algorithm is very simple:</p>
  
  <ul>
  <li>Variable <code>i</code> - counts times sensors being pressed</li>
  <li>Variable <code>Znak</code> (eng. sign) causes variable <code>i</code> to decrease if negative or increase if positive.</li>
  <li>Motor speed is calculated by multiplying <code>i</code> by 10. </li>
  </ul>
  
  <p>How can I solve this kind of problem?</p>
  
Tags: <ev3><mindstorms><ev3-g><sensor>
Title: Two Mindstorms touch sensors: how to determine which sensor was pressed?
UserDisplayName: Jacek U
ThreadText: # Two Mindstorms touch sensors: how to determine which sensor was pressed?
  
  (Asked by: username_0 on 2017-11-03)
  
  [![enter image description here](https://i.sstatic.net/hCrNz.jpg)](https://i.sstatic.net/hCrNz.jpg)
  
  I'm trying do make simple program. Two motors, two touch sensors. Sensor one increases speed, sensor two decreases.
  
  The whole program works very well but only with one sensor. When I put some logic that has "Wait for sensor two" brick it just fools around.
  
  The algorithm is very simple:
  
  * Variable `i` - counts times sensors being pressed
  * Variable `Znak` (eng. sign) causes variable `i` to decrease if negative or increase if positive.
  * Motor speed is calculated by multiplying `i` by 10.
  
  How can I solve this kind of problem?
  
  **Tags:** ev3, mindstorms, ev3-g, sensor
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-11-05. Score: 5
  
  I found an answer. I read in a book that I can't fork in a loop. But I can do up to 4 separate threads. So I did 3 threads:
  
  1. Running/changing motors speed based on a variable "i" which is changed in other threads.
  2. Waiting for a touch sensor A being bumped and increasing var "i".
  3. Waiting for a touch sensor B being bumped and decreasing var "i".
  
  [![3 threads](https://i.sstatic.net/occ4n.jpg)](https://i.sstatic.net/occ4n.jpg)
  
  
  ---
  
  