Advertisement
ccarman602

KGC Simple OLED Display

Jun 3rd, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Simple OLED display code
  3.  
  4. Wiring diagram at https://circuitdigest.com/microcontroller-projects/arduino-ssd1306-oled-display
  5.  
  6. You will need the Adafruit GFX library and the Adafruit SSD1306 library, which you can install
  7. in the Arduino IDE with the following steps:
  8. 1. go to Tools > Manage Libraries...
  9. 2. wait for it to update the list of libraries
  10. 3. in the top search box, enter "Adafruit SSD1306" and press Enter
  11. 4. next to Adafruit SSD1306, click the "Install" button
  12. 5. repeat steps 3 & 4 for "Adafruit GFX"
  13. 6. close the Library Manager window
  14. */
  15.  
  16. #include <SPI.h>
  17. #include <Wire.h>
  18. #include <Adafruit_GFX.h>
  19. #include <Adafruit_SSD1306.h>
  20.  
  21. // this defines the Arduino pins that connect to the display, you can use direct wires or a breadboard
  22. // you can't plug the OLED display directly into the Arduino!
  23. #define OLED_MOSI   9 // labeled "D1" on the OLED display
  24. #define OLED_CLK   10 // labeled "D0" on the OLED display
  25. #define OLED_DC    11 // labeled "DC" on the OLED display
  26. #define OLED_CS    12 // labeled "CS" on the OLED display
  27. #define OLED_RESET 13 // labeled "RES" on the OLED display
  28.  
  29. Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
  30.  
  31. void setup(){
  32.   Serial.begin(9600);
  33.  
  34.   // set up the OLED display
  35.   display.begin(SSD1306_SWITCHCAPVCC);
  36.   display.clearDisplay();
  37.   display.display();
  38. }
  39.  
  40. void loop(){
  41.  
  42.   // this block displays the first screen
  43.   display.clearDisplay();
  44.   display.setTextSize(2);
  45.   display.setTextColor(WHITE);
  46.   display.setCursor(0,0);
  47. //display.println("1234567890"); // text size 2 allows max 10 characters per line, max 2 lines
  48.   display.println("Kent Girl");
  49.   display.println("Coders :)");
  50.   display.display();
  51.   delay(2000); // delay for 2 seconds
  52.  
  53.   // this block blanks the screen for 1/4-second
  54.   display.clearDisplay();
  55.   display.setTextSize(1);
  56.   display.setTextColor(WHITE);
  57.   display.setCursor(0,0);
  58.   display.display();
  59.   delay(250);
  60.  
  61.   // this block displays the second screen
  62.   display.clearDisplay();
  63.   display.setTextSize(1);
  64.   display.setTextColor(WHITE);
  65.   display.setCursor(0,0);
  66. //display.println("12345678901234567890"); // text size 1 allows max 20 characters per line, max 4 lines
  67.   display.println("********************");
  68.   display.println("Who runs the world?");
  69.   display.println("Girls run the world!");
  70.   display.println("********************");
  71.   display.display();
  72.   delay(3000);
  73.  
  74.   // copy & paste the 8 lines of code above to make another screen!
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement