MarkT.
The last two conditionals in loop() are still inside the Serial.available()
test, so they will never be noticed except if a character comes in off the
Serial port.You need to move them up a level so they always get tested round loop()
That was the problem. I moved them up and it is working as I intended. Thank you. I am not sure how to mark this post as solved? The first message in this string was my very first post, ever, anywhere.
I have taken on board your suggestion that the loop() is too long. That means though I am going to have to seriously rethink the sketch that this snippet is going to be a part of.
raschemmel, yes I am using a 36V transformer on this. Thank you for your probing questions.
polyglot. I started to reply to you before trying the suggestion from Mark and for the benefit of anyone else looking to use a linear actuator with a reed switch for feed back here is the reply I was intending, as redundant some of it may now be:
Do you know that the currentPosition variable is being updated properly, i.e. that the pulses are being registered? Do you see the appropriate activity on your serial monitor showing the pulses
The currentPosition is definitely being updated correctly. I am saying that because as described above, if the goalPosition is 50, while the actuator extends past 50 on writing 'A' to serial, it will immediately retract on a second write to serial of 'A'. The same goes for a serial write of 'B'. It will extend if CurrentPosition > goalPosition and retract if goalPosition < CurrentPosition. Pulses are registering well on the serial monitor. I did have some initial problems with switch bounce but found this site;
http://robotgestation.com/SensorForce.html
and used the circuit shown in the "SwitchDebounce" image for hardware debounce which uses a 74hc14 schmitt trigger. It works very well but after doing the calcs Tc = C * R, rather than using a 10K resister shown in the example I chose to use a 5k resister. I went from an unfiltered switch bounce like in image "Unfiltered" to a signal shown in image "Circuit 1A" using the "Let's add a capacitor!" example from the webpage to the final signal shown in "Switch Debounce A" image, which according to my tired old CRO looks pretty clean. I hope the images are attached properly as I am intending them to be.
Thank you all for your help. I can finally go to bed without laying awake trying to figure this out. Simple in the end, as I knew it would be, being as green as I am.



