/*
MIT License
Copyright (c) 2022-2023, Adolfo Gutiérrez
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "AdoPod_Icons.h"
#include "pixChicago4pt7b.h"
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int16_t FIX_HEIGHT_TEXT = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.clearDisplay();
display.drawBitmap(0, 0, splash_screen, 128, 64, SSD1306_WHITE);
display.display();
delay(1000); // Pause for 1 seconds
}
void loop() {
// put your main code here, to run repeatedly:
display.clearDisplay();
display.setTextSize(1); // text size
display.setFont(&pixChicago4pt7b); // text font
display.setTextColor(WHITE); // text color
display.setCursor(0, FIX_HEIGHT_TEXT + 10); // position to display
// display string
String text = "Hello World!";
oledDisplayCenter(text);
delay(500);
String text1 = "This";
oledDisplayCenter(text1);
delay(500);
String text2 = "This is";
oledDisplayCenter(text2);
delay(500);
String text3 = "This is Center";
oledDisplayCenter(text3);
delay(500);
String text4 = "This is Center \n Text";
oledDisplayCenter(text4);
delay(500);
// display number
int number = 21;
String str = String(number);
oledDisplayCenter(str);
delay(500);
}
void oledDisplayCenter(String text) {
int16_t x1;
int16_t y1;
uint16_t width;
uint16_t height;
display.getTextBounds(text, 0, 0, &x1, &y1, &width, &height);
// display on horizontal and vertical center
display.clearDisplay(); // clear display
display.setCursor((SCREEN_WIDTH - width) / 2, FIX_HEIGHT_TEXT + (SCREEN_HEIGHT - height) / 2);
display.println(text); // text to display
display.display();
}