#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Keypad.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
// LCD
#define SCREEN_WIDTH 128 // Change this to your display's width (usually 128 pixels)
#define SCREEN_HEIGHT 64 // Change this to your display's height (usually 64 pixels)
#define OLED_RESET -1 // Reset pin # (or -1 if not used)
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Bitmap icon
// main icon
const unsigned char icon [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x07, 0x80, 0x00, 0x00, 0x00, 0x07, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1f, 0xc0, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3f, 0xe0, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1f, 0xf0, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7f, 0xf8, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xfc, 0x00, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3f, 0xfc, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7f, 0xfe, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7f, 0xff, 0x80, 0x00, 0x01, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1f, 0xff, 0xe0, 0x00, 0x03, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3f, 0xff, 0xff, 0x00, 0x07, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3f, 0xff, 0xff, 0xf8, 0x0f, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7f, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3f, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1f, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0f, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x07, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x07, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0xf8, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x08, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x03, 0xfc, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x8c, 0x0f, 0xff, 0xc2, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x8e, 0x18, 0x7f, 0xff, 0x1e, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0f, 0xc4, 0xc3, 0xee, 0x3e, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xf3, 0xfe, 0x08, 0x60, 0x1e, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x73, 0x7f, 0x08, 0x00, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x06, 0x28, 0x0d, 0xfe, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'humidity icon', 20x20px
const unsigned char humidity_icon [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x90, 0x00, 0x00, 0x90, 0x00, 0x01, 0x08, 0x00, 0x01,
0x08, 0x00, 0x02, 0x04, 0x00, 0x02, 0x04, 0x00, 0x04, 0x02, 0x00, 0x04, 0x82, 0x00, 0x09, 0x49,
0x00, 0x09, 0x51, 0x00, 0x10, 0x20, 0x80, 0x10, 0x40, 0x80, 0x10, 0x58, 0x80, 0x10, 0xa8, 0x80,
0x09, 0x29, 0x00, 0x04, 0x02, 0x00, 0x02, 0x04, 0x00, 0x01, 0xf8, 0x00
};
// 'temperature icon', 20x20px
const unsigned char temperature_icon [] PROGMEM = {
0x01, 0xc0, 0x00, 0x02, 0x26, 0x00, 0x02, 0x10, 0x00, 0x02, 0x90, 0x00, 0x02, 0x9c, 0x00, 0x02,
0x90, 0x00, 0x02, 0x96, 0x00, 0x02, 0x90, 0x00, 0x02, 0x90, 0x00, 0x02, 0x90, 0x00, 0x02, 0x90,
0x00, 0x02, 0x96, 0x00, 0x02, 0x90, 0x00, 0x04, 0x80, 0x00, 0x05, 0xc8, 0x00, 0x01, 0xe8, 0x00,
0x05, 0xe8, 0x00, 0x04, 0xc8, 0x00, 0x02, 0x10, 0x00, 0x01, 0xe0, 0x00
};
// 'light_icon', 20x20px
const unsigned char light_icon [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x21,
0x08, 0x40, 0x00, 0x10, 0x00, 0x00, 0x02, 0x00, 0x04, 0x06, 0x00, 0x04, 0x02, 0x00, 0x04, 0x02,
0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00
};
// 'waterlvl_icon', 20x20px
const unsigned char waterlvl_icon [] PROGMEM = {
0xfc, 0x04, 0x00, 0x84, 0x0e, 0x00, 0x9c, 0x1f, 0x00, 0x9c, 0x64, 0xc0, 0x84, 0xf4, 0xe0, 0x8c,
0xc4, 0x40, 0x84, 0x44, 0x40, 0xbc, 0x44, 0x40, 0x84, 0x44, 0x40, 0x8c, 0x40, 0x40, 0x8c, 0x40,
0x40, 0x84, 0x40, 0x40, 0xbc, 0x00, 0x00, 0x84, 0x96, 0x90, 0x8f, 0xff, 0xf0, 0x85, 0x69, 0x60,
0x9c, 0x80, 0x10, 0x9e, 0x96, 0x90, 0x87, 0xff, 0xe0, 0xfc, 0x00, 0x00
};
// 'food_icon', 20x20px
const unsigned char food_icon [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0xf1, 0xc0, 0x3f, 0xff, 0xc0, 0x1f, 0xff, 0x80, 0x1f,
0xff, 0x80, 0x1f, 0x0f, 0x80, 0x1f, 0x07, 0x80, 0x1f, 0x8f, 0x80, 0x1f, 0x0f, 0x80, 0x1f, 0x07,
0x80, 0x1f, 0x07, 0x80, 0x1e, 0x87, 0x80, 0x1e, 0x87, 0x80, 0x1f, 0xff, 0x80, 0x1f, 0xff, 0x80,
0x3f, 0xff, 0xc0, 0x38, 0xf1, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// Define the keypad layout and pins
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {13, 12, 14, 27};
byte colPins[COLS] = {26, 25, 33, 32};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// flags
volatile unsigned int choice;
volatile unsigned short menu_page;
volatile unsigned short progress;
// variables
volatile unsigned int chicken;
volatile bool humidity_act;
volatile bool temp_act;
volatile bool light_act;
volatile bool water_act;
volatile bool food_act;
// display main menu
void display_menu (){
display.setCursor(0, 0);
display.print("Main Menu");
display.setCursor(0, 30);
display.println("1) Poultry Condition");
display.println("2) Chicken Condition");
display.display(); // Show the updated display
}
// display menu 1
void menu_1(){
display.setCursor(0, 0);
display.print("Menu 1");
display.display(); // Show the updated display
}
// display menu 2
void menu_2(){
display.setCursor(0, 0);
display.print("Menu 2");
display.display(); // Show the updated display
}
// display user choice at lower bottom
void show_choice (char user_choice) {
display.setCursor(70, 52);
display.print("Choice:");
display.print(user_choice);
display.display(); // Show the updated display
// delay(100);
}
// sys initialisation
void setup() {
Serial.begin(115200);
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
// variable initialisation (may wrong)
humidity_act = false;
temp_act = false;
light_act = false;
water_act = false;
food_act = false;
// Initialise adafruit oled library
display.display(); // Clear the display buffer
delay(100); // Delay to let OLED hardware initialize
display.clearDisplay(); // Clear the display
display.display(); // Show the cleared display
// Text settings
display.setTextSize(0.5); // Text size (adjust as needed)
display.setTextColor(SSD1306_WHITE); // Text color (SSD1306_WHITE for white)
display.setCursor(0, 0); // Set the text cursor position
// startup page
display.drawBitmap(0, 0, icon, 128, 64, SSD1306_WHITE);
display.setCursor(66, 0);
display.print("Poultry");
display.setCursor(66, 9);
display.print("Farm");
display.setCursor(66, 18);
display.print("Monitoring");
display.setCursor(66, 27);
display.print("System");
display.display();
delay(4000);
}
void loop() {
// check key
char key = keypad.getKey();
// const char* key1 = &key;
// Progress = 0 because at main menu
progress = 0;
// display menu
display.clearDisplay(); // Clear the display
display_menu();
if (key) {
// Serial.println(key);
display.clearDisplay(); // Clear the display
display_menu();
// delay(100);
show_choice(key);
choice = key - '0'; //convert from aschii to deci
// 'A' to enter, 'D' to delete
while (key != 'A'){
char key = keypad.getKey();
if (key =='D'){
progress = 0;
break;
}
else if (key =='A'){
progress = 1;
break;
}
}
// if user confirm choice, proceed to progress 1
while (progress == 1){
char key = keypad.getKey();
// if user select menu 1
if (choice == 1){
menu_page = 1;
display.clearDisplay(); // Clear the display
menu_1();
progress = 2; //proceed to next progress
// delay(2000);
}
// if user select menu 1
else if (choice == 2){
menu_page = 2;
display.clearDisplay(); // Clear the display
menu_2();
progress = 2; //proceed to next progress
// delay(2000);
}
else{
char temp;
display.clearDisplay(); // Clear the display
display.setCursor(0, 20);
display.print("Invalid choice: ");
temp = choice + '0';
display.print(temp);
display.display(); // Show the updated display
delay(2000);
progress = 0; //return to progress 0
break;
}
// //press "B" to go back
// if (key=='B'){
// progress = 0; //return to progress 0
// break;
// }
}
// proceed to progress 2, either menu1 or menu2
while (progress==2){
// if menu 1 is selected
if (menu_page==1){
display.clearDisplay(); // Clear the display
// display Humidity
display.setCursor(0, 0);
display.print("1)Hum:");
display.print("77"); // to be changed later
display.print("%");
// display Temperature
display.setCursor(64, 0);
display.print("2)Tem:");
display.print("36"); // to be changed later
display.print("C");
// display Light intensity
display.setCursor(0, 20);
display.print("3)Lig:");
display.print("77"); // to be changed later
display.print("%");
// display Water Level
display.setCursor(64, 20);
display.print("4)H20:");
display.print("77"); // to be changed later
display.print("%");
// display Food Level
display.setCursor(0, 40);
display.print("5)Fd :");
display.print("77"); // to be changed later
display.print("%");
display.display(); // Show the updated display
char key = keypad.getKey();
// humidity menu
if (key=='1'){
progress = 3;
menu_page = 11;
break;
}
// temperature menu
else if (key=='2'){
progress = 3;
menu_page = 12;
break;
}
// light intensity menu
else if (key=='3'){
progress = 3;
menu_page = 13;
break;
}
// water level menu
else if (key=='4'){
progress = 3;
menu_page = 14;
break;
}
// food level menu
else if (key=='5'){
progress = 3;
menu_page = 15;
break;
}
// press 'B' to return
else if (key == 'B'){
show_choice(key);
progress = 0;
menu_page = 0;
delay(1000);
break;
}
}
else if (menu_page == 2){
// Promt user to select number of chicken
display.clearDisplay(); // Clear the display
display.clearDisplay(); // Clear the display
display.setCursor(0, 0);
display.print("Select Chicken:");
display.display(); // Show the updated display
//necessary variable for menu 2
char temp[1];
unsigned short counter = 0;
while (1){
char key = keypad.getKey();
// Serial.println(counter);
// Serial.println(temp[0]);
// Serial.println(temp[1]);
// Serial.println(temp[2]);
if ((key=='0'||key=='1'||key=='2'||key=='3'||key=='4'||key=='5'||key=='6'||key=='7'||key=='8'||key=='9')&&counter<1){
temp[counter]=key;
display.setCursor(32+counter*7, 30);
display.print(key);
display.display();
delay(200);
counter ++;
}
// press "A" to proceed to next
else if (key == 'A'){
//proceed to next progress
chicken = atoi(temp);
progress = 3;
menu_page = 21;
break;
}
// press "D" to delete
else if (key == 'D'){
if(counter > 0){
char temp[1]; //clear temp char
counter = 0 ; //reset counter
display.clearDisplay(); // Clear the display
display.setCursor(0, 0);
display.print("Select Chicken:");
display.display(); // Show the updated display
}
}
// press 'B' to return
else if (key == 'B'){
progress = 0;
menu_page = 0;
delay(500);
break;
}
}
// press 'B' to return
if (key == 'B'){
progress = 0;
menu_page = 0;
delay(500);
break;
}
}
}
// proceed to progress next page of menu 1 or menu 2
while (progress == 3){
// humidity menu
while(menu_page == 11){
display.clearDisplay(); // Clear the display
display.drawBitmap(0, 0, humidity_icon, 20, 20, SSD1306_WHITE);
display.setCursor(25, 0);
display.print("Humidity ");
display.print("77"); // to be changed later
display.print("%");
display.setCursor(25, 15);
display.print("Actuator is ");
if (humidity_act==true) display.print("on");// to be changed later
else display.print("off");// to be changed later
display.setCursor(0, 30);
display.print("Press 'C' to toggle");
display.display(); // Show the updated display
char key = keypad.getKey();
// press 'C' to toggle actuator
if (key == 'C'){
if(!humidity_act) humidity_act=true;
else humidity_act=false;
}
// press 'B' to return
if (key == 'B'){
progress = 0;
menu_page = 0;
delay(500);
break;
}
}
// temperature menu
while(menu_page == 12){
display.clearDisplay(); // Clear the display
display.drawBitmap(0, 0, temperature_icon, 20, 20, SSD1306_WHITE);
display.setCursor(25, 0);
display.print("Temperature ");
display.print("36"); // to be changed later
display.print("C");
display.setCursor(25, 15);
display.print("Actuator is ");
if (temp_act==true) display.print("on");// to be changed later
else display.print("off"); // to be changed later
display.setCursor(0, 30);
display.print("Press 'C' to toggle");
display.display(); // Show the updated display
char key = keypad.getKey();
// press 'C' to toggle actuator
if (key == 'C'){
if(!temp_act) temp_act=true;
else temp_act=false;
}
// press 'B' to return
if (key == 'B'){
progress = 0;
menu_page = 0;
delay(500);
break;
}
}
// light menu
while(menu_page == 13){
display.clearDisplay(); // Clear the display
display.drawBitmap(0, 0, light_icon, 20, 20, SSD1306_WHITE);
display.setCursor(25, 0);
display.print("Light Int ");
display.print("77"); // to be changed later
display.print("%");
display.setCursor(25, 15);
display.print("Actuator is ");
if (light_act==true) display.print("on");// to be changed later
else display.print("off"); // to be changed later
display.setCursor(0, 30);
display.print("Press 'C' to toggle");
display.display(); // Show the updated display
char key = keypad.getKey();
// press 'C' to toggle actuator
if (key == 'C'){
if(!light_act) light_act=true;
else light_act=false;
}
// press 'B' to return
if (key == 'B'){
progress = 0;
menu_page = 0;
delay(500);
break;
}
}
// water menu
while(menu_page == 14){
display.clearDisplay(); // Clear the display
display.drawBitmap(0, 0, waterlvl_icon, 20, 20, SSD1306_WHITE);
display.setCursor(25, 0);
display.print("H20 Lvl ");
display.print("77"); // to be changed later
display.print("%");
display.setCursor(25, 15);
display.print("Actuator is ");
if (water_act==true) display.print("on");// to be changed later
else display.print("off"); // to be changed later
display.setCursor(0, 30);
display.print("Press 'C' to toggle");
display.display(); // Show the updated display
char key = keypad.getKey();
// press 'C' to toggle actuator
if (key == 'C'){
if(!water_act) water_act=true;
else water_act=false;
}
// press 'B' to return
if (key == 'B'){
progress = 0;
menu_page = 0;
delay(500);
break;
}
}
// food menu
while(menu_page == 15){
display.clearDisplay(); // Clear the display
display.drawBitmap(0, 0, food_icon, 20, 20, SSD1306_WHITE);
display.setCursor(25, 0);
display.print("Food Lvl ");
display.print("77"); // to be changed later
display.print("%");
display.setCursor(25, 15);
display.print("Actuator is ");
if (food_act==true) display.print("on");// to be changed later
else display.print("off"); // to be changed later
display.setCursor(0, 30);
display.print("Press 'C' to toggle");
display.display(); // Show the updated display
char key = keypad.getKey();
// press 'C' to toggle actuator
if (key == 'C'){
if(!food_act) food_act=true;
else food_act=false;
}
// press 'B' to return
if (key == 'B'){
progress = 0;
menu_page = 0;
delay(500);
break;
}
}
while(menu_page == 21){
Serial.println(chicken);
display.clearDisplay(); // Clear the display
display.setCursor(30, 0);
display.print("Chicken ");
display.print(chicken);
display.display(); // Show the updated display
// press 'B' to return
char key = keypad.getKey();
if (key == 'B'){
progress = 0;
menu_page = 0;
delay(500);
break;
}
}
}
}
}