Last active
July 8, 2021 18:37
-
-
Save JeremySCook/fa6153a8dd7a5a82d80ca6bc6335721c to your computer and use it in GitHub Desktop.
simple-1306text-2.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#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 | |
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin) | |
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 | |
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); | |
void setup() { | |
Serial.begin(9600); | |
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally | |
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { | |
Serial.println(F("SSD1306 allocation failed")); | |
for(;;); // Don't proceed, loop forever | |
} | |
display.setRotation(2); //sets rotation 1 through 4 (2 = 180º rotation vs 4) | |
display.clearDisplay(); | |
// Draw text | |
display.setTextSize(1); // Normal 1:1 pixel scale | |
display.setTextColor(SSD1306_WHITE); // Draw white text | |
display.setCursor(30,0); // Start at top-left corner | |
display.print("Hello, world!"); | |
display.setCursor(30,30); | |
display.print("test"); | |
// Show the display buffer on the screen. You MUST call display() after | |
// drawing commands to make them visible on screen! | |
display.display(); | |
delay(1000); | |
display.setTextSize(3); | |
} | |
void loop() { | |
unsigned long currentMillis = millis(); | |
display.clearDisplay(); | |
display.invertDisplay(1); | |
display.setCursor(0,20); | |
display.print(currentMillis); | |
display.display(); | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment