Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a simpler helloworld example #4

Open
zoobab opened this issue Jul 30, 2018 · 1 comment
Open

Add a simpler helloworld example #4

zoobab opened this issue Jul 30, 2018 · 1 comment

Comments

@zoobab
Copy link

zoobab commented Jul 30, 2018

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
Copy link

Hi,

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

// #include <Wire.h> // 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 = (i*8)+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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants