Hello! cocktail maker, which if I don't set the quantity, the program will still run. And I would need to, if I set everything to 0, not run the program.
if (screen == 8 && doonce == 0) {
lcd.clear();
if (changestate == 0) {
lcd.print("Start?");
doonce = 1;
}
else {
lcd.print("Wait!");
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 1 ON");
digitalWrite(in1, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
if (Vodka==1)
lcd.clear();
lcd.print(pump1ml);
lcd.print("ml");
delay((pump1ml/11)*1000);
digitalWrite(in1, HIGH);
digitalWrite(in9, LOW);
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 2 ON");
digitalWrite(in2, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
}
Vodka = 0;
} {
if (Jager==1)
lcd.clear();
lcd.print(pump2ml);
lcd.print("ml");
delay((pump2ml/12)*1000);
digitalWrite(in2, HIGH);
digitalWrite(in9, LOW);
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 3 ON");
digitalWrite(in3, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
}
Jager = 0;
} {
if (Vorosbor==1)
lcd.clear();
lcd.print(pump3ml);
lcd.print("ml");
delay((pump2ml/12)*1000);
digitalWrite(in3, HIGH);
digitalWrite(in9, LOW);
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 4 ON");
digitalWrite(in4, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
}
Vorosbor = 0;
} {
if (Rosebor==1)
lcd.clear();
lcd.print(pump4ml);
lcd.print("ml");
delay((pump2ml/12)*1000);
digitalWrite(in4, HIGH);
digitalWrite(in9, LOW);
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 5 ON");
digitalWrite(in5, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
}
Rosebor = 0;
} {
if (Narancs==1)
lcd.clear();
lcd.print(pump5ml);
lcd.print("ml");
delay((pump2ml/12)*1000);
digitalWrite(in5, HIGH);
digitalWrite(in9, LOW);
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 6 ON");
digitalWrite(in6, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
}
Narancs = 0;
} {
if (Cola==1)
lcd.clear();
lcd.print(pump6ml);
lcd.print("ml");
delay((pump2ml/12)*1000);
digitalWrite(in6, HIGH);
digitalWrite(in9, LOW);
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 7 ON");
digitalWrite(in7, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
}
Cola = 0;
} {
if (Bodza==1)
lcd.clear();
lcd.print(pump7ml);
lcd.print("ml");
delay((pump2ml/12)*1000);
digitalWrite(in7, HIGH);
digitalWrite(in9, LOW);
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 8 ON");
digitalWrite(in8, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
}
Bodza = 0;
} {
if (Whisky)
lcd.clear();
lcd.print(pump8ml);
lcd.print("ml");
delay((pump3ml/12)*1000);
digitalWrite(in8, HIGH);
digitalWrite(in9, LOW);
delay(2000);
changestate = 0;
}
Whisky = 0;
} {
}
}
}
Well done for using code tags. karma. Now you need to put some text outside the tags to explain what your code is doing and what you are having a problem with.
You are missing curly brackets in all your if statements
I know it is missing, it is written in the original program. But he didn't change it. What exactly do I need to type?
Look up the arduino reference above and if statements. If gives you the syntax. The first if statement in your code is correct the others are not. {}
d_r_l00:
I know it is missing, it is written in the original program.
That is unlikely, there is no way the program could ever work that way.
First, I accidentally submitted the wrong code. This code is present in Arduino. But it still doesn't work the way it should.
else {
lcd.print("Wait!");
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 1 ON");
digitalWrite(in1, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
if (Vodka==1)
{
lcd.clear();
lcd.print(pump1ml);
lcd.print("ml");
delay((pump1ml/11)*1000);
digitalWrite(in1, HIGH);
digitalWrite(in9, LOW);
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 2 ON");
digitalWrite(in2, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
}
Vodka = 0;
}
if (Jager==1)
{
lcd.clear();
lcd.print(pump2ml);
lcd.print("ml");
delay((pump2ml/12)*1000);
digitalWrite(in2, HIGH);
digitalWrite(in9, LOW);
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 3 ON");
digitalWrite(in3, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
}
Jager = 0;
}
if (Vorosbor==1)
{
lcd.clear();
lcd.print(pump3ml);
lcd.print("ml");
delay((pump2ml/12)*1000);
digitalWrite(in3, HIGH);
digitalWrite(in9, LOW);
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 4 ON");
digitalWrite(in4, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
}
Vorosbor = 0;
}
if (Rosebor==1)
{
lcd.clear();
lcd.print(pump4ml);
lcd.print("ml");
delay((pump2ml/12)*1000);
digitalWrite(in4, HIGH);
digitalWrite(in9, LOW);
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 5 ON");
digitalWrite(in5, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
}
Rosebor = 0;
}
if (Narancs==1)
{
lcd.clear();
lcd.print(pump5ml);
lcd.print("ml");
delay((pump2ml/12)*1000);
digitalWrite(in5, HIGH);
digitalWrite(in9, LOW);
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 6 ON");
digitalWrite(in6, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
}
Narancs = 0;
}
if (Cola==1)
{
lcd.clear();
lcd.print(pump6ml);
lcd.print("ml");
delay((pump2ml/12)*1000);
digitalWrite(in6, HIGH);
digitalWrite(in9, LOW);
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 7 ON");
digitalWrite(in7, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
}
Cola = 0;
}
if (Bodza==1)
{
lcd.clear();
lcd.print(pump7ml);
lcd.print("ml");
delay((pump2ml/12)*1000);
digitalWrite(in7, HIGH);
digitalWrite(in9, LOW);
delay(2000);
weight = scale.read();
delay(100);
lcd.clear();
lcd.print("Pump 8 ON");
digitalWrite(in8, LOW);
digitalWrite(in9, HIGH);
while (scale.read() - weight < 3000) {
}
Bodza = 0;
}
if (Whisky)
{
lcd.clear();
lcd.print(pump8ml);
lcd.print("ml");
delay((pump3ml/12)*1000);
digitalWrite(in8, HIGH);
digitalWrite(in9, LOW);
delay(2000);
changestate = 0;
}
Whisky = 0;
}
}
}
}
Your description is poor! Read the forum guidelines. Give people a clue so they can help you. Your code is incomplete. How do your while loops exit?
I'm sitting here looking at the last line of text thinking..... that is so wrong.
Whiskey = 0
Wrong i say just wrong.
I think it should be
Whiskey = !0
d_r_l00:
First, I accidentally submitted the wrong code. This code is present in Arduino. But it still doesn't work the way it should.
That is not a complete sketch. If the complete sketch is too large to put in a post, upload it as an attachment.
The pieces of sketch that you have posted have been written by a beginner. They are very inefficient and it sounds like they don't do what you want them to do anyway. You might be better off starting from nothing!
This is the full code.
Koktélgép.txt (9.51 KB)
d_r_l00:
But it still doesn't work the way it should.
Ok. What does it do?
I'm sorry to say but that sketch is a disaster. It uses sets of 8 variables instead of arrays of variables. This makes the code far longer than it needs to be.
For each fluid it appears to be turning on a pump for 1 second per 11 ml and ALSO checking the weight of something until it gains at least 3000 units. Is this supposed to dispense by time or by weight?!? Since you have the scale hardware I would think weight would be more reliable.
With a few arrays the whole dispensing of fluids could be done in one fairly small function:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <HX711.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
enum FluidTypes {Vodka, Jager, Vorosbor, Rosebor, Narancs, Cola, Bodza, Whisky, FluidCount};
const char *FluidNames[FluidCount] = {"Vodka", "Jager", "Vorosbor", "Rosebor", "Narancs", "Cola", "Bodza", "Whisky"};
int FluidWeight[FluidCount]; // Amount to dispense
const byte FluidPumpPins[FluidCount] = {5, 6, 7, 8, 9, 10, 11, 12};
boolean FluidFlags[FluidCount];
HX711 scale;
const byte HX711_DOUT = A0; // DT
const byte HX711_CLK = A1; // SCK
void setup()
{
scale.begin(HX711_DOUT, HX711_CLK);
scale.set_scale();
scale.tare(); //Reset the scale to 0
lcd.begin(16, 2);
for (int fluid = 0; fluid < FluidCount; fluid++)
{
digitalWrite(FluidPumpPins[fluid], HIGH);
pinMode(FluidPumpPins[fluid], OUTPUT);
}
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
}
void loop()
{
}
void DispenceFluids()
{
for (int fluid = 0; fluid < FluidCount; fluid++)
{
if (FluidWeight[fluid] <= 0)
continue; // Skip this fluid since no weight is to be dispensed
long startWeight = scale.read();
lcd.clear();
lcd.print(FluidNames[fluid]);
lcd.print(" Pump ON");
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(FluidPumpPins[fluid], LOW); // Pump On
// Wait for the desired dispence weight
long w;
while ((w = scale.read() - startWeight) < FluidWeight[fluid])
{
lcd.setCursor(1, 1);
lcd.print(w);
lcd.print(" of ");
lcd.print(FluidWeight[fluid]);
lcd.print(" dispenced. ");
}
digitalWrite(FluidPumpPins[fluid], HIGH); // Pump Off
digitalWrite(LED_BUILTIN, LOW);
lcd.clear();
lcd.print(FluidNames[fluid]);
lcd.print(" Pump Off");
delay(2000);
}
}
The point is, if I set 0ml for all 8 drinks, the program won’t start. Only if one of the 8 volumes is greater than 0 ml.
d_r_l00:
The point is, if I set 0ml for all 8 drinks, the program won’t start. Only if one of the 8 volumes is greater than 0 ml.
As I said: total disaster. You would probably be better off starting from scratch.
I wonder what it does if you set the volume negative.
d_r_l00:
The point is, if I set 0ml for all 8 drinks, the program won’t start. Only if one of the 8 volumes is greater than 0 ml.
Sounds like it's working as designed. If you ask for a drink with nothing in it, it delivers!
Or do you mean that you can't make selections unless there's something already pre-selected?
It only gives the drink to which I give all the quantities. Because now if 0 is the quantity it still turns on.
Hi I have the final code that works. My question would be how to load the load cell into the program. To weight off not on time.
#include<LCD.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
#define pinNums 8
int pins[pinNums] = {5, 6, 7, 8, 9, 10, 11, 12};
int enablePin = 13;
volatile boolean TurnDetected;
volatile boolean up;
bool doonce = 0;
char screen = 0;
boolean changestate = false; // nem nulla, hanem false! Megérti így is, de te viszont belekavarodhatsz!
char serialReceived;
int calibrations[pinNums] = {100, 100, 100, 100, 100, 100, 100, 100 };
//float modifier = 1000; // korrekciós tényező az adagolás idejéhez
#define VODKA 0
#define JAGER 1
#define VOROSBOR 2
#define ROSEBOR 3
#define NARANCS 4
#define COLA 5
#define BODZA 6
#define WHISKEY 7
#define sw 4
#define clk 3
#define dt 2
#define UPPERLIMIT 100
#define ITALOK 9
int volumes[ITALOK]; // ebben tároljuk az italok mennyiségét
String names[ITALOK] = {"Vodka", "Jager", "Vorosbor", "Rose bor", "Narancs", "Cola", "Bodza", "Whiskey", ""}; // ebben tároljuk a neveket
void isr0 () {
TurnDetected = true;
up = (digitalRead(clk) == digitalRead(dt));
}
void setup() {
// Serial.begin(115200);
lcd.begin(16, 2);
pinMode(sw, INPUT_PULLUP);
pinMode(clk, INPUT);
pinMode(dt, INPUT);
attachInterrupt (0, isr0, RISING);
for (int i = 0; i < pinNums; i++)
{
pinMode(pins[i], OUTPUT);
digitalWrite(pins[i], HIGH);
}
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, LOW);
lcd.print("Start");
}
void turned()
{
if (TurnDetected)
{
doonce = 0;
if (!changestate)
{
if (up)
{
screen++;
if (screen >= ITALOK - 1) screen = ITALOK - 1 ;
}
else
{
screen --;
if (screen < 0) screen = 0;
}
}
else
{
if (up)
{
switch (screen)
{
case 0: volumes[0] += 10; break;
case 1: volumes[1] += 10; break;
case 2: volumes[2] += 10; break;
case 3: volumes[3] += 10; break;
case 4: volumes[4] += 25; break;
case 5: volumes[5] += 25; break;
case 6: volumes[6] += 25; break;
case 7: volumes[7] += 10; break;
case 8: // start menüpont
default: break;
}
if (volumes[screen] > UPPERLIMIT)
volumes[screen] = UPPERLIMIT;
}
else
{
switch (screen)
{
case 0: volumes[0] -= 10; break;
case 1: volumes[1] -= 10; break;
case 2: volumes[2] -= 10; break;
case 3: volumes[3] -= 10; break;
case 4: volumes[4] -= 25; break;
case 5: volumes[5] -= 25; break;
case 6: volumes[6] -= 25; break;
case 7: volumes[7] -= 10; break;
case 8: // start menüpont
default: break;
}
if (volumes[screen] < 0)
volumes[screen] = 0;
}
}
}
TurnDetected = false;
}
void drinkDisplay(char screen)
{
lcd.clear();
lcd.print(names[screen]);
lcd.print(" ");
if (screen < ITALOK - 1)
{
lcd.print(volumes[screen]);
lcd.print("ml");
doonce = 1;
}
else lcd.print("");
if (changestate == false)
{
lcd.setCursor(9,1);
lcd.print("Change?");
}
}
void loop()
{
turned();
if (serialReceived == 'b' || digitalRead(sw) == LOW)
// if (serialReceived == 'b') // if (digitalRead(sw) == LOW)
{
serialReceived = 0;
changestate = !changestate;
//changestate = true;
doonce = 0;
}
if (doonce == 0) drinkDisplay(screen);
if (doonce == 0 && screen == ITALOK - 1)
{
lcd.clear();
if (changestate == false)
{
lcd.print("Start?");
doonce = 1;
}
else {
lcd.print("Wait!");
delay(2000);
fill();
}
}
// olvasunk a soros portról.
// ha 'u' vagy 'd' karaktert kap, akkor az a rotary encoder forgatasa
// ha 'b' karaktert kap, akkor megnyomta a user a gombot.
if (Serial.available() > 0) // ha van miért, akkor
{
serialReceived = Serial.read(); // olvasunk egy byte-ot
if (serialReceived == 'u')
{
TurnDetected = true;
up = true;
serialReceived = 0;
}
if (serialReceived == 'd')
{
TurnDetected = true;
up = false;
serialReceived = 0;
}
}
}
void fill()
{
lcd.clear(); // lcd.clear();
for ( int i = 0; i < pinNums ; i++)
{
if (volumes[i] > 0)
{
lcd.print(names[i] + " ");
digitalWrite(pins[i], LOW);
digitalWrite(enablePin, HIGH);
lcd.print(volumes[i]);
lcd.println("ml");
delay(volumes[i] * calibrations[i]);
// delay(volumes[i] * modifier);
digitalWrite(pins[i], HIGH);
digitalWrite(enablePin, LOW);
}
}
doonce = 0;
screen = 0;
// mivel már kitöltöttük, töröljük a mennyiségeket
for (int i = 0; i < ITALOK; i++)
volumes[i] = 0;
changestate = false;
lcd.print("Done.");
delay(2000);
}