/************************************************************************** Monochrome OLEDs based on SSD1306 drivers This example is for a 128x64 pixel display using I2C to communicate 3 pins are required to interface (two I2C and one reset). Written by Sylvain DENIS for FabAcademy, with contributions from the open source community. Corrected By Quentin BOLSEE MIT license **************************************************************************/ #include #include #include #include #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define Y_POS 16 //Defines the starting position in height #define TXT_SIZE 5 //Define Size // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) // The pins for I2C are defined by the Wire-library. // On an arduino UNO: A4(SDA), A5(SCL) // On an arduino MEGA 2560: 20(SDA), 21(SCL) // On an arduino LEONARDO: 2(SDA), 3(SCL), ... #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 - Here - 0x3C Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); int x = SCREEN_WIDTH/2; // Start at half screen int x_min = 0; const char* txt = "Hello FabAcademy 2022"; //You can change the text void setup() { SerialUSB.begin(9600); // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { SerialUSB.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.display(); // Clear the buffer display.clearDisplay(); // testdrawchar(); display.clearDisplay(); display.setTextColor(SSD1306_WHITE); display.setTextWrap(false); //We prevent the return to the line // text size of 1 => 6 pixels x_min = -6 * TXT_SIZE * strlen(txt); } void loop() { display.clearDisplay(); display.setCursor(x, Y_POS); display.setTextSize(TXT_SIZE); display.print(txt); display.display(); x--; if (x < x_min) { x = SCREEN_WIDTH; } }