Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Simple OLED display code with NodeMCU
- This combines the earlier "Simple OLED display code" with a NodeMCU so that it's more compact.
- The easiest way to set up the OLED with a NodeMCU is to place the NodeMCU onto a
- breadboard so that it takes up holes b1-b15 and i1-i15 on the breadboard with the
- micro USB port pointing "up" (it should hang over the edge of the breadboard), and
- then plug the OLED pins into holes a9-a15, so that the "CS" pin on the OLED matches
- up with the "D0" pin on the NodeMCU (at the "bottom", near the squiggly copper wifi
- antenna). OLED pin "VCC" should match up with the "3V3" pin on the NodeMCU, and
- OLED pin "GND" should match up with the "GND" pin on the NodeMCU.
- In the Arduino IDE, make sure go to Tools > Board and select "NodeMCU 1.0",
- otherwise it won't work!
- */
- #include <SPI.h>
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- // If using software SPI (the default case):
- #define OLED_CS D0
- #define OLED_DC D1
- #define OLED_RESET D2
- #define OLED_MOSI D3 // aka "D1" on the OLED
- #define OLED_CLK D4 // aka "D0" on the OLED
- Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
- #if (SSD1306_LCDHEIGHT != 32)
- #error("Height incorrect, please fix Adafruit_SSD1306.h!");
- #endif
- 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);
- // this block displays the second screen
- display.clearDisplay();
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.setCursor(0,0);
- display.println("Girls run");
- display.println("the world!");
- display.display();
- delay(2000);
- // 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement