Advertisement
adolf01

SSD1306_test

Jun 17th, 2019
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPI.h>
  2. #include <Wire.h>
  3. #include <Adafruit_GFX.h>
  4. #include <Adafruit_SSD1306.h>
  5.  
  6. #define SCREEN_WIDTH 128 // OLED display width, in pixels
  7. #define SCREEN_HEIGHT 32 // OLED display height, in pixels
  8.  
  9. // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
  10. #define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
  11. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  12.  
  13.  
  14. void setup() {
  15.   Serial.begin(9600);
  16.  
  17.   // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  18.   if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
  19.     Serial.println(F("SSD1306 allocation failed"));
  20.     for (;;); // Don't proceed, loop forever
  21.   }
  22.  
  23.   // Show initial display buffer contents on the screen --
  24.   // the library initializes this with an Adafruit splash screen.
  25.   display.display();
  26.  
  27. }
  28.  
  29. void loop() {
  30.  
  31.   testdrawchar();      // Draw characters of the default font
  32.   display.invertDisplay(true);
  33.   delay(1000);
  34.   display.invertDisplay(false);
  35.   delay(1000);
  36. }
  37.  
  38.  
  39.  
  40. void testdrawchar(void) {
  41.   display.clearDisplay();
  42.  
  43.   display.setTextSize(1);      // Normal 1:1 pixel scale
  44.   display.setTextColor(WHITE); // Draw white text
  45.   display.setCursor(0, 0);     // Start at top-left corner
  46.   display.cp437(true);         // Use full 256 char 'Code Page 437' font
  47.   display.println(F("Ahoj, ty neshcopny"));
  48.   display.println(F("hovedo!!!"));
  49.   // Not all the characters will fit on the display. This is normal.
  50.   // Library will draw what it can and the rest will be clipped.
  51.   //  for (int16_t i = 0; i < 256; i++) {
  52.   //    if (i == '\n') display.write(' ');
  53.   //    else          display.write(i);
  54.   //  }
  55.   display.display();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement