#include //int button const int adjPin = 4; //button pin on P4 of ATtiny85. P5 is a reset and you won't have a good time tying that to ground! //int variables int seconds = 0; int minutes = 0; int hours = 0; //time test values unsigned long current = 0; //current time at test after second has elapsed unsigned long previous = 0; //time at previous test for second that has elapsed unsigned long period = 1000; //period between tests (millis) int buttonState = 0; void setup() { // put your setup code here, to run once: pinMode(adjPin, INPUT_PULLUP); oled.begin(128, 64, sizeof(tiny4koled_init_128x64r),tiny4koled_init_128x64r); oled.clear(); oled.on(); oled.setFont(FONT8X16); oled.setCursor(28,1); oled.println("Dumbwatch"); oled.setCursor(36,3); oled.println("by Maso"); delay(3000); //for boot screen oled.clear(); } void loop() { // put your main code here, to run repeatedly timer(); screen(); button(); } void timer() { current = millis(); //check to see if interval(second) has passed if(current - previous >= period){ previous = current; //save last time second passed if(seconds < 59){ // Check if a minute has elapsed. seconds++; // Increment seconds, } else { seconds = 0; // or reset seconds, if(minutes < 59){ // Check if an hour has elapsed. minutes++; // then increment minutes, } else { minutes = 0; // or reset minutes, if(hours < 23){ // Check if a day has elapsed. hours++; // then increment hours, } else { hours = 0; // or reset hours. } } } } else if(current - previous < 0){ //time correction, skips increment. CAN CAUSE DELAY previous = 0; } } void screen(){ oled.setFontX2(FONT8X16); oled.setCursor(24, 1); //set to x = 24 for HH:MM. For full debug set to x = 0 //oled.print("HH:MM:SS"); //placeholder //oled.print("HH:MM"); //also placeholder if(hours < 10) { oled.print("0"); //add leading zeroes } oled.print(hours); oled.print(":"); if(minutes < 10) { oled.print("0"); //add leading zeroes } oled.print(minutes); //oled.print(":"); //oled.print(seconds); } void button() { buttonState = digitalRead(adjPin); if(buttonState == LOW) { minutes++; } if(minutes > 59) { hours++; minutes = 0; } if(hours > 23) { hours = 0; } }