Although this is not actually a robotic problem as such, I believe that the folks here will be doing much the same as I am attempting ? so please excuse me if I am wrong in that asssumption.
I am developing a points control system for a model railway, and as a part of thast, I want to automate the situation where setting just one point that forms a crossover will automatically set the matching point accordingly.
I have got all the coding sorted out - no problems thee I am sure, I have debugged it right down to the n'th degree. The switching of the "master" point works as expected, as do all the other point switching operations.
My code does a check on a data array that reports the matching point, if any, and then resets the relevant pointer to address the "slave" point. I then make an identical call to servo.write for the "slave" point, but this simply does not move the servo (which works just fine anywhere else.) even though A CHECK WITH servo.read() suggests it has worked !
I have tried adding a delay(2000) in case it was happening too fast, no difference.
I have tested the servo from other output pins defined in the system, and also tried different pins as the output for the "slave" servo. Everything works when I switch just one point, but doing the second one seems to be ignored by the servo library.
I am using a Mega2560, and have tried various output pins for the "slave" with the same result. I am also using serial comms, so am aware that pin 10 must be left as an Output or the comms will not work, although I am using a different pin for the CS. I have therefore set pin 10 as an output in Setup()
It has driven me nuts for around 2 days now, so I would really appreciate any suggestions as to how to get this "slave" to work as expected ?
Here is a sample of the serial monitor output, the comments printed should be fairly self explanatory, point 6 is the "master" and point 7 the "Slave"
we now have array pointer *pptArray for 6
pptArray[1] = 6
pptArray[2] = 9
pptArray[3] = 0
pptArray[4] = 65
pptArray[5] = 120
pptArray[6] = 7
pptArray[7] = 6
Point 6 set to mode BRANCH, angle 65
Relevant memory array has been updated successfully
Checking if this point [6] is part of a crossover ...
YES, this point [6] is part of a crossover with point [7]...
Setting paired point to match ...
Entering fillPointStructure()
List of data from pptServo, a pointer to ptServo
*pptServo - 7
*pptServo - 15
*pptServo - 1
*pptServo - 65
*pptServo - 120
*pptServo - 6
*pptServo - 0
We are now going to change the setting for crossover point [7] using pin 15...
Setting point [7] on pin [15] to 65...
presult2 for point 7 is 65
Entering updateArray()
we now have array pointer *pptArray for 7
pptArray[1] = 7
pptArray[2] = 15
pptArray[3] = 0
pptArray[4] = 65
pptArray[5] = 120
pptArray[6] = 6
pptArray[7] = 0
Matching crossover Point 7 has been set using pin 15
SUCCESS - command [1] completed as requested
Many thanks
Ian