//Smart Glasses
//Made by: Vasco2020
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//Pins
const int VERT_PIN = A1;
const int HORZ_PIN = A2;
const int SEL_PIN = 2;
const int PIN_LED = 7;
const int PIN_BUZZER = A0;
const int PIN_TRIG = 5;
const int PIN_ECHO = 6;
//Display Stuff
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire);
int cursor = 0;
boolean SOUND = true;
//Make Custom Functions Here
//Factory Functions
void distance_detect() {
boolean US_distance = true;
GUI_FRAME("Distance");
GUI_PROGRESSBAR(5,"Loading Distance");
while (US_distance) {
GUI_FRAME("Distance");
// Start a new measurement:
digitalWrite(PIN_TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(PIN_TRIG, LOW);
// Read the result and output it to display:
float duration = pulseIn(PIN_ECHO, HIGH);
if (duration / 58 < 100) {
display.print("Cm: ");
display.println(duration / 58);
};
if (duration / 58 > 100) {
display.print("M: ");
display.print(duration / 5800);
};
display.display();
if (digitalRead(SEL_PIN) == LOW) {
GUI_FRAME("Distance");
display.setCursor(10,20);
display.println("Closing Distance");
US_distance = false;
display.display();
delay(500);
};
};
}
//Important System Functions
void GUI_MENU(String menu, String funcname1, String funcname2, String funcname3, String funcname4, String funcname5, String funcname6, String funcname7, String funcname8, String funcname9, String funcname10) {
display.clearDisplay();
GUI_FRAME(menu);
if (cursor >= 0 && cursor <= 4) {
display.setCursor(15, 14);
display.println(funcname1); //First Function
display.setCursor(15, 24);
display.println(funcname2); //Seccond Function
display.setCursor(15, 34);
display.println(funcname3); //Third Function
display.setCursor(15, 44);
display.println(funcname4); //Fourth Function
display.setCursor(15, 54);
display.println(funcname5); //Fifth Function
display.setCursor(5, ((cursor) * 10) + 14);
}
if (cursor >= 5 && cursor <= 10) {
display.setCursor(15, 14);
display.println(funcname6); //First Function
display.setCursor(15, 24);
display.println(funcname7); //Seccond Function
display.setCursor(15, 34);
display.println(funcname8); //Third Function
display.setCursor(15, 44);
display.println(funcname9); //Fourth Function
display.setCursor(15, 54);
display.println(funcname10); //Fifth Function
display.setCursor(5, ((cursor - 5) * 10) + 14);
}
display.print(">");
}
void lockScreen() {
int dot_count = 0;
unsigned long last_press_time = 0;
unsigned long current_time = 0;
boolean locked = true;
boolean displayon = true;
GUI_FRAME("Lockscreen");
display.setCursor(45, 20);
display.print("LOCKED");
display.display();
delay(100);
last_press_time = millis();
while (locked) {
current_time = millis();
if (digitalRead(SEL_PIN) == LOW) {
dot_count++;
last_press_time = current_time;
GUI_FRAME("Lockscreen");
display.setCursor(45, 20);
display.print("LOCKED");
display.setCursor(50, 50);
if (!displayon) {
dot_count = 0;
};
displayon = true;
if(dot_count == 0) {
display.display();
};
if(dot_count == 1) {
display.println(".");
display.display();
};
if(dot_count == 2) {
display.println(". .");
display.display();
};
if(dot_count >= 3) {
display.println(". . .");
display.display();
locked = false;
delay(250);
GUI_FRAME("Lockscreen");
display.setCursor(40, 20);
display.print("UNLOCKED");
display.display();
delay(500);
};
delay(100);
};
if (current_time - last_press_time > 5000 && current_time - last_press_time < 5050 ) {
dot_count = 0;
display.clearDisplay();
display.display();
displayon = false;
};
if (current_time - last_press_time > 1000 && current_time - last_press_time < 1050 && dot_count >= 1) {
dot_count = 0;
GUI_FRAME("Lockscreen");
display.setCursor(45, 20);
display.print("LOCKED");
display.setCursor(45, 30);
display.println("");
display.display();
};
}
}
void sound_toggle() {
GUI_FRAME("Sound");
display.setCursor(45, 16);
display.println("Sound:");
display.setCursor(45, 30);
if (SOUND) {
tone(PIN_BUZZER,1000,100);
SOUND = false;
display.println("OFF");
display.display();
delay(100);
tone(PIN_BUZZER,750,100);
delay(100);
tone(PIN_BUZZER,500,100);
}
else {
tone(PIN_BUZZER,500,100);
SOUND = true;
display.println("ON");
display.display();
delay(100);
tone(PIN_BUZZER,750,100);
delay(100);
tone(PIN_BUZZER,1000,100);
}
delay(250);
}
String GUI_CONTROLS() {
if (analogRead(VERT_PIN) <= 312) {return "DOWN";}
if (analogRead(VERT_PIN) >= 712) {return "UP";}
if (analogRead(HORZ_PIN) <= 312) {return "LEFT";}
if (analogRead(HORZ_PIN) >= 712) {return "RIGHT";}
else {return "CENTER";}
}
void GUI_FRAME(String func_name) {
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.clearDisplay();
display.drawRect(0, 0, 128, 64, WHITE);
display.drawRect(71, 0, 128, 12, WHITE);
display.setCursor(73,2);
display.print("vOS v0.3a");
display.drawRect(0, 0, 128, 12, WHITE);
display.setCursor(2,2);
display.print(func_name);
display.setCursor(10,20);
}
void GUI_PROGRESSBAR(int y,String func_name) {
display.drawRect(2, 49, 104, 13, WHITE);
display.setCursor(4,52);
display.print(func_name);
display.drawRect(105, 49, 21, 13, WHITE);
display.setCursor(107,52);
display.print("00%");
display.display();
delay(1000);
int progressbar_progress = 0;
display.fillRect(3, 51, 101, 9, BLACK);
display.display();
delay(100);
while (progressbar_progress <= 100) {
display.fillRect(4, 51, progressbar_progress, 9, WHITE);
display.fillRect(106, 50, 19, 9, BLACK);
display.setCursor(107,52);
if (progressbar_progress <= 9) {
display.print("0");
};
display.print(progressbar_progress);
if (progressbar_progress <= 99) {
display.print("%");
};
display.display();
progressbar_progress += y;
}
}
void setup() {
Serial.begin(115200);
pinMode(PIN_TRIG, OUTPUT);
pinMode(PIN_ECHO, INPUT);
pinMode(PIN_LED, OUTPUT);
pinMode(PIN_BUZZER, OUTPUT);
pinMode(SEL_PIN, INPUT_PULLUP);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.setTextSize(1);
delay(2500);
GUI_FRAME("BIOS");
display.display();
delay(500);
GUI_PROGRESSBAR(1,"Booting to vOS");
display.display();
tone(PIN_BUZZER, 1000, 250); // Plays 500Hz tone for 0.250 seconds
delay(500);
lockScreen();
}
void loop() {
display.setCursor(0,0);
display.clearDisplay();
if (GUI_CONTROLS() == "DOWN" && cursor <= 8) {
cursor++;
if (SOUND) {
tone(PIN_BUZZER, 75, 50); // Plays 1001Hz tone for 0.1 seconds
};
}
if (GUI_CONTROLS() == "UP" && cursor >= 1) {
cursor--;
if (SOUND) {
tone(PIN_BUZZER, 75, 50); // Plays 1001Hz tone for 0.1 seconds
};
}
if (digitalRead(SEL_PIN) == LOW) {
//Make Functions here
if (cursor == 0) { //First Function Option
distance_detect();
}
if (cursor == 1) { //Seccond Function Option
delay(125);
}
if (cursor == 2) { //Third Function Option
delay(125);
}
if (cursor == 3) { //Fourth Function Option
}
if (cursor == 4) {
}
if (cursor == 5) {
}
if (cursor == 6) {
}
if (cursor == 7) {
}
if (cursor == 8) {
lockScreen();
}
if (cursor == 9) {
sound_toggle();
}
}
GUI_MENU("Menu","Distance","2","3","4","5","6","7","8","Lock","- Sound Toggle -");
display.display();
delay(100);
}