// Include the library code
#include <Wire.h> // needed for I2C communication
#include <LiquidCrystal_I2C.h> // LCD with I2C adapter
#include <rotary.h> // rotary handler
#include <hx711.h>
Hx711 scale(A1, A0); // Hx711.DOUT - pin #A1
// Hx711.SCK - pin #A0
//****************Zutaten*******************
//0.X.
int PU_LER = 26; //0.1. 2 LEER
int PU_Teq = 28; //0.2. 3 Tequila
//1.X.
int PU_ZSiru = 30; //1.1. 5 Zuckersirup
int PU_MSiru = 32; //1.2. 6 Mandelsirup
int PU_Rum = 34; //1.3. 7 Rum
int PU_GSiru = 36; //1.4. 8 Grenadinsirup
//2.X
int PU_ASaft = 38; //2.4. 13 Ananassaft
int PU_ZSaft = 40; //2.3. 14 Zitronensaft
int PU_MSaft = 42; //2.2. 15 Maracujasaft
int PU_OSaft = 44; //2.1. 16 Orangensaft
//****************Rezepte*******************
//RezeptA Tequila Sunrise
int A_Teq = 70; // 70g Tequila
int A_OSaft = 325; // +225g Orangensaft
int A_GSiru = 345; // + 20g Grenadinsirup
//RezeptB Maitai
int B_Rum = 100; // 100g Rum
int B_ZSiru = 130; // + 30g Zuckersirup
int B_MSiru = 160; // + 30g Mandelsirup
int B_ASaft = 345; // +185g Ananassaft
//RezeptC Acapulco
int C_Rum = 80; // 80g Rum
int C_Teq = 130; // + 50g Tequila
int C_ZSaft = 175; // + 45g Zitronensaft
int C_OSaft = 250; // + 75g Orangensaft
int C_ASaft = 325; // + 75g Ananassaft
int C_GSiru = 345; // + 20g Grenadinsirup
//***********Zuordnung Gläser***************
int glasvoll = 345; // Inhalt Gesamt
int glasleer = 42; // Leeres Glas
//**************Allgemeines*****************
int AN = LOW; //An
int AUS = HIGH; //Aus
int gewicht; //aktuelles Gewicht
int nullstellung = 0; //Null (0)
boolean changestate = 0;
long weight;
volatile boolean TurnDetected;
volatile boolean up;
bool doonce = 0;
char screen = 0;
int b (scale.getGram());
// Initialize the Rotary object
// Rotary(Encoder Pin 1, Encoder Pin 2, Button Pin) Attach center to ground
Rotary r = Rotary(3, 4, 2); // there is no must for using interrupt pins !!
// Half-step mode
#define HALF_STEP
// Define I2C_LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Define your cocktail information
int maxNumber = 3;
char* myCocktails[] = {
"Tequila Sunrise",
"Maitai",
"Acapulco",
};
int x = 0;
void setup() {
//initialize serial and wait for port to open :
Serial.begin(9600); // only for debugging, comment out later
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Initialized");
Serial.println();
//*******Definition Pumpe *********
pinMode(PU_Teq,OUTPUT);
pinMode(PU_LER,OUTPUT);
pinMode(PU_Rum,OUTPUT);
pinMode(PU_OSaft,OUTPUT);
pinMode(PU_ASaft,OUTPUT);
pinMode(PU_ZSaft,OUTPUT);
pinMode(PU_MSaft,OUTPUT);
pinMode(PU_GSiru,OUTPUT);
pinMode(PU_ZSiru,OUTPUT);
pinMode(PU_MSiru,OUTPUT);
digitalWrite(PU_Teq, AUS);
digitalWrite(PU_LER, AUS);
digitalWrite(PU_Rum, AUS);
digitalWrite(PU_OSaft, AUS);
digitalWrite(PU_ASaft, AUS);
digitalWrite(PU_ZSaft, AUS);
digitalWrite(PU_MSaft, AUS);
digitalWrite(PU_GSiru, AUS);
digitalWrite(PU_ZSiru, AUS);
digitalWrite(PU_MSiru, AUS);
lcd.begin();
lcd.clear (); // go home
lcd.print ("Barboot");
lcd.setCursor(0, 1);
lcd.print("Please Select");
delay(2000);
//lcd.backlight(); // only needed for 0x3F I2C Adapter
// ------- Quick 3 blinks of backlight -------------
blinkLCD();
char lcdline1[13];
sprintf (lcdline1, "Cocktail #: %02i", x + 1); // index starts at 0
lcd.setCursor(0, 0);
lcd.print (lcdline1);
lcd.setCursor(0, 1);
lcd.print(" "); // erase previous content
lcd.setCursor(0, 1);
lcd.print(myCocktails[x]);
}
void loop() {
volatile unsigned char result = r.process();
if (result) {
result == DIR_CCW ? x = x - 1 : x = x + 1;
if (x < 0) { // no values < 0; later: use unsigned int
blinkLCD();
x = maxNumber - 1; // roll over
}
if (x > maxNumber - 1) { // no more strings
// ------- Quick 3 blinks of backlight -------------
blinkLCD();
x = 0; // roll over
}
char lcdline1[13];
sprintf (lcdline1, "Cocktail #: %02i", x + 1);
lcd.setCursor(0, 0);
lcd.print (lcdline1);
lcd.setCursor(0, 1);
lcd.print(" "); // erase previous content
lcd.setCursor(0, 1);
lcd.print(myCocktails[x]);
}
if (r.buttonPressedReleased(25)) {
switch (x) {
case 0:
//lcdScreen1();
Cocktail_1(); // Start der Produktion
break;
case 1:
lcdScreen1();
Cocktail_2(); // Start der Produktion
break;
case 2:
//lcdScreen1();
Cocktail_3(); // Start der Produktion
break;
}
blinkLCD();
lcd.clear (); // go home
lcd.print ("****Barboot****");
lcd.setCursor(0, 1);
lcd.print("Drink is ready!"); //
delay(3000);
//lcd.backlight(); // only needed for 0x3F I2C Adapter
// ------- Quick 3 blinks of backlight -------------
blinkLCD();
x = 0; // reset to start position
lcd.clear();
char lcdline1[13];
sprintf (lcdline1, "Cocktail #: %02i", x + 1);
lcd.print (lcdline1);
lcd.setCursor(0, 1);
lcd.print(myCocktails[x]);
}
}
// #################### Functions ###################
void blinkLCD() {
for (int i = 0; i < 3; i++)
{
lcd.noBacklight();
delay(50);
lcd.backlight();
delay(50);
}
}
void lcdScreen1() { // instead of the real mixing process, just for demo
lcd.setCursor(0, 0);
lcd.print("Now Mixing of ");
// scroll 13 positions (string length) to the left
// to move it offscreen left:
for (int positionCounter = 0; positionCounter < 10; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(250);
}
// scroll 29 positions (string length + display length) to the right
// to move it offscreen right:
for (int positionCounter = 0; positionCounter < 20; positionCounter++) {
// scroll one position right:
lcd.scrollDisplayRight();
// wait a bit:
delay(250);
}
}