Grafik-Demo für das ESP8266 Mikrocontrollerboard



Ziel: Zeigen der verschiedenen Grafikelemente für das OLED.








Quelltext:

// Dieses Programm benutzt die Bibliothek "u8g2" von oli kraus.
// Siehe dazu: https://github.com/olikraus/u8g2/wiki
// Referenz (mögliche Befehle): https://github.com/olikraus/u8g2/wiki/u8g2reference

// Bibliotheken:
#include <U8g2lib.h> // by oli kraus

// Instanziierung:
U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, 5, 4, 16);

// globale Variablen:
int i = 0;


void setup(void) {
  u8g2.begin();
}

void loop(void) {

  u8g2.clearBuffer();

  u8g2.setFont(u8g2_font_mozart_nbp_tf); // winzige Schrift

  if (i == 0) u8g2.drawStr(5, 7, "drawString()");
  if (i == 1) u8g2.drawStr(5, 7, "drawBox()");
  if (i == 2) u8g2.drawStr(5, 7, "drawFrame()");
  if (i == 3) u8g2.drawStr(5, 7, "drawCircle()");
  if (i == 4) u8g2.drawStr(5, 7, "drawDisc()");
  if (i == 5) u8g2.drawStr(5, 7, "drawEllipse()");
  if (i == 6) u8g2.drawStr(5, 7, "drawFilledEllipse()");
  if (i == 7) u8g2.drawStr(5, 7, "drawUTF8()");
  if (i == 8) u8g2.drawStr(5, 7, "drawGlyph()");
  if (i == 9) u8g2.drawStr(5, 7, "drawLine()");
  if (i == 10) u8g2.drawStr(5, 7, "drawPixel()");
  


  if (i == 0) {
  	u8g2.setFont(u8g2_font_ncenB12_tr);  // mittelgroße Schrift
  	u8g2.drawStr(5, 31, "Hallo Welt!");  // x, y, string
  }
  
  if (i == 1) u8g2.drawFrame(5, 17, 22, 14);           // x, y, width, height
  if (i == 2) u8g2.drawBox(5, 17, 22, 14);             // x, y, width, height
  if (i == 3) u8g2.drawCircle(15, 23, 8);              // x, y, radius
  if (i == 4) u8g2.drawDisc(15, 23, 8);                // x, y, radius
  if (i == 5) u8g2.drawEllipse(20, 23, 15, 8);         // x, y, radius_x, radius_y
  if (i == 6) u8g2.drawFilledEllipse(20, 23, 15, 8);   // x, y, radius_x, radius_y
  
  if (i == 7) {
  	u8g2.setFont(u8g2_font_unifont_t_symbols); 
  	u8g2.drawUTF8(5, 23, "Snowman: ☃"); // siehe ganz unten!
  }
  
  if (i == 8) {
  	u8g2.setFont(u8g2_font_unifont_t_symbols); 
  	u8g2.drawGlyph(5, 27, 9731);// x, y, Unicodenumber
  } 
  
  if (i == 9) u8g2.drawLine(5, 23, 100, 15);
  if (i == 10) u8g2.drawPixel(5, 23);
  
  u8g2.sendBuffer();

  i++; if (i == 11) i = 0;

  delay(5000);
}



Da für den Schneemann bei "if (i == 7)" ein UTF8-Schneemannsymbol erforderlich ist (welches Dein Browser wahrscheinlich falsch darstellt), gibt es hier den originalen Quelltext als Arduino-Sketch zum Download.