#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "img.h"

#define SCREEN_WIDTH 128 // OLED width,  in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
#define VOLTAGE_PIN 13 
const int freq_pin = 4;
const int yes = 5;
const int no = 19;
const int submit = 18;
const char* array[] = {"Details", "125Hz", "250Hz", "500Hz", "1 kHz", "2 kHz", "4 kHz", "8 kHz"};
const char* detail[] = {"Name", "Phone No", "Email"};

String value[100];
String incoming;

int i = 1, k = 45, l = 0, m = 0, j = 0, n = 1,x=0,w=114;
int freq[] = {125, 250, 500, 1000, 2000, 4000, 8000};

// create an OLED display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
  Serial.begin(9600);
  pinMode(VOLTAGE_PIN,OUTPUT);
  analogWrite(VOLTAGE_PIN,4095);
  // initialize OLED display with I2C address 0x3C
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) 
  {
    Serial.println(F("failed to start SSD1306 OLED"));
    while (1);
  }

  oled.clearDisplay();
  // oled.drawBitmap(w, 0, BATTERY_BOX1, 128, 64, WHITE);
  oled.drawBitmap(w, 0, BATTERY_BOX2, 128, 64, WHITE);
  // oled.drawBitmap(w, 20, BATTERY_BOX3, 128, 64, WHITE);
  // oled.drawBitmap(w, 30, BATTERY_BOX0, 128, 64, WHITE);
  oled.drawBitmap(2, 0, BLUETOOTH, 128, 64, WHITE);
  oled.setTextColor(WHITE);
  WELCOME();
  oled.display();
}

void loop()
{

}

void WELCOME()
{
  // oled.clearDisplay();
  oled.setTextSize(2);
  oled.setTextColor(WHITE);
  oled.setCursor(25, 10);
  oled.print("We_Hear");
  oled.setTextSize(1);
  oled.setCursor(28, 33);
  oled.println("Welcomes You");
  oled.setCursor(43, 45);
  oled.println("To The");
  oled.setCursor(28, 57);
  oled.setTextSize(1);
  oled.println("HEARING TEST");
  oled.display();
}

void START()
{
  // oled.clearDisplay();
  oled.setCursor(16, 12);
  oled.setTextSize(2);
  oled.println("STARTING");
  oled.setCursor(44, 31);
  oled.println("THE");
  oled.setCursor(39, 50);
  oled.print("TEST");
  oled.display();
}

void NO()
{
  oled.setCursor(110, 52);
  oled.setTextSize(1);
  oled.print("NO");
  oled.display();
}

void YES()
{
  oled.setCursor(109, 52);
  oled.setTextSize(1);
  oled.print("YES");
  oled.display();
}

void FREQ(String freq)
{
  // oled.clearDisplay();
  oled.setTextColor(WHITE);
  oled.setCursor(21, 10);
  oled.setTextSize(3);
  oled.println(freq);
  oled.setCursor(56, 37);
  oled.setTextSize(1);
  oled.println("AT");
  oled.setTextSize(2);
  oled.setCursor(35, 50);
  oled.print(k);
  oled.print(" dB");
  oled.display();
}

void SUBMIT()
{
  // oled.clearDisplay();
  oled.setTextColor(WHITE);
  oled.setCursor(29, 5);
  oled.setTextSize(2);
  oled.println("Please ");
  oled.setCursor(10, 20);
  oled.println("Press The");
  oled.setCursor(29, 35);
  oled.println("Submit");
  oled.setCursor(30, 50);
  oled.println("Button");
  oled.display();
}

void END()
{
  delay(500);
  // oled.clearDisplay();
  oled.setTextColor(WHITE);
  oled.setCursor(10, 12);
  oled.setTextSize(2);
  oled.println("THANK YOU");
  oled.setCursor(23, 31);
  oled.println("FOR THE");
  oled.setCursor(41, 50);
  oled.println("TEST");
  oled.display();
}