I'm a beginner and trying to write a code for a horse race derby game (made out of wood). There are two horses and each is driven by a 360° servo. Each horse is connected to three different sensors. Depending on which sensor is activated the horse should walk 1, 2 or 3 steps, what means, that the servo should make 1, 2 or 3 full rotations. I already wrote a working code using long delays to run the servos. But with this solution there are some issues: Its not possible that both horses walk at the same time and i don't know how to make the horses return at the exact start position after one player one (one horse arrived at the end of the runway) at this moment the servos should rotate backwards, but each one individually. I thought I could place sensors at the start end the end of the runway, but they wont be activated during the delay.
d1d1:
I already wrote a working code using long delays to run the servos.
Welcome to the forum!
Post your 'working' code so we can inspect it. Use the </> button above to do this.
Long delays? Red warning light to most programmers. Servos can move to the required position without delays. Thus, several servos can be active simultaneously.
See point 1! And anything else you may have discovered in the meantime.
If you persevere you will be able to fix this but you must be prepared to do the 'grunt work' whilst others here suggest and nudge you in the right direction. After all, this is fun, right?
I just wanted to add, that it might be a good ideer to put your servo position into a variable, so that you can add to it.
For instance, you might want to have the servo go to the new position at a certain speed, and therefore you would make it move slower then it would normally do. This could mean that the used has another successful hit, which should be added to the desired servo position.