Firstly, way up top in the code is this:
byte drinkozarray[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
byte drinkozprevarray[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned long pumpcompensatearray[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
Then there is "pouramount" which is used inside of "countandpour", which is then used inside of "pour"
Here is "pouramount":
void pouramount(byte drink, byte &previousdrink, unsigned long &runtime, byte volume)
{
unsigned long pourdelay = 0;
if(drink < previousdrink) {
previousdrink = 0;
runtime = 0; //when I refill the bottle and reset the count, this should reset the added runtime too.
}
else if(drink >= previousdrink) {
previousdrink = drink;
runtime = runtime + 925 * volume; //this should add 925ms for each full oz poured to account for lack in bottle backpressure
} // seeing as every 10 qtr oz I pour, the rate drops by about one qtr oz
if (volume >= 1, volume < 32){
pourdelay = volume * 9250;
delay(pourdelay); //9250ms = one quarter ounce. This way, when I type in my ingredients, I just tell it how many quarter oz to pour
}
else if (volume = 0){
delay(1157); //This gives me a way to specify a "dash", or 1/8th ounce in a recipe, without getting all math crazy
runtime = runtime + 116;
}
else if (volume = 33){
delay(3053);
runtime = runtime - 305250; //This gives me a way to specify a "third", or 1/3rd ounce in a recipe, without getting all math crazy
runtime = runtime + 305;
}
delay(1250); //this account for the pump spin-up time, while it's pumping liquid but none has yet come out of the nozzle
delay(runtime); //this should add the extra backpressure acounting time to the runtime of the pump.
}
Here is countandpour:
void countandpour(byte array, byte volume) {
if(volume >= 1, volume < 32) {
drinkozarray[array] = drinkozarray[array] + volume;
}
else if(volume = 33) {
drinkozarray[array] = drinkozarray[array] + 2;
}
pouramount(drinkozarray[array], drinkozprevarray[array], pumpcompensatearray[array], volume);
}
and last but not least, here is "pour":
void pour(byte array, int drink, byte volume)
{
switch (drink)
{
case vodkas:
digitalWrite(latch, 0);
lightredpour1();
pour_vodka();
digitalWrite(latch, 1);
countandpour(array, volume);
break;
case rumlts:
digitalWrite(latch, 0);
lightredpour1();
pour_rumlt();
digitalWrite(latch, 1);
countandpour(array, volume);
break;
//etc, etc...
You'll notice that "pour" also calls "pour_vodka();" and "lightredpour1();"
The function with the liquor name just looks like this:
void pour_vodka()
{
shiftOut(data, clock,MSBFIRST, shiftoutarray[1]);
shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
//vodka = vodka + volume;
}
void pour_rumlt()
{
shiftOut(data, clock,MSBFIRST, shiftoutarray[2]);
shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
shiftOut(data, clock, MSBFIRST, shiftoutarray[0]);
}
//etc, etc...
And the "lightredpour();" function just controls effect lighting, changing it to red lights while pouring.
NOW to my original problem, which occurs inside "pouramount();"
I try to feed delay
unsigned long pourdelay = 0;
pourdelay = volume * 9250;
delay(pourdelay);
and if the result is anything over 32k, the delay just never ends. What is going on? (Additionally, I know my code is probably sloppy... I am still a dummy at this and I am working on that. Please try to stick to the delay problem I'm having instead of the ugliness of my code- as I would like it to work first before I spend lots of time optimizing something that doesn't work in the first place)
Oh and for those of you that have been helping me since the beginning- IT WORKS! I have booze in it, and it is pouring recipes! Until I fix this delay issue though, if a pour has to last longer than 32 seconds- it just pours until the end of time LOL.