/**************************************************************************
Version SSD1306_Test1e: Uses #defines for text blocks' x, y coords.
**************************************************************************/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
//----x, y coords for text block------
#define REPS_X 20
#define REPS_Y 24
//----Test Sizes-------
#define REPS_TEXT_SIZE 6
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino resetpin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int Reps = 1; // Rep counter to be displayed on OLED screen.
void setup()
{
Serial.begin(115200);
delay(1000);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
} //
// Clear the buffer.
display.clearDisplay();
display.setTextSize(2);
display.setFont(NULL);
display.setTextColor(WHITE, BLACK);
display.setCursor(1, 0);
display.println("REPS:");
display.println("");
display.display();
}
void loop() {
for (int Reps = 1; Reps <= 110; Reps++) {
display.setCursor(REPS_X, REPS_Y);
display.setTextSize(6);
// Drawing the number in WHITE
display.setTextColor(WHITE, BLACK);
display.println(Reps); // show 'Reps' in white
display.display();
delay(250); // wait for a second
// "Erasing" the number with BLACK
// Here, we need to ensure we're overwriting the exact position. Resetting the cursor is crucial.
display.setCursor(REPS_X, REPS_Y); // Reset cursor to ensure black color overwrites the exact position
display.setTextColor(BLACK, BLACK); // "erase" 'Reps' by writing in black
display.println(Reps);
display.display();
// If you don't clear the screen or part of it, old data from the buffer can remain as a ghost on the display.
// So, you may need to manage clearing specific parts of the screen or ensure exact overwriting depending on your needs.
}
// After reaching 10, the loop restarts, and 'Reps' is reset to 1 by the 'for' loop's control structure.
}