I am trying to reduce the size of a sketch so I can use an ATTiny85V rather than an Arduino Nano. The sketch, which compiles and runs on my Nano, is currently 17,870 bytes, however, I suspect much of this is to do with the Adafruit libraires, which are included.
I have tried changing the sketch by using the TinyWire.h and SH1106mini.h libraries, which are much smaller, but I don't know enough about programming to do it.
Does anyone know if what I am trying to do is possible and, if so, can you please give me some pointers as to how best to do it.
Thanks in anticipation.
The code is as follows:-
// Tested and compiled with no errors
// Arduino Stopwatch with OLED display
// with Start, Stop and Reset button
// source - www.circuitschools.com
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's
// SCL A5
// SDA A4
#define OLED_RESET 0 // GPIO0
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
pinMode(6, INPUT_PULLUP); //Switch
display.begin(0x3C, true); // initialize with the I2C addr 0x3C (for the 128x64)
display.display();
display.clearDisplay();
display.setFont(&FreeSans9pt7b);
display.setTextColor(SH110X_WHITE);
display.setCursor(27, 25);
display.println("Cotton's");
display.setCursor(22, 45);
display.println("Creations");
display.display();
delay(5000);
}
int poz = 1;
int broj = 1;
int kretanjeY = 30;
int sec1 = 0;
int min1 = 0;
unsigned long msec = 0;
unsigned long mili = 0;
int pres = 0;
int fase = 0;
int start = 0;
unsigned long tim = 0;
void loop() {
display.clearDisplay();
if (digitalRead(6) == 0) {
if (pres == 0) {
fase = fase + 1;
pres = 1;
if (fase > 2)
fase = 0;
}
} else {
pres = 0;
}
if (fase == 0) {
display.setFont(&FreeSans9pt7b);
display.setFont();
display.setCursor(33, 15);
display.println("STOPWATCH");
display.setFont(&FreeSans12pt7b);
display.setFont();
display.setCursor(30, 35);
display.print("Press Start");
sec1 = 0;
min1 = 0;
tim = 0;
mili = 0;
msec = 0;
start = 0;
}
if (fase == 1) {
display.clearDisplay();
display.setFont(&FreeSans12pt7b);
display.setFont();
display.setCursor(37, 0);
display.print("Stopwatch");
display.setFont(&FreeSans9pt7b);
if (start == 0) {
start = 1;
tim = millis();
}
msec = (millis() - tim);
min1 = msec / 60000;
if ((msec / 1000) > 59) {
sec1 = (msec / 1000) - (min1 * 60);
} else {
sec1 = msec / 1000;
}
mili = (msec % 1000) / 10;
display.setCursor(42, 30);
if (min1 <= 9) {
display.print("0");
display.print(min1);
} else {
display.print(min1);
}
display.print(":");
if (sec1 <= 9) {
display.print("0");
display.print(sec1);
} else {
display.print(sec1);
}
display.setFont(&FreeSans12pt7b);
display.setCursor(50, 57);
if (mili <= 9) {
display.print("0");
display.print(mili);
} else {
display.print(mili);
}
}
if (fase == 2) {
display.clearDisplay();
display.setFont(&FreeSans12pt7b);
display.setFont();
display.setCursor(52, 0);
display.print("Time:");
display.setFont(&FreeSans9pt7b);
display.setCursor(42, 30);
if (min1 <= 9) {
display.print("0");
display.print(min1);
} else {
display.print(min1);
}
display.print(":");
if (sec1 <= 9) {
display.print("0");
display.print(sec1);
} else {
display.print(sec1);
}
display.setFont(&FreeSans12pt7b);
display.setCursor(50, 57);
if (mili <= 9) {
display.print("0");
display.print(mili);
} else {
display.print(mili);
}
}
display.display();
}