i made a small watch program but whenever i try to upload it to my ATtiny85 20PU using Arduino UNO as ISP it stops at compiling and reports:
/home/pi/Downloads/arduino-1.8.13/hardware/tools/avr/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld: Watch.ino.elf section `.text' will not fit in region `text'
/home/pi/Downloads/arduino-1.8.13/hardware/tools/avr/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld: region `text' overflowed by 5392 bytes
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board ATtiny25/45/85.
i tried it on my Arduino UNO and it compiled, uploaded and worked fine
i think it may have something to do the Strings created when i do the u8x8.print() command but i'm not sure what to do about that
here is the program (with way too many comments):
#include <U8x8lib.h>
//prepare screen (i'm using a 1306 I2c 128x64 white oled btw)
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(7,5);
//buttons for setting the time
int upButton = 2;
int selButton = 3;
//time variables
int hours;
int minutes;
int seconds;
long last;
//variable for if hours (1), minutes (2), or none (0) is selected
int select;
void setup() {
//set up buttons
pinMode(upButton, INPUT);
pinMode(selButton, INPUT);
//variable start values
hours = 12;
minutes = 0;
seconds = 0;
last = millis();
select = 0;
//begin screen
u8x8.begin();
}
void loop() {
//loop until a second passes
while (millis() - last < 1000) {
//show time on screen
displayTime();
//check if the select button has been pressed
if (digitalRead(selButton) == LOW) {
//select next time part (hours, minutes, none)
select ++;
if (select == 3) {
select = 0;
}
}
//check if the up button has been pressed
if (digitalRead(upButton) == LOW) {
//if select is on hours
if (select == 1) {
//increase the hour
increaseTime(0, 0, 1);
//if select is on minutes
}else if (select == 2) {
//increase the minute
increaseTime(0, 1, 0);
}
}
}
//prepare for next second
last += 1000;
//increase the second
increaseTime(1, 0, 0);
}
//use to show time on the screen
void displayTime() {
//set font
u8x8.setFont(u8x8_font_courB24_3x4_r);
//if select is on hours
if (select == 1) {
//make the hours text inverted colors
u8x8.setInverseFont(1);
//if not on hours
}else {
//do not make the hours text inverted colors
u8x8.setInverseFont(0);
}
//if hours is less than 10
if (hours < 10) {
//add a zero before the hour
u8x8.drawString(1,2,"0");
//set cursor in position
u8x8.setCursor(4,2);
//if hours is more than zero
}else {
//set cursor in position
u8x8.setCursor(1,2);
}
//show hour
//I THINK HERE MAY BE ONE OF THE PLACES THAT IS MAKING IT NOT COMPILE FOR ATTINY85
u8x8.print(hours);
//do not make text inverted
u8x8.setInverseFont(0);
//add colon
u8x8.drawString(7,2,":");
//if select is on minutes
if (select == 2) {
//make text inverted
u8x8.setInverseFont(1);
//if not on minutes
}else {
//do not make text inverted
u8x8.setInverseFont(0);
}
//if minutes is less than 10
if (minutes < 10) {
//add a 0 before minute
u8x8.drawString(10,2,"0");
//set cursor in position
u8x8.setCursor(13,2);
//if minutes is bigger that 10
}else {
//set cursor in position
u8x8.setCursor(10,2);
}
//show minutes
//I THINK HERE IS THE OTHER PART THAT HAS TROUBLE COMPILING FOR ATTINY85
u8x8.print(minutes);
}
//use to increase either seconds (s) minutes (m) or hours (h)
void increaseTime(int s, int m, int h) {
//increase seconds by s value
seconds += s;
//if seconds is 60 or more
if (seconds >= 60) {
//reset seconds to 0
seconds = 0;
//increase minutes by 1
minutes ++;
}
//increase minutes by m value
minutes += m;
//if minutes is 60 or more
if (minutes >= 60) {
//reset minutes to 0
minutes = 0;
//increase hour by 1
hours ++;
}
//increase hour by h value
hours += h;
//if hour is over 12
if (hours >= 13) {
//reset hour to 1
hours = 1;
}
}