65Views2Replies

Author Options:

6 multiservo random selection Answered

Hi!

I would like to create a project for the random selection of shooting targets. E.g. each target should show up and stay there for 5 seconds and if not shot down the servo should pull it back. Does anyone have the code required for random selection of servos and making sure they delay between on and off is 5 secs? Ideally the random component would ensure that all targets have an equal chance of being selected but only one at a time.

2 Replies

user
randofo (author)2018-02-06

That is a fairly straight forward challenge. You should look into Arduino "case statements."

The pseudo code would basically look like:

Variable == select random number between 1 - 5

Variable Case 1:

move motor 1 up
delay 5 seconds
move the motor back
break

Variable Case 2:

move motor 2 up
delay 5 seconds
move the motor back
break

etc.

This is just an idea of the structure of the code. The actual code will be formatted differently.

Also, check out the Arduino Class:
https://www.instructables.com/class/Arduino-Class/

And the robot class for servos:
https://www.instructables.com/class/Robots-Class/

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)2018-02-06

There's a RANDOM function in Arduino its straight forward to use.
Here's the reference pages
https://www.arduino.cc/reference/en/language/functions/random-numbers/random/

Its only pseudo random, you could seed the random number generator with a read from an open analog input line.

Select as Best AnswerUndo Best Answer