// #include <avr/pgmspace.h> // attiny85 memory manager
#include "SSD1306_minimal.h" // https://github.com/kirknorthrop/SSD1306_minimal/tree/master
SSD1306_Mini oled; // Declare the OLED object
char *hello = "Hello, World!";
float dtosVal = 123.456;
byte dtosWdth = 7; // character count (without null terminator)
byte dtosPrcn = 3; // decimal places
char dtosBuff[8]; // buffer of dtosVal plus null terminator
void setup() {
oled.init(0x3C); // Initialize display with address
oled.clear(); // Clear display
printAcrossBottom();
printAlongSide();
printAcrossTop();
printFloatAsChar(123.456);
}
void loop() {}
void printFloatAsChar(float value) {
oled.cursorTo((128 - 6 * 7) / 2, 3); // center six characters
oled.printString(dtostrf(value, dtosWdth, dtosPrcn, dtosBuff)); // rounds the float
}
void printAcrossBottom() {
oled.cursorTo(7 * 10, 6); // horizontal by pixel ("7" pixels per character)
oled.printString("11111111");
oled.cursorTo(0, 7); // eight rows
oled.printString("012345678901234567"); // string uses array of char
}
void printAlongSide() {
for (int i = 1; i < 7; i++) { // eight rows
oled.cursorTo(0, i);
oled.printChar(i + '0');
}
}
void printAcrossTop() {
oled.cursorTo(0, 0);
oled.printChar(2);
oled.printString(hello); // does not print integers
oled.printChar(1);
}Loading
ssd1306
ssd1306