#include "TinyWireM.h"
#include <Tiny4kOLED.h>
String Proyecto = "Proy: ATtiny85-015";
void setup() {
// put your setup code here, to run once:
oled.begin(128, 64, sizeof(tiny4koled_init_128x64b), tiny4koled_init_128x64b);
oled.setRotation(1);
oled.clear();
oled.on();
oled.setFont(FONT6X8P);
oled.setCursor(0, 0);
oled.print(Proyecto);
delay(1000);
pinMode(4, INPUT); // CI-3
pinMode(1, INPUT); // CI-6
pinMode(3, OUTPUT); // CI-2
}
int hora = 0;
int minutes = 2;
int seconds = 0;
int fase = 0;
int chosen = 0;
//int times[] = {1, 2, 10, 15, 20, 25, 30, 40};
int times[] = {30, 60, 90, 120};
int ani = 14;
int ViewDisplay = 1;
int debounce4 = 0;
int debounce1 = 0;
int set=0;
void loop(){
if (fase == 0 ) {
if (digitalRead(4) == 0) {
if (debounce4 == 0) {
ViewDisplay = 1;
debounce4 = 1;
chosen++;
if (chosen > 3) //7
chosen = 0;
if (fase == 3)
fase = 0;
}
} else {
debounce4 = 0;
}
if (digitalRead(1) == 0) {
if (debounce1 == 0) {
ViewDisplay = 1;
debounce1 = 1;
minutes = times[chosen];
if(minutes==90){
hora=1;
minutes=30;
}
if(minutes==120){
hora=2;
minutes=0;
}
set=minutes;
ver();
fase = 1;
if (fase == 3)
fase = 0;
}
} else {
debounce1 = 0;
}
}
if (fase == 1 || fase == 2) {
delay(10);
seconds--;
if (seconds <= 0) {
seconds = 59;
minutes--;
if (hora >= 1 && minutes <= 0){
hora--;
minutes=59;
}
}
}
if (fase == 3) { //Alarma
digitalWrite(3, 1);
delay(500);
digitalWrite(3, 0);
delay(500);
if (digitalRead(4) == 0) {
if (debounce4 == 0) {
ViewDisplay = 1;
debounce4 = 1;
fase = 0;
set=fase;
ver();
minutes = 2;
chosen = 0;
ViewDisplay = 1;
}
} else {
debounce4 = 0;
}
}
if (minutes == 0)
fase = 1;
if (minutes == -1)
fase = 3;
updateDisplay();
}
void updateDisplay() {
if (ViewDisplay == 1) {
oled.clear();
ViewDisplay = 0;
}
if (fase == 0) {
//oled.setFont(FONT6X8P);
oled.setCursor(0, 0);
oled.print(" SET TIME:");
oled.setCursor(0, 1);
oled.print("----------------------");
oled.setCursor(0, 2);
for (int i = 0; i < 4; i++) //8
{
oled.print(" ");
oled.print(times[i]);
}
if (chosen == 1)
oled.setCursor(25, 3 ); //32
else if (chosen == 2)
oled.setCursor(45, 3 ); //32
else if (chosen == 3)
oled.setCursor(60, 3); //50
else if (chosen > 3)
oled.setCursor(chosen * 17, 3);
else
oled.setCursor(6 + chosen * 12, 3);
oled.print("^");
}
if (fase == 1) {
//oled.setFont(FONT6X8P);
//oled.setFont(FONT8X16P);
oled.setCursor(8, 0);
oled.print("TIME:");
//oled.setFont(FONT8X16P);
//oled.setFont(FONT16X32DIGITS);
oled.setCursor(40, 3);
if (hora < 10)
oled.print(0);
oled.print(hora);
oled.print(" : ");
if (minutes < 10)
oled.print(0);
oled.print(minutes);
oled.print(" : ");
if (seconds < 10)
oled.print(0);
oled.print(seconds);
}
if (fase == 2) {
//oled.setFont(FONT8X16P);
//oled.setFont(FONT16X32DIGITS);
// oled.setCursor(8, 0);
// oled.setCursor(50, 3);
// oled.print(seconds);
}
}
void ver(){
oled.setCursor(0, 6);
oled.print(set);
delay(2000);
}