Advertisement
Guest User

Arduino SH1106 test sketch

a guest
Aug 26th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include "U8glib.h"
  2.  
  3. U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9);
  4.  
  5. int cnt;
  6.  
  7. void draw(void) {
  8.   // graphic commands to redraw the complete screen should be placed here  
  9.   u8g.setFont(u8g_font_unifont);
  10.   //u8g.setFont(u8g_font_osb21);
  11.   u8g.drawStr( 0, 22, "Hello World!");
  12. }
  13.  
  14. void setup(void) {
  15.   // flip screen, if required
  16.   // u8g.setRot180();
  17.  
  18.   // set SPI backup if required
  19.   //u8g.setHardwareBackup(u8g_backup_avr_spi);
  20.  
  21.   // assign default color value
  22.   if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
  23.     u8g.setColorIndex(255);     // white
  24.   }
  25.   else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
  26.     u8g.setColorIndex(3);         // max intensity
  27.   }
  28.   else if ( u8g.getMode() == U8G_MODE_BW ) {
  29.     u8g.setColorIndex(1);         // pixel on
  30.   }
  31.   else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
  32.     u8g.setHiColorByRGB(255,255,255);
  33.   }
  34.  
  35.   cnt = 3;
  36. }
  37.  
  38. void loop(void) {
  39.   // picture loop
  40.   u8g.firstPage();  
  41.   do {
  42.     draw();
  43.   } while( u8g.nextPage() );
  44.  
  45.   // rebuild the picture after some delay
  46.   delay(1000);
  47.  
  48.   switch(--cnt){
  49.     case 2:
  50.       u8g.setRot90();
  51.       break;
  52.     case 1:
  53.       u8g.setRot180();
  54.       break;
  55.     case 0:
  56.       u8g.setRot270();
  57.       break;
  58.     default:
  59.       u8g.undoRotation();
  60.       cnt = 3;
  61.   }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement