#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include "timeObj.h"
const int LED_PIN = 13;
bool ledState = false;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
timeObj aTimer;
timeObj bTimer;
void setup() {
Serial.begin(115200);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
pinMode(LED_PIN, OUTPUT);
aTimer.setTime(5000);
aTimer.start();
bTimer.setTime(50);
bTimer.start();
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
oled.setCursor(18, 0);
oled.print("Time Remaining");
oled.drawRoundRect(0, 10, 128, 47, 10, WHITE);
oled.fillRect(11, 19, 109, 29, WHITE);
oled.display();
}
void loop() {
if (aTimer.ding()) { // If the timer has expired..
oled.fillRect(11, 19, 109, 29, WHITE);
oled.display();
ledState = !ledState;
digitalWrite(LED_PIN, ledState);
aTimer.start(); // Restart the timer.
}
if (bTimer.ding()) {
float fraction = aTimer.getFraction();
int val = int (fraction * 100.0);
//for (int i = 0; i < (val / 10); i++) {
//oled.fillRect(109 - (100 - val), 19, 9, 29, BLACK);
oled.fillRect(109 - val, 19, 9, 29, BLACK);
//}
//oled.fillRect(9, 19, 109, 29, WHITE);
oled.display();
Serial.println(val);
bTimer.start();
}
}