Skip to main content
deleted 8 characters in body
Source Link
dda
  • 1.6k
  • 1
  • 12
  • 18

A normal servo doesn't have a "go" function, it only has positional control. That is, weatherwhether you run servo.write(90)servo.write(90) forever or once, the servo will go to 90 and continue to actively keep that position until you write another position. The only way to turn a servo off is:

servo.detach(); 

For a normal DC motor, you will need to turn it on then off and then have kind of state tracking in the loop to never turn it on again, using a variable or millis()millis() etc.

Of course, if you want something to only run once, put it in setup() setup() (maybe within a loop in setup for simple tasks).

Also, you can simulate ending the program by entering an infinite loop with

while(true){} 

while(true){} or for(;;){}.

for(;;){} 

A normal servo doesn't have a "go" function, it only has positional control. That is, weather you run servo.write(90) forever or once, the servo will go to 90 and continue to actively keep that position until you write another position. The only way to turn a servo off is

servo.detach(); 

For a normal DC motor, you will need to turn it on then off and then have kind of state tracking in the loop to never turn it on again, using a variable or millis() etc.

Of course, if you want something to only run once, put it in setup() (maybe within a loop in setup for simple tasks)

Also, you can simulate ending the program by entering an infinite loop with

while(true){} 

or

for(;;){} 

A normal servo doesn't have a "go" function, it only has positional control. That is, whether you run servo.write(90) forever or once, the servo will go to 90 and continue to actively keep that position until you write another position. The only way to turn a servo off is:

servo.detach(); 

For a normal DC motor, you will need to turn it on then off and then have kind of state tracking in the loop to never turn it on again, using a variable or millis() etc.

Of course, if you want something to only run once, put it in setup() (maybe within a loop in setup for simple tasks).

Also, you can simulate ending the program by entering an infinite loop with while(true){} or for(;;){}.

Source Link
BrettFolkins
  • 4.4k
  • 1
  • 15
  • 26

A normal servo doesn't have a "go" function, it only has positional control. That is, weather you run servo.write(90) forever or once, the servo will go to 90 and continue to actively keep that position until you write another position. The only way to turn a servo off is

servo.detach(); 

For a normal DC motor, you will need to turn it on then off and then have kind of state tracking in the loop to never turn it on again, using a variable or millis() etc.

Of course, if you want something to only run once, put it in setup() (maybe within a loop in setup for simple tasks)

Also, you can simulate ending the program by entering an infinite loop with

while(true){} 

or

for(;;){}