Advertisement
hwthinker

nodemcu esp8266 oled 0.91

Jan 29th, 2024
933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. #include "OLED.h"
  3. // 0.91s OLED connection:
  4. //SDA -- D4
  5. //SCL -- D5
  6. //RST -- D2
  7. OLED display(SDA, SCL);
  8. void setup() {
  9.   pinMode(D2, OUTPUT);
  10.   digitalWrite(D2, LOW);  // turn D2 low to reset OLED
  11.   delay(50);
  12.   digitalWrite(D2, HIGH);  // while OLED is running, must set D2 in high
  13.   Serial.begin(9600);
  14.   Serial.println("OLED test!");
  15.   // Initialize display
  16.   display.begin();
  17.   // Test message
  18.   display.print("Hello ");
  19.   delay(3 * 1000);
  20.   // Test long message
  21.   display.print("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
  22.   delay(3 * 1000);
  23.   // Test display clear
  24.   display.clear();
  25.   delay(3 * 1000);
  26.   // Test message postioning
  27.   display.print("TOP-LEFT");
  28.   display.print("4th row", 4);
  29.   display.print("RIGHT-BOTTOM", 7, 4);
  30.   delay(3 * 1000);
  31.   // Test display OFF
  32.   display.off();
  33.   display.print("3rd row", 3, 8);
  34.   delay(3 * 1000);
  35.   // Test display ON
  36.   display.on();
  37.   delay(3 * 1000);
  38. }
  39. int r = 0, c = 0;
  40. void loop() {
  41.   r = r % 4;
  42.   c = micros() % 6;
  43.   if (r == 0) display.clear();
  44.   display.print("Hello ", r++, c++);
  45.   delay(500);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement