osresearch / esp32-ttgo

Code for the TT GO ESP32 module
156 stars 49 forks source link

Add a simpler helloworld example #4

Open zoobab opened 6 years ago

zoobab commented 6 years ago

Hi,

I am trying out this simple helloworld code:

https://techtutorialsx.com/2017/12/02/esp32-arduino-interacting-with-a-ssd1306-oled-display/

Would it be possible to add such example to your repo?

Best

echelon75 commented 4 years ago

Hi,

Here is a single demo code: `// Classic Munching Squares effect.

// #include // Only needed for Arduino 1.6.5 and earlier

include "SSD1306.h" // alias for #include "SSD1306Wire.h"

//OLED pins to ESP32 GPIOs via this connecthin: //OLED_SDA -- GPIO4 //OLED_SCL -- GPIO15 //OLED_RST -- GPIO16

SSD1306 display(0x3c, 4, 15);

const unsigned int WIDTH = 128; const unsigned int HEIGHT = 64;

// 128x64 display unsigned char image[WIDTH*HEIGHT/8];

void munching(unsigned char t) { for (int i = 0; i < WIDTH/8; i++) { for (int j = 0; j < HEIGHT; j++) { const unsigned int idx = j(WIDTH/8) + i; unsigned char c = 0x0; for (int k = 0; k < 8; k++) { const unsigned int y = j; const unsigned int x = (i8)+k; if ((x^y) < t) { c |= (1<<(7-k)); }
} image[idx]=c; } } }

void setup() { pinMode(16,OUTPUT); digitalWrite(16, LOW); // set GPIO16 low to reset OLED delay(50); digitalWrite(16, HIGH); // while OLED is running, must set GPIO16 in high

Serial.begin(115200); Serial.println(); Serial.println();

display.init();

display.flipScreenVertically(); display.displayOn(); display.init(); }

unsigned char t = 0;

void loop() { munching(t); t++; if (t > 128) t = 0; display.clear(); // display.drawXbm(0,0,128,64,(const char)image); // If you receive an error during compilation : // My_SSD1306_On_TTGO_Oled:59:48: error: invalid conversion from 'const char' to 'const uint8_t {aka const unsigned char}' [-fpermissive] // display.drawXbm(0,0,128,64,(const char)image); // uncomment this line herafter
display.drawXbm(0,0,128,64,(const uint8_t
)image); // Swap over to get an interleaved munching squares :) //display.drawFastImage(0,0,128,64,(const char*)image); display.display(); delay(2);
}`

Regards

Richard