/**************************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
This example is for a 128x64 pixel display using I2C to communicate
3 pins are required to interface (two I2C and one reset).
Adafruit invests time and resources providing this open
source code, please support Adafruit and open-source
hardware by purchasing products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries,
with contributions from the open source community.
BSD license, check license.txt for more information
All text above, and the splash screen below must be
included in any redistribution.
**************************************************************************/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Keypad.h>
#include <EEPROM.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
static const unsigned char PROGMEM logo_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };
// 1keypad
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String inputString;
String inputStringA;
String inputStringB;
String inputStringC;
long inputInt;
long inputIntA;
long inputIntB;
long inputIntC;
String cofStr;
long cofInt;
long wat;
long valAddr = 0;
// 1keypad
void setup() {
Serial.begin(9600);
inputString.reserve(10); // maximum number of digit for a number is 10, change if needed
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.clearDisplay();
delay(500);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println(F("Coffee\nSnobs"));
display.display();
delay(3000);
display.clearDisplay();
display.setTextSize(1.6);
display.setCursor(0,0);
display.println(F("Coffee Snob Setup"));
display.display();
display.setTextSize(1);
display.setCursor(0,10);
display.println(F("A = Coffee Setup"));
display.println(F("B = Brewing Ratios"));
display.println(F("C = Brew Recipe"));
display.println(F("D = Start"));
display.println(F("# = Enter"));
display.println(F("* = Setup Page"));
display.display();
}
void loop() {
char key = keypad.getKey();
if (key) {
Serial.println(inputString);
//display.println(inputString);
//display.display();
if (key >= '0' && key <= '9') { // only act on numeric keys
inputString += key; // append new character to input string
} else if (key == '#') {
if (inputString.length() > 0) {
inputInt = inputString.toInt(); // YOU GOT AN INTEGER NUMBER
inputString = "";
// clear input
// DO YOUR WORK HERE
display.println(inputInt);
display.display();
}
} else if (key == 'A') {
buttonA();
} else if (key == 'B') {
buttonB();
}else if (key == 'C') {
buttonC();
}else if (key == 'D') {
buttonD();
}
}
}
void buttonA (){
char key = keypad.getKey();
inputStringA = "";
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0,0);
display.println(F("How muh coffee did you ground?"));
display.display(); // clear input
if (key >= '0' && key <= '9') { // only act on numeric keys
inputStringA += key; // append new character to input string
} else if (key == '#') {
if (inputStringA.length() > 0) {
cofStr = inputStringA;
cofInt = inputStringA.toInt();
inputIntA = inputStringA.toInt(); // YOU GOT AN INTEGER NUMBER
return (inputStringA);
display.println(inputIntA); // print coffee amount
display.display();
}
}
}
void buttonB (){
char key = keypad.getKey();
inputStringA = "";
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0,0);
display.println(F("What is your brewing ratio?"));
display.display(); // clear input
if (key >= '0' && key <= '9') { // only act on numeric keys
inputStringB += key; // append new character to input string
} else if (key == '#') {
if (inputStringB.length() > 0) {
inputIntB = inputStringB.toInt(); // YOU GOT AN INTEGER NUMBER
return inputIntB;
display.println(inputIntB); // print coffee amount
display.display();
inputStringB = "";
}
}
}
void buttonC (){
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0,0);
//cof = EEPROM.read(valAddr)*4;
display.print("Brewing Recipe: ");
display.println(cofInt);
Serial.print("My variable is: ");
Serial.println(cofInt);
display.display();// clear input
}
void buttonD (){
display.clearDisplay();
Serial.println(inputIntA);
Serial.println(cofInt);
Serial.println(inputStringA);
display.display();// clear input
}