#include "FastLED.h"
#include "ButtonConfig.h"
#include "Debounce.h"
#include "Math_Functions.h"
//*************Tiny4koled (ssd1306)*************
//#include <TinyI2CMaster.h>
#include <TinyWireM.h>
#include "Tiny4kOLED.h"
#include "font16x32digits.h"
#define TINY4KOLED_QUICK_BEGIN
#define screen oled
uint8_t width = 128;
uint8_t height = 64;
#define screeninit tiny4koled_init_128x64br
#define TimeStartPoint 24
//***********Button Setup*******************
#define buttoncheckinterval 3 // time in ms between button checks
#define ButtonsUsed 0b00000011
// Byte using a 1 to represent button has a pull-up sp is normally high,
// A 0 means buton has pull-down or is not in use
// Button order as defined in ButtonsUsed term above
#define UpButton 0x01
#define DownButton 0x02
Debouncer btns(ButtonsUsed);
uint8_t CurrentMinutes =2;
uint8_t CurrentSeconds =4;
uint8_t CurrentTenths = 9;
uint8_t BatPrintSetting=0;
uint8_t LastBatPrintSetting=0;
bool RunFastTime=false;
bool TimerDone=false;
bool FirstFastRun=true;
bool StartProgram=false;
const uint8_t box_bitmap[] PROGMEM = {
0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE
};
uint8_t CurrentTime[4]={0,2,0,4};
uint8_t FastTime[4]={0,5,9,9};
#define VOLT_PIN PB3
#define UP_PIN PB4
#define DOWN_PIN PB5
void setup() {
pinMode(VOLT_PIN, INPUT);
pinMode(UP_PIN,INPUT_PULLUP);
pinMode(DOWN_PIN,INPUT_PULLUP);
ScreenSetup();
PrintBasicTime(CurrentMinutes,CurrentSeconds);
while(!StartProgram){
EVERY_N_MILLIS_I(Buttoncheck, buttoncheckinterval){
uint32_t ms=millis();
ButtonMenu(ms);
}
}
CheckBattery();
}
void loop() {
EVERY_N_SECONDS_I(BattLevel,3){CheckBattery();}
if (!TimerDone){
if (RunFastTime){
if(FirstFastRun){
screen.setCursor(0,2);
screen.clearToEOL();
LastBatPrintSetting=0;
CheckBattery();
PrintFastTime(CurrentSeconds,CurrentTenths);
FirstFastRun=false;
delay(50);
}
EVERY_N_MILLIS_I(FastTimeUpdate,100){FastCountDown();}
}
else{// onlyupdating every second
EVERY_N_SECONDS_I(BasicTimeUpdate,1){BasicCountDown();}
}
}
}