betlog

I2C_oled_1306_easySetResolution.ino

Jul 21st, 2019
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // MODIFIED Small Simple OLED library demo
  2. // betlog - 2019-07-16--23-09-43
  3. // drawpixel DOES require #define USE_BACKBUFFER to be set at start of ../libraries/ss_oled/src/ss_oled.cpp
  4. // https://github.com/bitbank2/ss_oled
  5. // https://github.com/bitbank2/BitBang_I2C
  6. // 72x40, 96x16, 64x32, 128x32, 128x64 and 132x64 (SH1106) display sizes
  7. //
  8. //--- user specified ---
  9. int X=128;
  10. int Y=32;
  11. //------------
  12. #include <ss_oled.h>
  13. void setup() {
  14.     int rc;
  15.     if (X == 72) {
  16.         rc = oledInit(OLED_72x40, 0, 0, -1, -1,400000L); // use standard I2C bus at 400Khz
  17.     } else if (X == 96) {
  18.         rc = oledInit(OLED_96x16, 0, 0, -1, -1,400000L); // use standard I2C bus at 400Khz
  19.     } else if (X == 64) {
  20.         rc = oledInit(OLED_64x32, 0, 0, -1, -1,400000L); // use standard I2C bus at 400Khz
  21.     } else if (X == 128) {
  22.         if (Y == 32) {
  23.             rc = oledInit(OLED_128x32, 0, 0, -1, -1,400000L); // use standard I2C bus at 400Khz
  24.         } else if (Y == 64) {
  25.             rc = oledInit(OLED_128x64, 0, 0, -1, -1,400000L); // use standard I2C bus at 400Khz
  26.         } else if (X == 132) {                        
  27.             rc = oledInit(OLED_132x64, 0, 0, -1, -1,400000L); // use standard I2C bus at 400Khz
  28.         }
  29.     }
  30.     if (rc != OLED_NOT_FOUND)
  31.     {
  32.         char *msgs[] = {"SSD1306 @ 0x3C", "SSD1306 @ 0x3D","SH1106 @ 0x3C","SH1106 @ 0x3D"};
  33.         oledFill(0);
  34.         oledWriteString(0,0,msgs[rc], FONT_NORMAL, 0);
  35.         delay(2000);
  36.     }
  37.     Serial.begin(115200);
  38. }
  39.  
  40. void loop() {
  41.  
  42. int i, x, y, j, rot, max;    
  43.  
  44.     oledFill(0);  
  45.     rot=360;
  46.     j;
  47.     for (j=0;j<rot; j++){
  48.         x=map(j,0,360,0,X);
  49.         y=map(sin(j*DEG_TO_RAD)*10, -10, 10, Y*10, 0);
  50.         y/=10.0;
  51.         Serial.print("x: " );
  52.         Serial.print(x);
  53.         Serial.print("y: " );
  54.         Serial.println(y);        
  55.         oledSetPixel(x, y, 1);    
  56.     }
  57.     delay(3000);  
  58.    
  59.     oledFill(0);      
  60.     rot=1800;
  61.     for (j=0;j<rot; j++){
  62.         x=map(j,0,1800,0,X);
  63.         y=map(sin(j*DEG_TO_RAD)*10, -10, 10, Y*10, 0);
  64.         y/=10.0;
  65.         Serial.print("x: " );
  66.         Serial.print(x);
  67.         Serial.print("y: " );
  68.         Serial.println(y);        
  69.         oledSetPixel(x, y, 1);    
  70.     }
  71.     delay(3000);    
  72.    
  73.    
  74.    
  75.    
  76.    
  77.    
  78.  
  79.  
  80.   oledFill(0x0);
  81.   oledWriteString(0,0,(char *)"normal-1234567890abcdef", FONT_NORMAL, 0);
  82.   oledWriteString(0,1,(char *)"normal-1234567890abcdef", FONT_NORMAL, 0);
  83.   oledWriteString(0,2,(char *)"normal-1234567890abcdef", FONT_NORMAL, 0);    
  84.   oledWriteString(0,3,(char *)"normal-1234567890abcdef", FONT_NORMAL, 0);    
  85.   delay(2000);
  86.  
  87.   oledFill(0x0);
  88.   oledWriteString(0,0,(char *)"normal-1234567890abcdef", FONT_NORMAL, 1);
  89.   oledWriteString(0,1,(char *)"normal-1234567890abcdef", FONT_NORMAL, 1);  
  90.   oledWriteString(0,2,(char *)"normal-1234567890abcdef", FONT_NORMAL, 1);      
  91.   oledWriteString(0,3,(char *)"normal-1234567890abcdef", FONT_NORMAL, 1);    
  92.   delay(2000);
  93.  
  94.  
  95.   oledFill(0x0);
  96.   oledWriteString(0,0,(char *)"small-1234567890abcdef", FONT_SMALL, 0);
  97.   oledWriteString(0,1,(char *)"small-1234567890abcdef", FONT_SMALL, 0);  
  98.   oledWriteString(0,2,(char *)"small-1234567890abcdef", FONT_SMALL, 0);    
  99.   oledWriteString(0,3,(char *)"small-1234567890abcdef", FONT_SMALL, 0);    
  100.   delay(2000);
  101.  
  102.   oledFill(0x0);
  103.   oledWriteString(0,0,(char *)"small-1234567890abcdef", FONT_SMALL, 1);
  104.   oledWriteString(0,1,(char *)"small-1234567890abcdef", FONT_SMALL, 1);
  105.   oledWriteString(0,2,(char *)"small-1234567890abcdef", FONT_SMALL, 1);    
  106.   oledWriteString(0,3,(char *)"small-1234567890abcdef", FONT_SMALL, 1);    
  107.   delay(2000);
  108.  
  109. //   oledFill(0x0);
  110. //   oledWriteString(0,0,(char *)"large-1234567890abcdef", FONT_LARGE, 0);
  111. //   oledWriteString(0,1,(char *)"large-1234567890abcdef", FONT_LARGE, 0);
  112. //   oledWriteString(0,2,(char *)"large-1234567890abcdef", FONT_LARGE, 0);    
  113. //   oledWriteString(0,3,(char *)"large-1234567890abcdef", FONT_LARGE, 0);    
  114. //   delay(2000);
  115. //
  116. //   oledFill(0x0);
  117. //   oledWriteString(0,0,(char *)"large-1234567890abcdef", FONT_LARGE, 1);
  118. //   oledWriteString(0,1,(char *)"large-1234567890abcdef", FONT_LARGE, 1);
  119. //   oledWriteString(0,2,(char *)"large-1234567890abcdef", FONT_LARGE, 1);    
  120. //   oledWriteString(0,3,(char *)"large-1234567890abcdef", FONT_LARGE, 1);    
  121. //   delay(2000);
  122.  
  123.  
  124.   oledFill(0x0);
  125.   oledWriteString(0,0,(char *)"fill", FONT_NORMAL, 0);
  126.   delay(1000);
  127.   oledFill(0);
  128.   y=0;
  129.   x=0;
  130.   max=X*Y;
  131.   for (i=0; i<max; i++) {
  132.     x+=1;
  133.     if (x>=X) {
  134.         y+=1;
  135.         x=0;
  136.     }
  137.     if (y>=Y) {
  138.         y=0;
  139.     }
  140.     oledSetPixel(x, y, 1);    
  141. //     delay(5);
  142.   }
  143.   delay(3000);    
  144.  
  145.  
  146.  
  147.   oledFill(0x0);
  148.   oledWriteString(0,0,(char *)"fill", FONT_NORMAL, 0);
  149.   delay(1000);
  150.   oledFill(0);
  151.   y=0;
  152.   x=0;
  153.   max=X*Y;
  154.   for (i=0; i<max; i++) {
  155.     y+=1;
  156.     if (y>=Y) {
  157.         x+=1;
  158.         y=0;
  159.     }
  160.     if (x>=X) {
  161.         x=0;
  162.     }
  163.     oledSetPixel(x, y, 1);    
  164. //     delay(5);
  165.   }
  166.   delay(3000);    
  167.  
  168.  
  169.  
  170.   oledFill(0x0);
  171.   oledWriteString(0,0,(char *)"random", FONT_SMALL, 0);
  172.   delay(1000);
  173.   oledFill(0);
  174.   for (i=0; i<250; i++) {
  175.     x = random(X);
  176.     y = random(Y);
  177.     oledSetPixel(x, y, 1);
  178.     delay(50);        
  179.     oledSetPixel(x, y, 0);
  180.    
  181.   }
  182.  
  183.   oledFill(0x0);
  184.   oledWriteString(0,0,(char *)"fastrandom", FONT_SMALL, 0);
  185.   delay(1000);
  186.   oledFill(0);
  187.   for (i=0; i<5000; i++) {
  188.     x = random(X);
  189.     y = random(Y);
  190.     oledSetPixel(x, y, 1);
  191.     oledSetPixel(x, y, 0);
  192.   }
  193.  
  194. //
  195. // By default, the line drawing function is disabled on AVR since it requires a backing buffer (1K RAM)
  196. // Which is usually a large % on most of the AVRs (Arduino UNO only has 2K RAM total)
  197. // To enable this functionality, define USE_BACKBUFFER at the beginning of ss_oled.cpp
  198. //
  199. #ifndef __AVR__
  200.   oledFill(0);
  201.   for (x=0; x<X-1; x+=2)
  202.   {
  203.     oledDrawLine(x, 0, X-1-x, Y-1);
  204.   }
  205.   for (y=0; y<Y-1; y+=2)
  206.   {
  207.     oledDrawLine(X-1,y, 0,Y-1-y);
  208.   }
  209.   delay(2000);
  210. #endif // !__AVR__
  211. } /* main() */
Advertisement
Add Comment
Please, Sign In to add comment