Hi
I am a newbee in programing, i am trying to make a very simple countdown timer, that starts on a push of a button and runs for 2 min. when it finishes the display turnes off, and starts again when the button is pushed.
I am using a small OLED as a display.
This a the code i am using ( i found it on the internet and modified it )
#include <U8g2lib.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
unsigned long Watch, _micro, time = micros();
unsigned int Clock = 0, R_clock;
boolean Reset = false, Stop = false, Paused = false;
volatile boolean timeFlag = false;
unsigned long clickTime = 0;
unsigned long Timer = 0;
unsigned long Timer_sec = 0;
unsigned long Timer_min = 0;
void setup(void) {
SetTimer(0,2,0);
StartTimer();
u8g2.begin();
}
void loop()
{
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_fub30_tf);
CountDownTimer();
if (TimeHasChanged() )
{
u8g2.setCursor(0, 32);
u8g2.print(u8x8_u8toa(ShowMinutes(),2));
u8g2.sendBuffer();
u8g2.setCursor(44, 28);
u8g2.print(":");
u8g2.sendBuffer();
u8g2.setCursor(62, 32);
u8g2.print(u8x8_u8toa(ShowSeconds(),2));
u8g2.sendBuffer();
delay(1000);
}
}
boolean CountDownTimer()
{
static unsigned long duration = 1000000;
timeFlag = false;
if (!Stop && !Paused)
{
if ((_micro = micros()) - time > duration )
{
Clock--;
timeFlag = true;
if (Clock == 0)
Stop = true;
_micro < time ? time = _micro : time += duration;
}
}
return !Stop;
}
void ResetTimer()
{
SetTimer(R_clock);
Stop = false;
}
void StartTimer()
{
Watch = micros();
time = micros();
Stop = false;
Paused = false;
}
void StopTimer()
{
Stop = true;
}
void StopTimerAt(unsigned int minutes, unsigned int seconds)
{
if (TimeCheck(minutes, seconds) )
Stop = true;
}
void SetTimer(unsigned int hours, unsigned int minutes, unsigned int seconds)
{
unsigned int _S = (seconds / 60), _M = (minutes / 60);
if(_S) minutes += _S;
if(_M) hours += _M;
Clock = (hours * 3600) + (minutes * 60) + (seconds % 60);
R_clock = Clock;
Stop = false;
}
void SetTimer(unsigned int seconds)
{
Clock = seconds;
R_clock = Clock;
Stop = false;
}
int ShowMinutes()
{
return (Clock / 60) % 60;
}
int ShowSeconds()
{
return Clock % 60;
}
boolean TimeHasChanged()
{
return timeFlag;
}
boolean TimeCheck(unsigned int minutes, unsigned int seconds)
{
return (minutes == ShowMinutes() && seconds == ShowSeconds());
}
My problem is that i am trying to upload it to an ATTiny 2313 8K ( as i need multiple timers ). but i am getting an error : "egion `text' overflowed by 8142 bytes" which i understand happens because my code is too big for the Attiny 2313.
Please is there a smart way to achieve what i want with a smaller/smarter code ? or should i buy a bigger Attiny ? .. if so please any suggestion which one i need to buy ?
Thanks.