Answers.Body: <p>You can do this with parallel programs and a logic variable. You will need 3 loops, one for each sensor and one for the motor. In the sensor loops, wait for the touch sensor to be pressed and then set a logic variable to true. In the motor loop, have a switch block that tests the logic variable. If it is true, reverse and turn around and then set the logic variable to false. If the logic variable is already false, just go forward.</p>
  
  <p><img src="https://i.sstatic.net/7Ydy2.png" alt="Code sample"></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-08T18:16:06.323Z
Answers.Text: Thanks a lot. I considered using a variable to track it, but I wanted to know if there was a simpler, more intuitive way. Your script is probably better than what I could have come up with.
Answers.UserDisplayName: Saamoz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-08T16:32:55.260Z
Answers.LastActivityDate: 2015-04-08T16:32:55.260Z
Answers.UserDisplayName: David Lechner
Answers.Body: <p>Here is another pattern that watches more than one sensor.  Instead of parallel code blocks setting a variable value, this code combines sensor outputs to feed a logic block which feeds a switch.  No variable is used.</p>
  
  <p>Note that only the touched side of the switch statement is used.  Not an important difference, I just find it easier to follow.</p>
  
  <p>The other pattern might be described as event driven, which is used widely in programming.</p>
  
  <p><a href="https://i.sstatic.net/kUjX2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/kUjX2.png" alt="Backup, turn and go forward when either touch sensor is touched."></a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-25T03:08:02.283Z
Answers.LastActivityDate: 2015-08-25T03:08:02.283Z
Answers.UserDisplayName: dfrevert
Body: <p>Originally, I had a simple program to move until the robot hit a wall, then it reversed and turned and moved again, repeated to infinity. It works by turning the motors on, waiting for input from the touch sensor, then reversing, turning, and continuing. Now I want to add a second wait on the touch sensor to trigger the reverse and turn sequence, but I can't add two different ports to wait from, or have two different triggers to start the reverse and turn. Is there any way to have a trigger from two different wait inputs?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-08T10:42:58.357Z
Comments.Text: This question about NXT could maybe help you: http://bricks.stackexchange.com/questions/3027/how-to-use-two-nxt-bricks-for-3-motors-and-4-sensors
Comments.UserDisplayName: pcantin
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-08T18:17:08.740Z
Comments.Text: That would work, but I'm aiming for a solution with the software so I don't have rely of external implants.
Comments.UserDisplayName: Saamoz
Tags: <ev3><programming><ev3-g>
Title: Have Multiple Inputs to Programming Block
UserDisplayName: Saamoz
ThreadText: # Have Multiple Inputs to Programming Block
  
  (Asked by: username_0 on 2015-04-08)
  
  Originally, I had a simple program to move until the robot hit a wall, then it reversed and turned and moved again, repeated to infinity. It works by turning the motors on, waiting for input from the touch sensor, then reversing, turning, and continuing. Now I want to add a second wait on the touch sensor to trigger the reverse and turn sequence, but I can't add two different ports to wait from, or have two different triggers to start the reverse and turn. Is there any way to have a trigger from two different wait inputs?
  
  **Tags:** ev3, programming, ev3-g
  
  > **Comments:**
  > **username_1**: This question about NXT could maybe help you: http://bricks.stackexchange.com/questions/3027/how-to-use-two-nxt-bricks-for-3-motors-and-4-sensors  
  > **username_0**: That would work, but I'm aiming for a solution with the software so I don't have rely of external implants.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2015-04-08. Score: 2 | Accepted answer
  
  You can do this with parallel programs and a logic variable. You will need 3 loops, one for each sensor and one for the motor. In the sensor loops, wait for the touch sensor to be pressed and then set a logic variable to true. In the motor loop, have a switch block that tests the logic variable. If it is true, reverse and turn around and then set the logic variable to false. If the logic variable is already false, just go forward.
  
  ![Code sample](https://i.sstatic.net/7Ydy2.png)
  
  > **Comments:**
  > **username_0**: Thanks a lot. I considered using a variable to track it, but I wanted to know if there was a simpler, more intuitive way. Your script is probably better than what I could have come up with.  
  
  ---
  
  ### Answer by username_3 on 2015-08-25. Score: 2
  
  Here is another pattern that watches more than one sensor. Instead of parallel code blocks setting a variable value, this code combines sensor outputs to feed a logic block which feeds a switch. No variable is used.
  
  Note that only the touched side of the switch statement is used. Not an important difference, I just find it easier to follow.
  
  The other pattern might be described as event driven, which is used widely in programming.
  
  [![Backup, turn and go forward when either touch sensor is touched.](https://i.sstatic.net/kUjX2.png)](https://i.sstatic.net/kUjX2.png)
  
  
  ---
  
  