Pages: [1]   Go Down
Author Topic: How to use sensor signal trigger/stop code execution?  (Read 278 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi I am very new to Arduino, so please excuse the simplicity of my question. 
I try to do this:
Read 1st. Proximity sensor signal, then trigger/start my code execution, once get 2nd. Proximity sensor signal, then stop my code execution, and do something else, such as rotate stepper motor 500 rev.

Could somebody give me similar example to achieve this?

Thanks very much in advance.




Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need a state variable:

Code:
byte started = 0

if sensor is triggered then
  started = 1 - started

if started then
  do stuff that doesn't use large delays()
   
Logged

Pages: [1]   Go Up
Jump to: