Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Simple OLED display code
- Wiring diagram at https://circuitdigest.com/microcontroller-projects/arduino-ssd1306-oled-display
- You will need the Adafruit GFX library and the Adafruit SSD1306 library, which you can install
- in the Arduino IDE with the following steps:
- 1. go to Tools > Manage Libraries...
- 2. wait for it to update the list of libraries
- 3. in the top search box, enter "Adafruit SSD1306" and press Enter
- 4. next to Adafruit SSD1306, click the "Install" button
- 5. repeat steps 3 & 4 for "Adafruit GFX"
- 6. close the Library Manager window
- */
- #include <SPI.h>
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- // this defines the Arduino pins that connect to the display, you can use direct wires or a breadboard
- // you can't plug the OLED display directly into the Arduino!
- #define OLED_MOSI 9 // labeled "D1" on the OLED display
- #define OLED_CLK 10 // labeled "D0" on the OLED display
- #define OLED_DC 11 // labeled "DC" on the OLED display
- #define OLED_CS 12 // labeled "CS" on the OLED display
- #define OLED_RESET 13 // labeled "RES" on the OLED display
- Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
- void setup(){
- Serial.begin(9600);
- // set up the OLED display
- display.begin(SSD1306_SWITCHCAPVCC);
- display.clearDisplay();
- display.display();
- }
- void loop(){
- // this block displays the first screen
- display.clearDisplay();
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.setCursor(0,0);
- //display.println("1234567890"); // text size 2 allows max 10 characters per line, max 2 lines
- display.println("Kent Girl");
- display.println("Coders :)");
- display.display();
- delay(2000); // delay for 2 seconds
- // this block blanks the screen for 1/4-second
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(WHITE);
- display.setCursor(0,0);
- display.display();
- delay(250);
- // this block displays the second screen
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(WHITE);
- display.setCursor(0,0);
- //display.println("12345678901234567890"); // text size 1 allows max 20 characters per line, max 4 lines
- display.println("********************");
- display.println("Who runs the world?");
- display.println("Girls run the world!");
- display.println("********************");
- display.display();
- delay(3000);
- // copy & paste the 8 lines of code above to make another screen!
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement