While a PV Control system is operational, it would be really nice if the safety margin could be tweaked on-the-fly. The ideal "sweet spot" could then be determined between importing and exporting.
Using if (Serial.available() > 0), the Serial port could be routinely polled without interrupting normal operation. What I would like to have is the ability to type "123" follwed by 'c/r', and for these characters to be converted into the decimal value 123.
But string manipulation is not my forte. Maybe someone can point me in the right direction please ...
TIA
Re: Struggling with Strings
My code over at https://github.com/stuartpittaway/VariableTimeBaseSSR does something similar, but using up/down values instead of actual numbers.
Re: Struggling with Strings
Thanks Stuart, that's an impressive response time!
Yes, I can see how this works with individual characters. This approach could presumably be used to nudge my safety margin up and down. Maybe that would be the best way to do it, using just the '+' or '-' keys followed by [cr]. Each time either character is entered, the new safety margin value could be displayed.
I rather like the idea of entering, say, 100 and seeing how long it takes to go from importing to exporting; and then entering -100 and seeing if it takes the same amount of time to go from exporting to importing. Any imbalance would be due to some inherent offset in my system which could then be calibrated out using the approriate value.
I'm interested to see your interrupt code for switching a load at zero-crossing points. My preferred way of doing this is to get a dedicated trigger device to do the actual detection, and get the Arduino to 'arm' it (or not) at the right point in each preceeding mains cycle.
Re: Struggling with Strings
Serial.readBytesUntil(character, buffer, length)
followed up by atoi( ). This seems to work, returns zero for non-numeric input.
You may need to change the terminating character ('\n') to suit the serial host/terminal.
Re: Struggling with Strings
Thanks Robert, works a treat!
(do you ever take a break ;)