Script – Walking bitmap

Display OLED via I2C (SH1106)

Script – Walking bitmap

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
 
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
// U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE); // I2C / TWI  
 
const uint8_t bm[] PROGMEM = {
  0b00011000,
  0b00111100,
  0b01111110,
  0b11111111,
  0b11111111,
  0b01111110,
  0b00111100,
  0b00011000
};
 
static int WIDTH=128;
static int HEIGHT=64;
 
int x, y;
 
void setup(void) {
  u8g.begin();
  x = 0;
  y = 0;
}
 
void loop(void) {
 
  u8g.firstPage();  
  do {
    u8g.drawBitmap( x, y, 1, 8, bm);
  } while( u8g.nextPage() );
  
  delay(100);
 
  x += 8;
  if( x >= WIDTH){
    x = 0;
    y += 8;
    if( y >= HEIGHT){
      y = 0;
    }
  }
}

ref:

Leave a Reply

Your email address will not be published. Required fields are marked *