#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
int Input1 = 0;
int Input2 = 0;
int Output = 0;
int Pre_Input1 = -1;
int Pre_Input2 = -1;
int Pre_Output = -1;
unsigned long current = 0;
int Logic = 1;
int BUTTON = A0;
// AND Gate
const unsigned char andGate_72x42[] PROGMEM = {
  0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x01, 0xf0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00,
  0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00,
  0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
  0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00,
  0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x01, 0xf0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00
};
// OR Gate
const unsigned char orGate_72x42[] PROGMEM = {
  0x00, 0x1f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x0f, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x07, 0x80, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x01, 0x80, 0x07, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0xc0, 0x00, 0x1f, 0xc0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0xe0, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x70, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x38, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x1c, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00,
  0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00,
  0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00,
  0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00,
  0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00,
  0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
  0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00,
  0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00,
  0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff,
  0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff,
  0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00,
  0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00,
  0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
  0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
  0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00,
  0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00,
  0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x00,
  0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00,
  0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x38, 0x00, 0x00, 0x07, 0xf0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x70, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0xe0, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x01, 0xc0, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x03, 0x80, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x07, 0x80, 0x0f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x0f, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x1f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// NOT Gate
const unsigned char notGate_72x42[] PROGMEM = {
  0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00,
  0xff, 0xff, 0xfc, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00,
  0xff, 0xff, 0xfc, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x1f, 0x87, 0xc0, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x07, 0xef, 0xe0, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0xfe, 0x70, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x3f, 0xff,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0xff,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0xfe, 0x70, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0f, 0xcf, 0xe0, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x3f, 0x07, 0xc0, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00,
  0xff, 0xff, 0xfc, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00,
  0xff, 0xff, 0xfc, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// NAND Gate
const unsigned char nandGate_72x42[] PROGMEM = {
  0x00, 0x00, 0x3f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x3f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
  0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00,
  0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xff, 0x80, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xe0, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x7f, 0xff,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x7f, 0xff,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x60, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xe0, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xff, 0x80, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00,
  0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00,
  0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x3f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00
};
// NOR Gate
const unsigned char norGate_72x42[] PROGMEM = {
  0x00, 0x7f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x3f, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x1e, 0x01, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x06, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x03, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x03, 0x80, 0x00, 0x0f, 0xe0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x01, 0xc0, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0xe0, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x70, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x38, 0x00, 0x00, 0x01, 0xf0, 0x00, 0x00, 0x00,
  0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
  0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00,
  0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00,
  0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x63, 0xc0, 0x00,
  0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xe0, 0x00,
  0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x70, 0x00,
  0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x3f, 0xff,
  0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x3f, 0xff,
  0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x70, 0x00,
  0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x77, 0xe0, 0x00,
  0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x63, 0xc0, 0x00,
  0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00,
  0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00,
  0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
  0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
  0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x70, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0xe0, 0x00, 0x00, 0x1f, 0xc0, 0x00, 0x00, 0x00,
  0x00, 0x01, 0xc0, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x03, 0x80, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x07, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x0e, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x1e, 0x00, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x3f, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x7f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// XOR Gate
const unsigned char xorGate_72x42[] PROGMEM = {
  0x00, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x1f, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x0c, 0x03, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x06, 0x00, 0x3f, 0xe0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x03, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x01, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x80, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0xc0, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x60, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x38, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00,
  0xff, 0xff, 0xf8, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00,
  0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
  0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
  0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
  0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00,
  0xff, 0xff, 0xf8, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00,
  0xff, 0xff, 0xf0, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00,
  0x00, 0x00, 0x60, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x40, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00,
  0x00, 0x00, 0xc0, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
  0x00, 0x01, 0x80, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00,
  0x00, 0x03, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x06, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x06, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x0e, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x1f, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x3f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// XNOR Gate
const unsigned char xnorGate_72x42[] PROGMEM = {
  0x00, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x1f, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x0c, 0x03, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x06, 0x00, 0x3f, 0xe0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x03, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x01, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x80, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0xc0, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x60, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x30, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x38, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00,
  0xff, 0xff, 0xf8, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00,
  0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
  0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
  0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
  0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00,
  0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
  0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00,
  0xff, 0xff, 0xf8, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00,
  0xff, 0xff, 0xf0, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00,
  0x00, 0x00, 0x60, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x40, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00,
  0x00, 0x00, 0xc0, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
  0x00, 0x01, 0x80, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00,
  0x00, 0x03, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x06, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x06, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x0e, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x1f, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x3f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// ================= FUNCTIONS =================
void drawGate(const unsigned char *bitmap, int x, int y) {
  display.drawBitmap(x, y, bitmap, 80, 40, SSD1306_WHITE);
}
void setup() {
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
}
void loop() {
  if (digitalRead(BUTTON) == LOW) {
    Logic++;
    Input1 = -1;
    Input2 = -1;
    delay(300);
    if (Logic > 6)
      Logic = 0;
    Serial.println(Logic);
    while (digitalRead(BUTTON) == LOW)
      delay(1000);
  }
  if (millis() - current <= 2000) {
    Input1 = 0;
    Input2 = 0;
  } else if (millis() - current <= 4000) {
    Input1 = 0;
    Input2 = 1;
  } else if (millis() - current <= 6000) {
    Input1 = 1;
    Input2 = 0;
  } else if (millis() - current <= 8000) {
    Input1 = 1;
    Input2 = 1;
  }
  if (millis() - current >= 8001) {
    Input1 = 0;
    Input2 = 0;
    current = millis();
    return;
  }
  if (Logic == 0) {
    AND_LOGIC();
    int xx = check();
    if (xx)
      return;
    Serial.println("Updating");
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(20, 0);
    display.print("AND GATE");
    drawGate(andGate_72x42, 20, 20);
    display.setCursor(0, 21);
    display.print(Input1);
    display.setCursor(0, 46);
    display.print(Input2);
    display.setCursor(115, 32);
    display.print(Output);
    display.fillCircle(22, 30, 4, SSD1306_BLACK);
    display.fillCircle(22, 50, 4, SSD1306_BLACK);
    display.fillCircle(103, 39, 4, SSD1306_BLACK);
    if (Input1 == 1)
      display.fillCircle(22, 30, 4, SSD1306_WHITE);
    else
      display.drawCircle(22, 30, 4, SSD1306_WHITE);
    if (Input2 == 1)
      display.fillCircle(22, 50, 4, SSD1306_WHITE);
    else
      display.drawCircle(22, 50, 4, SSD1306_WHITE);
    if (Output == 1)
      display.fillCircle(103, 39, 4, SSD1306_WHITE);
    else
      display.drawCircle(103, 39, 4, SSD1306_WHITE);
    display.display();
    delay(100);
  }
  if (Logic == 1) {
    int xx = check();
    if (xx)
      return;
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(20, 0);
    display.print("OR GATE");
    drawGate(orGate_72x42, 20, 20);
    display.setCursor(0, 21);
    display.print(Input1);
    display.setCursor(0, 46);
    display.print(Input2);
    display.setCursor(115, 32);
    display.print(Output);
    display.fillCircle(22, 30, 4, SSD1306_BLACK);
    display.fillCircle(22, 50, 4, SSD1306_BLACK);
    display.fillCircle(103, 39, 4, SSD1306_BLACK);
    if (Input1 == 1)
      display.fillCircle(22, 30, 4, SSD1306_WHITE);
    else
      display.drawCircle(22, 30, 4, SSD1306_WHITE);
    if (Input2 == 1)
      display.fillCircle(22, 50, 4, SSD1306_WHITE);
    else
      display.drawCircle(22, 50, 4, SSD1306_WHITE);
    if (Output == 1)
      display.fillCircle(103, 39, 4, SSD1306_WHITE);
    else
      display.drawCircle(103, 39, 4, SSD1306_WHITE);
    display.display();
    delay(200);
  }
  if (Logic == 2) {
    int xx = check();
    if (xx)
      return;
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(20, 0);
    display.print("NOT GATE");
    drawGate(notGate_72x42, 20, 20);
    display.setCursor(0, 21);
    display.print(Input1);
    display.setCursor(0, 46);
    display.print(Input2);
    display.setCursor(115, 32);
    display.print(Output);
    display.fillCircle(22, 30, 4, SSD1306_BLACK);
    display.fillCircle(22, 50, 4, SSD1306_BLACK);
    display.fillCircle(103, 39, 4, SSD1306_BLACK);
    if (Input1 == 1)
      display.fillCircle(22, 30, 4, SSD1306_WHITE);
    else
      display.drawCircle(22, 30, 4, SSD1306_WHITE);
    if (Input2 == 1)
      display.fillCircle(22, 50, 4, SSD1306_WHITE);
    else
      display.drawCircle(22, 50, 4, SSD1306_WHITE);
    if (Output == 1)
      display.fillCircle(103, 39, 4, SSD1306_WHITE);
    else
      display.drawCircle(103, 39, 4, SSD1306_WHITE);
    display.display();
    delay(200);
  }
  if (Logic == 3) {
    int xx = check();
    if (xx)
      return;
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(20, 0);
    display.print("NAND GATE");
    drawGate(nandGate_72x42, 20, 20);
    display.setCursor(0, 21);
    display.print(Input1);
    display.setCursor(0, 46);
    display.print(Input2);
    display.setCursor(115, 32);
    display.print(Output);
    display.fillCircle(22, 30, 4, SSD1306_BLACK);
    display.fillCircle(22, 50, 4, SSD1306_BLACK);
    display.fillCircle(103, 39, 4, SSD1306_BLACK);
    if (Input1 == 1)
      display.fillCircle(22, 30, 4, SSD1306_WHITE);
    else
      display.drawCircle(22, 30, 4, SSD1306_WHITE);
    if (Input2 == 1)
      display.fillCircle(22, 50, 4, SSD1306_WHITE);
    else
      display.drawCircle(22, 50, 4, SSD1306_WHITE);
    if (Output == 1)
      display.fillCircle(103, 39, 4, SSD1306_WHITE);
    else
      display.drawCircle(103, 39, 4, SSD1306_WHITE);
    display.display();
    delay(200);
  }
  if (Logic == 4) {
    int xx = check();
    if (xx)
      return;
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(20, 0);
    display.print("NOR GATE");
    drawGate(norGate_72x42, 20, 20);
    display.setCursor(0, 21);
    display.print(Input1);
    display.setCursor(0, 46);
    display.print(Input2);
    display.setCursor(115, 32);
    display.print(Output);
    display.fillCircle(22, 30, 4, SSD1306_BLACK);
    display.fillCircle(22, 50, 4, SSD1306_BLACK);
    display.fillCircle(103, 39, 4, SSD1306_BLACK);
    if (Input1 == 1)
      display.fillCircle(22, 30, 4, SSD1306_WHITE);
    else
      display.drawCircle(22, 30, 4, SSD1306_WHITE);
    if (Input2 == 1)
      display.fillCircle(22, 50, 4, SSD1306_WHITE);
    else
      display.drawCircle(22, 50, 4, SSD1306_WHITE);
    if (Output == 1)
      display.fillCircle(103, 39, 4, SSD1306_WHITE);
    else
      display.drawCircle(103, 39, 4, SSD1306_WHITE);
    display.display();
    delay(200);
  }
  if (Logic == 5) {
    int xx = check();
    if (xx)
      return;
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(20, 0);
    display.print("XOR GATE");
    drawGate(xorGate_72x42, 20, 20);
    display.setCursor(0, 21);
    display.print(Input1);
    display.setCursor(0, 46);
    display.print(Input2);
    display.setCursor(115, 32);
    display.print(Output);
    display.fillCircle(22, 30, 4, SSD1306_BLACK);
    display.fillCircle(22, 50, 4, SSD1306_BLACK);
    display.fillCircle(103, 39, 4, SSD1306_BLACK);
    if (Input1 == 1)
      display.fillCircle(22, 30, 4, SSD1306_WHITE);
    else
      display.drawCircle(22, 30, 4, SSD1306_WHITE);
    if (Input2 == 1)
      display.fillCircle(22, 50, 4, SSD1306_WHITE);
    else
      display.drawCircle(22, 50, 4, SSD1306_WHITE);
    if (Output == 1)
      display.fillCircle(103, 39, 4, SSD1306_WHITE);
    else
      display.drawCircle(103, 39, 4, SSD1306_WHITE);
    display.display();
    delay(200);
  }
  if (Logic == 6) {
    int xx = check();
    if (xx)
      return;
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(20, 0);
    display.print("XNOR GATE");
    drawGate(xnorGate_72x42, 20, 20);
    display.setCursor(0, 21);
    display.print(Input1);
    display.setCursor(0, 46);
    display.print(Input2);
    display.setCursor(115, 32);
    display.print(Output);
    display.fillCircle(22, 30, 4, SSD1306_BLACK);
    display.fillCircle(22, 50, 4, SSD1306_BLACK);
    display.fillCircle(103, 39, 4, SSD1306_BLACK);
    if (Input1 == 1)
      display.fillCircle(22, 30, 4, SSD1306_WHITE);
    else
      display.drawCircle(22, 30, 4, SSD1306_WHITE);
    if (Input2 == 1)
      display.fillCircle(22, 50, 4, SSD1306_WHITE);
    else
      display.drawCircle(22, 50, 4, SSD1306_WHITE);
    if (Output == 1)
      display.fillCircle(103, 39, 4, SSD1306_WHITE);
    else
      display.drawCircle(103, 39, 4, SSD1306_WHITE);
    display.display();
    delay(200);
  }
}
void AND_LOGIC() {
  if (Input1 == 1 && Input2 == 1)
    Output = 1;
  else
    Output = 0;
}
boolean check() {
  if (Input1 == Pre_Input1 && Input2 == Pre_Input2 && Output == Pre_Output) {
    return 1;
  } else {
    Pre_Input1 = Input1;
    Pre_Input2 = Input2;
    Pre_Output = Output;
    return 0;
  }
}