/*
Created by ArduinoGetStarted.com
This example code is in the public domain
Tutorial page: https://arduinogetstarted.com/faq/how-to-input-a-multiple-digits-number-using-the-keypad
*/
#include <SPI.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 4; //four columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
String inputString;
String inputStringA;
String inputStringB;
String inputStringC;
String inputStringD;
int inputInt = 0;
long GrindAmount;
long WaterRatio;
long BrewAmount;
long inputIntD = 0;
int IntCountA = 0;
boolean Step1 = true;
boolean Step2 = false;
boolean Step3 = false;
boolean Step4 = false;
boolean Step5 = false;
boolean Step6 = false;
//int BrewAmount = 0;
//long P1;
//long P2;
//int P3;
//int P4;
//int P5;
int Rest1 = 10000;
int Rest2 = 10000;
int Rest3 = 10000;
int Rest4 = 10000;
int Rest5 = 10000;
float dripratio1 = .235;
float dripratio2 = .19125;
float pumprate = 7.4;
int waittime = 1000;
int button;
int brew = 0;
//char key;
char keyA;
char keyB;
char key;
void setup() {
Serial.begin(9600);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(7, 0);
lcd.println("Hello");
lcd.setCursor(3, 1);
lcd.println("Coffee Snobs");
lcd.display();
delay(100); // DELAY //
lcd.setCursor(4, 2);
lcd.println("Lets make a");
lcd.setCursor(0, 3);
lcd.println("Great cup of Coffee");
lcd.display();
delay(500); // DELAY //
lcd.clear();
lcd.setCursor(0, 0);
lcd.println("How much coffee did");
lcd.setCursor(0, 1);
lcd.println("you grind?");
lcd.setCursor(0, 3);
lcd.print("Press # to log");
}
void loop() {
char key = keypad.getKey();
if (key >= '0' && key <= '9')// only act on numeric keys
{
inputString += key; // append new character to input string
}
else if (key == '#') {
if (Step4) { //IntCountA = IntCountA +1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.println("Step 4");
lcd.display();
lcd.setCursor(0, 1);
float P1 = (dripratio1 * BrewAmount);
float P2 = (P1 / pumprate);
float P3 = (P2 * waittime);
lcd.print("Coffee Setup: ");
lcd.print(P1);
lcd.setCursor(0, 2);
lcd.println(P2);
lcd.setCursor(0, 3);
lcd.println(P3);
//lcd.print("g");
//lcd.setCursor(0, 2);
//lcd.print("Brewing Ratios: 1/");
//lcd.print(WaterRatio);
//lcd.setCursor(0, 2);
//lcd.print("Brew Recipe: ");
//lcd.print(BrewAmount);
//lcd.print("ml");
lcd.display();
Step4 = false;
}
if (Step3) { //IntCountA = IntCountA +1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.println("Coffee Snob Recipe");
lcd.display();
lcd.setCursor(0, 1);
BrewAmount = (GrindAmount * WaterRatio);
lcd.print("Coffee Setup: ");
lcd.print(GrindAmount);
lcd.print("g");
lcd.setCursor(0, 2);
lcd.print("Brewing Ratios: 1/");
lcd.print(WaterRatio);
lcd.setCursor(0, 2);
lcd.print("Brew Recipe: ");
lcd.print(BrewAmount);
lcd.print("ml");
lcd.println();
lcd.display();
Step3 = false;
Step4 = true;
}
if (inputString.length() > 0) {
if (Step2) {
WaterRatio = inputString.toInt(); // YOU GOT AN INTEGER NUMBER
inputString = "";// clear input
Serial.println(WaterRatio);
lcd.setCursor(0, 2);
lcd.print("1/");
lcd.print(WaterRatio);
lcd.print("oz");
lcd.display();
Step2 = false;
Step3 = true;
delay(1000);
lcd.clear();
lcd.display();
lcd.setCursor(0, 0);
lcd.print("Press # to view");
lcd.setCursor(0, 1);
lcd.print("Brew Recipe");
lcd.display();
Serial.println(Step2);
Serial.println(Step3);
}
if (Step1) {
GrindAmount = inputString.toInt(); // YOU GOT AN INTEGER NUMBER
inputString = "";// clear input
Serial.println(GrindAmount);
lcd.setCursor(0, 2);
lcd.print(GrindAmount);
lcd.print("grams");
lcd.display();
Step1 = false;
Step2 = true;
delay(1000);
lcd.clear();
lcd.display();
lcd.setCursor(0, 0);
lcd.println("What is your ");
lcd.setCursor(0, 1);
lcd.println("brew ratio?");
lcd.setCursor(0, 3);
lcd.print("Press # to log");
lcd.display();
Serial.println(Step1);
Serial.println(Step2);
}
}
}
if (key == '*') {
Serial.println("Clear");
lcd.clear();
Step1 = true;
Step2 = false;
Step3 = false;
Step4 = false;
setup();
}
}