Image Crossfade


(spinal) #1

In a slight continuation from the screen brightness thread, I have started an example of fading between two images. It flickers a bit, but then, everything that attempts to fade does right now.

If anyone thinks that they can clean it up a little, maybe cut down the flicker a bit, please show what you can do :slight_smile:

Here is the code, itโ€™s quite simple.

bool oldSerial=0;

const unsigned char image1[] PROGMEM = {
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0x7f, 0x3f, 0x7f, 0xff, 0x7f, 0x67, 
  0x47, 0x47, 0x7f, 0xff, 0xef, 0x87, 0x87, 0xcf, 
  0xff, 0x87, 0x47, 0x67, 0xff, 0xff, 0x8f, 0x0f, 
  0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x3f, 0x7f, 
  0xff, 0x7f, 0x67, 0x47, 0x47, 0x7f, 0xff, 0xef, 
  0x87, 0x87, 0xcf, 0xff, 0x87, 0x47, 0x67, 0xff, 
  0xff, 0x8f, 0x0f, 0x1f, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 
  0xff, 0x7f, 0x7f, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0x7f, 0xff, 0xff, 0xff, 0xcf, 0x8f, 0x8f, 0xff, 
  0xff, 0xdf, 0x0f, 0x0f, 0x9f, 0xff, 0x0f, 0x8f, 
  0xcf, 0xff, 0xff, 0x1f, 0x1f, 0x3f, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 
  0x8f, 0xbf, 0x86, 0x04, 0x00, 0x0f, 0x1e, 0x38, 
  0xd8, 0x80, 0x30, 0x37, 0x7e, 0xe1, 0x0f, 0xf9, 
  0x04, 0x82, 0x40, 0x20, 0x0f, 0x83, 0x01, 0x01, 
  0xc2, 0x0c, 0x08, 0x08, 0x0f, 0xdf, 0xdd, 0x30, 
  0xf0, 0x39, 0x8f, 0x00, 0x08, 0x04, 0x04, 0x00, 
  0x01, 0x00, 0x00, 0xd8, 0x80, 0x10, 0x37, 0x7e, 
  0xe1, 0x0f, 0xf9, 0x04, 0x82, 0x40, 0x20, 0x3f, 
  0xc3, 0x01, 0x01, 0xc2, 0xcf, 0xf8, 0x00, 0x03, 
  0x07, 0xff, 0xe7, 0x86, 0x84, 0x04, 0x07, 0x7f, 
  0xee, 0x18, 0xf8, 0x9c, 0x4f, 0x28, 0x04, 0x06, 
  0xff, 0x3f, 0x18, 0x10, 0x01, 0x1f, 0x0f, 0x0c, 
  0x08, 0x00, 0x1f, 0x3c, 0x70, 0xb0, 0x00, 0x60, 
  0x6f, 0xfd, 0xc3, 0x1f, 0xf3, 0x09, 0x05, 0x80, 
  0x40, 0x7f, 0x87, 0x03, 0x02, 0x84, 0x9f, 0xf1, 
  0x31, 0x3f, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcd, 0xc8, 
  0xf8, 0xd9, 0x89, 0x86, 0x86, 0x06, 0x8e, 0xcc, 
  0x7f, 0x37, 0x2c, 0x6c, 0x90, 0x1f, 0x00, 0x2f, 
  0xa7, 0x01, 0x00, 0x30, 0x20, 0xc0, 0xc0, 0xc1, 
  0xc1, 0x80, 0xf8, 0xf0, 0x86, 0x86, 0x07, 0xf4, 
  0x01, 0xcd, 0xc0, 0x30, 0x08, 0x00, 0x06, 0x06, 
  0x06, 0x8e, 0xcc, 0x7f, 0x37, 0x2c, 0x6c, 0x90, 
  0x1f, 0x00, 0x2f, 0xe7, 0x01, 0x80, 0x70, 0x28, 
  0xa0, 0xff, 0x1f, 0x00, 0x08, 0x18, 0x18, 0x60, 
  0x60, 0x60, 0xe1, 0xc3, 0xfd, 0x78, 0xc3, 0xc3, 
  0x07, 0xfe, 0x00, 0xff, 0x70, 0x18, 0x04, 0x02, 
  0x83, 0x0c, 0xf0, 0x90, 0x10, 0x80, 0x83, 0x01, 
  0x0c, 0x0c, 0x0c, 0x1c, 0x98, 0xff, 0x6f, 0x58, 
  0xd8, 0x20, 0x3f, 0x00, 0x5f, 0xce, 0x03, 0x00, 
  0xe0, 0x50, 0x41, 0xfe, 0x7e, 0x63, 0x71, 0x31, 
  0x31, 0x3f, 0x4f, 0xcf, 0xef, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xfc, 0xe8, 0xc5, 0x87, 0x87, 0x84, 0x84, 0x9d, 
  0xd8, 0xe0, 0xc0, 0xe0, 0x38, 0x00, 0x00, 0xc2, 
  0xf1, 0x79, 0x06, 0x13, 0x31, 0x60, 0x70, 0x80, 
  0x91, 0xb9, 0x0f, 0x06, 0x05, 0x0d, 0x12, 0x03, 
  0x00, 0x45, 0x7c, 0xa0, 0xc0, 0x44, 0x05, 0x04, 
  0x04, 0x84, 0x05, 0x40, 0xc0, 0xc0, 0xc0, 0x20, 
  0x00, 0x00, 0xc2, 0xf3, 0x7d, 0x26, 0x33, 0x33, 
  0x61, 0x7b, 0x9c, 0x98, 0x8a, 0x8c, 0x58, 0x78, 
  0x78, 0x40, 0x48, 0xdc, 0x87, 0x03, 0x02, 0x06, 
  0x89, 0x01, 0x00, 0x22, 0x3e, 0xd0, 0x68, 0x37, 
  0x32, 0x1a, 0xbf, 0xf3, 0xb3, 0xa1, 0xc1, 0x81, 
  0x01, 0x02, 0x00, 0x09, 0x3b, 0xb0, 0xc0, 0x80, 
  0xc0, 0x71, 0x00, 0x00, 0x84, 0xe7, 0xfa, 0x4d, 
  0x66, 0x66, 0xc3, 0xf7, 0x3e, 0x36, 0x34, 0xfc, 
  0xfc, 0xfc, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xfc, 0xf8, 0xf8, 0x0f, 0x00, 0x00, 0x00, 0xff, 
  0xfd, 0xfc, 0xf8, 0xf8, 0xf8, 0xf0, 0xf0, 0xf0, 
  0xf0, 0xf3, 0x9b, 0x1c, 0x18, 0xfc, 0x07, 0x00, 
  0x00, 0xf8, 0xbe, 0x8f, 0x04, 0x06, 0x86, 0x8c, 
  0xcf, 0xf3, 0xf3, 0xf0, 0xf8, 0xf8, 0x0f, 0x00, 
  0x00, 0x00, 0xff, 0xfd, 0xfc, 0xf8, 0xf8, 0xfc, 
  0xfc, 0xfe, 0xff, 0xff, 0xff, 0xfe, 0xfc, 0xf8, 
  0xf8, 0xf8, 0xf8, 0xf9, 0xcd, 0x8e, 0x8c, 0xfe, 
  0x03, 0x00, 0x00, 0xfc, 0xdf, 0xc7, 0x82, 0x83, 
  0xc3, 0xc6, 0xe7, 0xf9, 0xf9, 0xf9, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, 0xf1, 0xf1, 
  0x1f, 0x00, 0x00, 0x00, 0xff, 0xfb, 0xf8, 0xf0, 
  0xf0, 0xf8, 0xf8, 0xfc, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 
  0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 
  0xbf, 0xbf, 0xbf, 0x80, 0x80, 0x80, 0x80, 0x87, 
  0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 
  0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0x01, 0x00, 0x00, 
  0x00, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 
  0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0x80, 0x80, 
  0x80, 0x80, 0x87, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 
  0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 
  0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0x00, 
  0x00, 0x00, 0x00, 0x3f, 0xbf, 0xbf, 0xbf, 0xbf, 
  0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 
  0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 
  0x00, 0x00, 0x00, 0x00, 0x0f, 0xbf, 0xbf, 0xbf, 
  0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 
  0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 
  0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 
  0xf8, 0xf8, 0xf8, 0xf8, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
};

const unsigned char image2[] PROGMEM = {
0xaa, 0x55, 0xaa, 0x55, 0x2a, 0x55, 0xaa, 0x55, 
0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 
0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 
0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x80, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x2a, 0x15, 0x8a, 0x00, 0x88, 0x45, 0xaa, 0x55, 
0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 
0xaa, 0x55, 0x8a, 0x15, 0x22, 0x11, 0x28, 0x15, 
0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0xf0, 0xf0, 0xe0, 0xc0, 0xc3, 0x9f, 
0xff, 0xff, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0xc0, 0x80, 0x03, 0x0f, 0x1f, 
0x01, 0x00, 0xe0, 0xf8, 0x80, 0x80, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x2a, 0x55, 0x2a, 0x15, 0x2a, 0x55, 0x2a, 0x15, 
0x2a, 0x15, 0x0a, 0x05, 0x02, 0x05, 0x82, 0x41, 
0xa0, 0x51, 0xa8, 0x50, 0xa8, 0x54, 0xa8, 0x54, 
0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x80, 0xc0, 0xc0, 0xe0, 0x60, 0xa0, 0xc0, 
0xc0, 0xe0, 0xc0, 0x00, 0x80, 0x00, 0x00, 0x1e, 
0x7f, 0xfe, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 
0xff, 0x18, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x02, 0x0f, 0x1f, 0x1f, 0x7f, 0xfc, 0xfc, 
0xfe, 0xff, 0x07, 0xc1, 0xff, 0xff, 0x1c, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0xa0, 0x50, 0xa8, 0x50, 0xa8, 0x50, 
0xa8, 0x54, 0xa8, 0x50, 0xa0, 0x50, 0xa2, 0x51, 
0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 
0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 
0x7b, 0x1b, 0x63, 0x7b, 0x3c, 0xbd, 0x9d, 0xcd, 
0xed, 0xe1, 0xf6, 0x27, 0x03, 0x00, 0x00, 0x00, 
0x00, 0x03, 0x3f, 0xff, 0xff, 0x00, 0x3f, 0xff, 
0x99, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x04, 0x3e, 0xff, 0xff, 
0x2f, 0x1f, 0xff, 0x9f, 0x0b, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 
0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 
0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 
0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xb0, 
0xd8, 0xdc, 0x3c, 0xfd, 0xfb, 0xf7, 0xe6, 0xc1, 
0x01, 0x01, 0x01, 0x00, 0x80, 0x80, 0x3a, 0xc6, 
0x16, 0x14, 0xec, 0xe9, 0x29, 0x28, 0xa8, 0xa9, 
0x29, 0xac, 0x14, 0x16, 0xc6, 0x3a, 0x80, 0x80, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 
0x80, 0x3a, 0xc6, 0x16, 0x14, 0xec, 0xe9, 0x29, 
0x28, 0xa8, 0xa9, 0x29, 0xac, 0x14, 0x16, 0xc6, 
0x3a, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0xaa, 0x55, 0xaa, 0x45, 0xa2, 0x45, 
0x8a, 0x05, 0x8a, 0x15, 0x8a, 0x55, 0x8a, 0x55, 
0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 
0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 
0xff, 0x7f, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 
0xff, 0xf0, 0x00, 0x03, 0x00, 0x1c, 0x63, 0xc0, 
0x83, 0x84, 0x89, 0x53, 0x56, 0x74, 0x75, 0x70, 
0x51, 0x48, 0x84, 0x83, 0xc0, 0x63, 0x1c, 0x00, 
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 
0x1c, 0x63, 0xc0, 0x83, 0x84, 0x89, 0x53, 0x56, 
0x74, 0x75, 0x70, 0x51, 0x48, 0x84, 0x83, 0xc0, 
0x63, 0x1c, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x2a, 0x55, 0xaa, 0x55, 0xaa, 0x55, 
0x2a, 0x55, 0x2a, 0x15, 0x0a, 0x15, 0x0a, 0x81, 
0x02, 0x81, 0x42, 0xa1, 0x50, 0xa1, 0x50, 0xa8, 
0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc1, 0x0f, 
0x7f, 0xfe, 0xe0, 0x1c, 0xfc, 0xf8, 0xf8, 0xf9, 
0xf1, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x8c, 0x33, 0x77, 0x77, 0x77, 
0x33, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x33, 
0x77, 0x77, 0x77, 0x33, 0x8c, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x80, 0x40, 0x80, 0x40, 0xa1, 0x50, 0xa8, 
0x50, 0xa8, 0x54, 0xa8, 0x54, 0xaa, 0x55, 0xaa, 
0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 
0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xfe, 
0xf8, 0xe7, 0xcf, 0xde, 0xdd, 0xe3, 0xff, 0xff, 
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 
0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
};


#include "Arduboy.h"

// make an instance of arduboy used for many functions
Arduboy arduboy;

void setContrast(uint8_t contrast)
{
  arduboy.LCDCommandMode();
  SPI.transfer(0x81); // contrast command
  SPI.transfer(contrast);
  arduboy.LCDDataMode();
}

// This function runs once in your game.
// use it for anything that needs to be set only once in your game.
void setup() {
  // initiate arduboy instance
  arduboy.begin();

  arduboy.setFrameRate(60);
  // extra setup for the screen, I think I need it for my clone, but probably not for real arduboy.
  arduboy.LCDCommandMode();
  SPI.transfer(0xD9); // charge time command
  SPI.transfer(0x00); // 0 - 16
  SPI.transfer(0x81); // contrast command
  SPI.transfer(127);
  SPI.transfer(0xdb); // VCOM deselect level mode
  SPI.transfer(0x00); // set vcomh = 0.83 * VCC
  SPI.transfer(0xa4); // set entire display on/off
  SPI.transfer(0xa6); // set normal display
  SPI.transfer(0xaf); // set display on
  arduboy.LCDDataMode();

  oldSerial=Serial;
}

// Button updates
#define HELD 0
#define NEW 1
#define RELEASE 2
byte CompletePad, ExPad, TempPad;
bool _A[3], _B[3], _Up[3], _Down[3], _Left[3], _Right[3];

void UPDATEPAD(int pad, int var) {
  _B[pad] = (var & B_BUTTON) >> 2; // 4
  _A[pad] = (var & A_BUTTON) >> 3; // 8
  _Down[pad] = (var & DOWN_BUTTON) >> 4; // 16
  _Left[pad] = (var & LEFT_BUTTON) >> 5; // 32
  _Right[pad] = (var & RIGHT_BUTTON) >> 6; // 64
  _Up[pad] = (var & UP_BUTTON) >> 7; // 128
}
void UpdatePad(int joy_code)
{
  ExPad = CompletePad;
  CompletePad = joy_code;
  UPDATEPAD(HELD, CompletePad); // held
  UPDATEPAD(RELEASE, (ExPad & (~CompletePad))); // released
  UPDATEPAD(NEW, (CompletePad & (~ExPad))); // newpress
}

int myContrast=0;
int bounce = 1;
int myDelay = 5721+75;
// 75
void loop() {

  //if(!Serial){myDelay = 5721;}else{myDelay = 5721+75;}

  // capture buttons once per loop only
  UpdatePad(arduboy.buttonsState());

  if(_Up[NEW]){myDelay+=5;}  
  if(_Down[NEW]){myDelay-=5;}  
  if(_Right[NEW]){myDelay+=1;}  
  if(_Left[NEW]){myDelay-=1;}  

  delayMicroseconds(myDelay);
  arduboy.clear();
  arduboy.drawBitmap(0,0,image1,128,64,1);
  arduboy.display();
  setContrast(myContrast);
  delayMicroseconds(myDelay);
  arduboy.clear();
  arduboy.drawBitmap(0,0,image2,128,64,1);
  arduboy.display();
  setContrast(127-myContrast);

  myContrast += bounce;
  if(myContrast>=127){bounce=-1; myContrast=127;}
  if(myContrast<=0){bounce=1; myContrast=0;}
}

(Josh Goebel) #2

Video please. Show us.


(spinal) #3

Do twitter videos work here?

Been messing with the timing on my #arduboy crossfade test. It looks much better in real life. pic.twitter.com/3CuxNHwPqu

โ€” Spinal (@Spinal_Cord) January 18, 2017

(Holmes) #4

WOW!

That looks a lot sexier than I thought it would!


(spinal) #5

Regarding the sync issues, are there any commands for the oled that will force reset the redraw? Perhaps we can just send a command or two every couple of frames to force a resync even if we donโ€™t know when the vblank is?