Created
July 8, 2021 18:11
-
-
Save JeremySCook/6a765582dba6675388aa887f856dd6bf to your computer and use it in GitHub Desktop.
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); | |
int x = 0; | |
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(4); //sets rotation 1 through 4 | |
display.display(); | |
delay(1000); // Pause for 2 seconds | |
// Clear the buffer | |
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(2000); | |
display.setTextSize(6); | |
} | |
void loop() { | |
display.clearDisplay(); | |
display.setCursor(0,20); | |
display.print(x); | |
display.display(); | |
delay(1000); | |
x++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment