Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MODIFIED Small Simple OLED library demo
- // betlog - 2019-07-16--23-09-43
- // drawpixel DOES require #define USE_BACKBUFFER to be set at start of ../libraries/ss_oled/src/ss_oled.cpp
- // https://github.com/bitbank2/ss_oled
- // https://github.com/bitbank2/BitBang_I2C
- // 72x40, 96x16, 64x32, 128x32, 128x64 and 132x64 (SH1106) display sizes
- //
- //--- user specified ---
- int X=128;
- int Y=32;
- //------------
- #include <ss_oled.h>
- void setup() {
- int rc;
- if (X == 72) {
- rc = oledInit(OLED_72x40, 0, 0, -1, -1,400000L); // use standard I2C bus at 400Khz
- } else if (X == 96) {
- rc = oledInit(OLED_96x16, 0, 0, -1, -1,400000L); // use standard I2C bus at 400Khz
- } else if (X == 64) {
- rc = oledInit(OLED_64x32, 0, 0, -1, -1,400000L); // use standard I2C bus at 400Khz
- } else if (X == 128) {
- if (Y == 32) {
- rc = oledInit(OLED_128x32, 0, 0, -1, -1,400000L); // use standard I2C bus at 400Khz
- } else if (Y == 64) {
- rc = oledInit(OLED_128x64, 0, 0, -1, -1,400000L); // use standard I2C bus at 400Khz
- } else if (X == 132) {
- rc = oledInit(OLED_132x64, 0, 0, -1, -1,400000L); // use standard I2C bus at 400Khz
- }
- }
- if (rc != OLED_NOT_FOUND)
- {
- char *msgs[] = {"SSD1306 @ 0x3C", "SSD1306 @ 0x3D","SH1106 @ 0x3C","SH1106 @ 0x3D"};
- oledFill(0);
- oledWriteString(0,0,msgs[rc], FONT_NORMAL, 0);
- delay(2000);
- }
- Serial.begin(115200);
- }
- void loop() {
- int i, x, y, j, rot, max;
- oledFill(0);
- rot=360;
- j;
- for (j=0;j<rot; j++){
- x=map(j,0,360,0,X);
- y=map(sin(j*DEG_TO_RAD)*10, -10, 10, Y*10, 0);
- y/=10.0;
- Serial.print("x: " );
- Serial.print(x);
- Serial.print("y: " );
- Serial.println(y);
- oledSetPixel(x, y, 1);
- }
- delay(3000);
- oledFill(0);
- rot=1800;
- for (j=0;j<rot; j++){
- x=map(j,0,1800,0,X);
- y=map(sin(j*DEG_TO_RAD)*10, -10, 10, Y*10, 0);
- y/=10.0;
- Serial.print("x: " );
- Serial.print(x);
- Serial.print("y: " );
- Serial.println(y);
- oledSetPixel(x, y, 1);
- }
- delay(3000);
- oledFill(0x0);
- oledWriteString(0,0,(char *)"normal-1234567890abcdef", FONT_NORMAL, 0);
- oledWriteString(0,1,(char *)"normal-1234567890abcdef", FONT_NORMAL, 0);
- oledWriteString(0,2,(char *)"normal-1234567890abcdef", FONT_NORMAL, 0);
- oledWriteString(0,3,(char *)"normal-1234567890abcdef", FONT_NORMAL, 0);
- delay(2000);
- oledFill(0x0);
- oledWriteString(0,0,(char *)"normal-1234567890abcdef", FONT_NORMAL, 1);
- oledWriteString(0,1,(char *)"normal-1234567890abcdef", FONT_NORMAL, 1);
- oledWriteString(0,2,(char *)"normal-1234567890abcdef", FONT_NORMAL, 1);
- oledWriteString(0,3,(char *)"normal-1234567890abcdef", FONT_NORMAL, 1);
- delay(2000);
- oledFill(0x0);
- oledWriteString(0,0,(char *)"small-1234567890abcdef", FONT_SMALL, 0);
- oledWriteString(0,1,(char *)"small-1234567890abcdef", FONT_SMALL, 0);
- oledWriteString(0,2,(char *)"small-1234567890abcdef", FONT_SMALL, 0);
- oledWriteString(0,3,(char *)"small-1234567890abcdef", FONT_SMALL, 0);
- delay(2000);
- oledFill(0x0);
- oledWriteString(0,0,(char *)"small-1234567890abcdef", FONT_SMALL, 1);
- oledWriteString(0,1,(char *)"small-1234567890abcdef", FONT_SMALL, 1);
- oledWriteString(0,2,(char *)"small-1234567890abcdef", FONT_SMALL, 1);
- oledWriteString(0,3,(char *)"small-1234567890abcdef", FONT_SMALL, 1);
- delay(2000);
- // oledFill(0x0);
- // oledWriteString(0,0,(char *)"large-1234567890abcdef", FONT_LARGE, 0);
- // oledWriteString(0,1,(char *)"large-1234567890abcdef", FONT_LARGE, 0);
- // oledWriteString(0,2,(char *)"large-1234567890abcdef", FONT_LARGE, 0);
- // oledWriteString(0,3,(char *)"large-1234567890abcdef", FONT_LARGE, 0);
- // delay(2000);
- //
- // oledFill(0x0);
- // oledWriteString(0,0,(char *)"large-1234567890abcdef", FONT_LARGE, 1);
- // oledWriteString(0,1,(char *)"large-1234567890abcdef", FONT_LARGE, 1);
- // oledWriteString(0,2,(char *)"large-1234567890abcdef", FONT_LARGE, 1);
- // oledWriteString(0,3,(char *)"large-1234567890abcdef", FONT_LARGE, 1);
- // delay(2000);
- oledFill(0x0);
- oledWriteString(0,0,(char *)"fill", FONT_NORMAL, 0);
- delay(1000);
- oledFill(0);
- y=0;
- x=0;
- max=X*Y;
- for (i=0; i<max; i++) {
- x+=1;
- if (x>=X) {
- y+=1;
- x=0;
- }
- if (y>=Y) {
- y=0;
- }
- oledSetPixel(x, y, 1);
- // delay(5);
- }
- delay(3000);
- oledFill(0x0);
- oledWriteString(0,0,(char *)"fill", FONT_NORMAL, 0);
- delay(1000);
- oledFill(0);
- y=0;
- x=0;
- max=X*Y;
- for (i=0; i<max; i++) {
- y+=1;
- if (y>=Y) {
- x+=1;
- y=0;
- }
- if (x>=X) {
- x=0;
- }
- oledSetPixel(x, y, 1);
- // delay(5);
- }
- delay(3000);
- oledFill(0x0);
- oledWriteString(0,0,(char *)"random", FONT_SMALL, 0);
- delay(1000);
- oledFill(0);
- for (i=0; i<250; i++) {
- x = random(X);
- y = random(Y);
- oledSetPixel(x, y, 1);
- delay(50);
- oledSetPixel(x, y, 0);
- }
- oledFill(0x0);
- oledWriteString(0,0,(char *)"fastrandom", FONT_SMALL, 0);
- delay(1000);
- oledFill(0);
- for (i=0; i<5000; i++) {
- x = random(X);
- y = random(Y);
- oledSetPixel(x, y, 1);
- oledSetPixel(x, y, 0);
- }
- //
- // By default, the line drawing function is disabled on AVR since it requires a backing buffer (1K RAM)
- // Which is usually a large % on most of the AVRs (Arduino UNO only has 2K RAM total)
- // To enable this functionality, define USE_BACKBUFFER at the beginning of ss_oled.cpp
- //
- #ifndef __AVR__
- oledFill(0);
- for (x=0; x<X-1; x+=2)
- {
- oledDrawLine(x, 0, X-1-x, Y-1);
- }
- for (y=0; y<Y-1; y+=2)
- {
- oledDrawLine(X-1,y, 0,Y-1-y);
- }
- delay(2000);
- #endif // !__AVR__
- } /* main() */
Advertisement
Add Comment
Please, Sign In to add comment