Hey everyone,
I typically don't ask questions as Google search seems to have all the answers, but this one has been doing my head in and I just can't pin-point what I'm doing wrong.
Brief intro to my project.
I am building an oil dosage machine, which I have successfully made and coded in the past with a simple 2 line lcd screen. I felt it was time to upgrade to a 128x64 lcd with SPI interface, for the rest most of it is the same besides the upcoming stirring PWM integration. Please note, the code is not complete.
Specs: Board: Arduino Mega 2560. display: ST7920 128x64 DFRobot.
Problem:
I have the display working fine, it is showing what I want. I'm not the best programmer, but I like to work by ensuring all the pages in the processes are displayed nicely. To do this, I don't attach the sensors and simply feed it manual information. The page I'm having issues with is called via the doDose() function, which is called by the press of a button via OneButton library (which works fine in old machine and does all the debouncing etc).
This function basically loads a page on the display to show that it is pumping, and how much in ml and % it has pumped. The strange thing is, it won't show if I only call the page display (lcd_Dose) in the main loop or if I only call it within the doDose function. The exact same screen calls are made in booth for it to display. If I take it out of the main loop, my mega board displays it for a fraction of a second then resets. If I only have it in the main loop it doesn't change from the ready screen. See codebelow.
The second issue is that having it in both shows up fine, although odd. But as I am running a while loop (line 281):
while(currentPumpedVolume < (doseVolume + volumeError))
it keeps looping even though it clearly exceeds the comparison, which should break the loop, continue and be done with the function. Removing the currentPumpedVolume = 0; before the while loop stops the function looping, but then it won't work after one run. I tried moving the currentPumpedVolume = 0 all over the shop inside and out of the function and it makes no difference.
I'm sure I did something wrong and I hope it is obvious. My head hurts too much from banging it on the desk. I have included the old code which works on 2 line lcd, and the new one which has clearer variable names, but is causing me grief. Any guidance is very much appreciated in advance.
Code Attached - apparently too long to post. NEW file with issues: AutoPopIncSureDose_V5.ino. Old working file: SureDose_V4_2018.ino
AutoPopIncSureDose_V5.ino (22.7 KB)
SureDose_V4_2018.ino (30.2 KB)