#include <Wire.h> //oled
#include <Adafruit_GFX.h> //oled
#include <Adafruit_SSD1306.h> //oled
#define button 2 //define button pin
#define relay_module 4
Adafruit_SSD1306 display(128,64,&Wire,-1); //library function
/********FUNCTION DEFINED********************/
void display_welcome_message();
bool detect_button();
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
display_welcome_message();
bool state = 1;
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
state = detect_button();
if(state == 0)
{
display_welcome_message();
}
}
void display_welcome_message()
{
if(!display.begin(SSD1306_SWITCHCAPVCC,0x3c))
{Serial.write("failed loading....");
while(true);
}
delay(1000);
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0,10);
display.setTextColor(WHITE);
display.println("WELCOME TO CAFE");
display.display();
delay(1000);
display.clearDisplay();
display.setCursor(0,10);
display.setTextColor(WHITE);
display.println("PRESS BUTTON TO START");
display.display();
}
bool detect_button()
{
bool state;
pinMode(button,INPUT);
state = digitalRead(button);
return state;
}
void relay(bool state)
{
pinMode(relay_module, OUTPUT);
digitalWrite(relay_module,state);
}