Hey all,
Really hope someone can help me out here.....
I Have not got my UNO program to hand until I return to work next week but I have a glitch I need help with if someone can ?
Program Purpose:
My program, uses PWM output to an external module which converts PWM 0 - 100% to 0 - 5v, it's controlling the speed of a Grundfos industrial centrifugal water pump. I have x5 INT variables which hold PWM values to represent flow rate set points which produces a 32 step pattern over a 6 hr period of varying flow rates and holds. This 6 hour sequence then repeats over and over while a logger records water pressure and flow rate at 10 sec intervals.
Apart from the 'main Loop()' I have 3 functions. One deals with the pump speed when it needs to increase from it's current flow rate, another which deals with pump speed when it needs to decrease from it's current flow rate and a third which deals with a situation where the flow rate needs to hold for a set amount of time.
Eg: START - Hold at zero for 10 mins - increase from zero to 1000 over 2 mins - Hold at 1000 for 20 mins - Increase from 1000 to 2000 over 2 mins - Hold at 2000 for 32 mins etc etc
In the main Loop(), I have a sequence of x32 'code blocks' which call either of these functions depending on the flow sequence required and passes the required PWM variable for the function to use when changing pump speed, all the functions use a basic loop which changes speed over a 2 min period but the Holding function uses different amounts of time to hold at certain flow rates.
The water being pumped is going through a line of brand new domestic water meters with the intention of getting them to a value of 1000 cubic meters on their registers which concludes the test sequence.
Every week of this rig running I need to completely stop the flow to take readings from the registers of the water meters on test and continue the sequence after. I created a forth function to handle this. I have a simple 'Pause switch' hooked up to one of the UNO's pins which is coninuously monitored while the program runs. Once this switch is clicked it enters a pause state where the current 'step' completes and the Pause function is then called. Once in the Pause function, the 'Completed step' is recorded to a variable and the pump is set to zero speed which stops the flow. I then print up a message to the Serial monitor asking the user to type the reason for the pause and hit enter.
while (Serial.Available() ==0) {} Holds this situation until a user typed input is there
The users typed input is assigned to a string variable and printed to the serial monitor. At this point the state of the 'Pause Switch' is monitored via another 'while loop' and nothing happens, I take my meter readings, once done, pause switch is turned off. Once this happens, the pause function reads the last completed 'step' flow rate and it restarts the pump to reach that speed over 2 mins before continuing with the sequence.
Hope the above makes basic sense and I really hope I have not gone on too long, sorry if I have ?
MY PROBLEM:
I send the Program to the UNO and it begins to run.....All works fine at this point and also when I activate the very first 'Pause' action, all perfect. The problem comes later when I try to activate the 'Pause' again.....It completes the current Step and brings the flow rate down to zero as expected along with the message to enter the reason for the pause in the serial monitor, but this time, instead of waiting at that endless While loop for the user input is shoots straight passed this as if the user has already typed and hit enter. ? My assumption is that 'Serial.Available() == 0' is no longer empty after the first 'Pause' action and user input but googling is not giving me a result of how to clear that buffer, Or, maybe it is something else.
Many Thanks for any help if anyone would be so kind.
Regards
Paul
