NeTgHoSt
Member
Code:
void draw(void) {
switch (draw_state >> 3) {
case 0: drawRunAnim(draw_state & 7); break;
case 1: drawIronmanLogo(draw_state & 7); break;
}
}
I borrowed some code for my projects experimenting with an SSD1306 i2C display from the u8g2 "Graphics Test" example, some of which uses this advanced (for me) switch/case function to call each graphic test function.
My code just draws two alternating xmp bitmaps, one a still image and the other a 5 frame "animation." They scroll across the screen as they alternate.
I deleted case 3-9 because they aren't needed yet. What I don't understand still, is the (draw_state & 7) parameters for each case. Isn't the "&" symbol for pointers or something? Changing the 7 to a higher number did not increase the time the drawIronmanLogo function ran.. so, what is it? Also, the >> 3 bit shift, what the heck does it do??? That number doesn't seem to respond well to adjustment, either. Forgive my ignorance if I should know these things already, but I only learned how to count in binary and hex yesterday, finally. Here is the full code. Note that some stuff such as the buzzer library aren't being used yet.
Code:
#include <U8g2lib.h>
#include <SPI.h>
#include <Wire.h>
#include "Buzzer.h"
//Compiler / Global Defines
#define BUZZER_PIN_SIG 6 // Beeper pin
#define battLevelPin A9 // Battery reading input
#define battCheckButton 2 //Battery level check button
int led = 13;
//Sensor and Display Connection Setup etc.
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
Buzzer buzzer(BUZZER_PIN_SIG);
#define ironman_width 44
#define ironman_height 64
static const unsigned char ironman_bits[] PROGMEM = {
0x00, 0x00, 0xfc, 0x03, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x3f, 0x00, 0x00,
0x00, 0xf8, 0xff, 0xff, 0x01, 0x00, 0x00, 0x86, 0xff, 0x1f, 0x06, 0x00,
0x80, 0x81, 0xff, 0x1f, 0x18, 0x00, 0xc0, 0x80, 0xff, 0x1f, 0x30, 0x00,
0x20, 0x80, 0xff, 0x1f, 0xc0, 0x00, 0x10, 0x00, 0xff, 0x0f, 0x80, 0x01,
0x08, 0x00, 0xff, 0x0f, 0x00, 0x01, 0x08, 0x00, 0xff, 0x0f, 0x00, 0x02,
0x08, 0x00, 0xff, 0x0f, 0x00, 0x02, 0x08, 0x00, 0xfe, 0x07, 0x00, 0x02,
0x08, 0x00, 0xfe, 0x07, 0x00, 0x02, 0x08, 0x00, 0xfe, 0x07, 0x00, 0x02,
0x08, 0x00, 0x00, 0x00, 0x00, 0x06, 0x08, 0x00, 0x00, 0x00, 0x00, 0x06,
0x08, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0c, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0c, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0c, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x06,
0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06,
0x06, 0x00, 0x00, 0x00, 0x00, 0x0e, 0xc6, 0x07, 0x00, 0x00, 0x7c, 0x0e,
0xe6, 0xff, 0xff, 0xff, 0xff, 0x0e, 0xe6, 0xff, 0x03, 0xf8, 0xff, 0x0c,
0x02, 0x3f, 0x00, 0x80, 0x1f, 0x0c, 0x02, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x03, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x03, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x0c,
0x03, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x06,
0x07, 0x00, 0x00, 0x00, 0x00, 0x06, 0x16, 0x00, 0x00, 0x00, 0x00, 0x06,
0x2e, 0x00, 0x00, 0x00, 0x80, 0x07, 0x6e, 0x00, 0x00, 0x00, 0x40, 0x07,
0x6e, 0x00, 0x00, 0x00, 0x60, 0x07, 0xde, 0x00, 0x00, 0x00, 0xb0, 0x07,
0xde, 0x00, 0x00, 0x00, 0xb0, 0x07, 0x9c, 0x01, 0x00, 0x00, 0xd8, 0x03,
0xbc, 0x01, 0x00, 0x00, 0xf8, 0x03, 0x3c, 0x01, 0x00, 0x00, 0xe8, 0x03,
0x7c, 0x03, 0x00, 0x00, 0xf4, 0x03, 0xfc, 0x02, 0x00, 0x00, 0xf4, 0x03,
0xfc, 0xc2, 0xff, 0x1f, 0xfa, 0x03, 0xf8, 0x25, 0xff, 0x27, 0xfa, 0x01,
0xf8, 0x38, 0x00, 0x60, 0xf9, 0x01, 0xf8, 0x10, 0x00, 0xc0, 0xf8, 0x01,
0xf0, 0x00, 0x00, 0x00, 0xf8, 0x01, 0xf0, 0x00, 0x00, 0x00, 0xf8, 0x01,
0xf0, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xe0, 0xc1, 0xff, 0x0f, 0xf8, 0x00,
0xc0, 0xe3, 0xff, 0x1f, 0x7c, 0x00, 0x80, 0xff, 0xff, 0x7f, 0x3e, 0x00,
0x00, 0xff, 0xff, 0x7f, 0x0f, 0x00, 0x00, 0xf6, 0x00, 0xfe, 0x07, 0x00,
0x00, 0x3c, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x08, 0x00, 0x40, 0x00, 0x00
};
#define runAnim_width 44
#define runAnim_height 52
static const unsigned char runAnim1_bits[] PROGMEM = {
0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x41, 0x00,
0x00, 0x00, 0x00, 0x80, 0xff, 0x00, 0x00, 0x00, 0x06, 0x88, 0xff, 0x01,
0x00, 0x00, 0x0f, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x1f, 0xfe, 0xff, 0x03,
0x00, 0x00, 0xfe, 0xff, 0xff, 0x03, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x07,
0x00, 0x00, 0xfc, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x0f,
0x00, 0x00, 0xff, 0xff, 0x81, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x00, 0x0f,
0x00, 0x00, 0xfe, 0x1f, 0x00, 0x0e, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x0c,
0x00, 0x00, 0xfc, 0x07, 0x0c, 0x0c, 0x00, 0x00, 0xfc, 0x03, 0x0c, 0x0c,
0x00, 0x00, 0xf8, 0x01, 0xc0, 0x0c, 0x00, 0x00, 0xf8, 0x01, 0xc0, 0x0f,
0x00, 0x00, 0xfc, 0x03, 0x80, 0x07, 0x00, 0x78, 0xfe, 0x07, 0x80, 0x03,
0x00, 0xfc, 0xe7, 0x0f, 0xc0, 0x01, 0x80, 0xfe, 0xc3, 0x1f, 0xe0, 0x00,
0xc0, 0xe7, 0xc1, 0xff, 0x70, 0x00, 0xe0, 0x03, 0xc0, 0xff, 0x39, 0x00,
0x70, 0x01, 0xc0, 0xff, 0x1f, 0x00, 0x38, 0xf8, 0xe0, 0xff, 0x1f, 0x00,
0x38, 0xfc, 0xff, 0xff, 0x3f, 0x00, 0x70, 0xfe, 0xff, 0xff, 0x73, 0x08,
0xe0, 0x97, 0xff, 0xff, 0x39, 0x0c, 0xc0, 0x83, 0xff, 0xff, 0x70, 0x0e,
0x80, 0xc1, 0xff, 0xff, 0xe0, 0x07, 0x00, 0xc0, 0xff, 0xff, 0xc5, 0x03,
0x00, 0xc0, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0x1f, 0x08,
0x00, 0xf0, 0xff, 0xff, 0xf9, 0x0f, 0x00, 0xf8, 0xff, 0xcf, 0xf0, 0x0f,
0x00, 0xfc, 0xff, 0xcf, 0xe0, 0x0f, 0x00, 0xce, 0xff, 0xff, 0x00, 0x00,
0x00, 0x87, 0xff, 0xff, 0x00, 0x00, 0x80, 0x03, 0xff, 0xff, 0x81, 0x01,
0xc0, 0x01, 0xfe, 0xff, 0xc3, 0x03, 0xe0, 0x00, 0xfe, 0xff, 0xe7, 0x07,
0x70, 0x00, 0xff, 0xff, 0xff, 0x03, 0x38, 0x80, 0xff, 0xff, 0xff, 0x03,
0x1c, 0xc0, 0xe1, 0xff, 0xff, 0x03, 0x0e, 0xe0, 0xc0, 0xff, 0xff, 0x03,
0x0e, 0x70, 0x00, 0xfe, 0xff, 0x07, 0x1c, 0x70, 0x00, 0xfc, 0xff, 0x03,
0x38, 0xe0, 0x00, 0xe0, 0xff, 0x01, 0x70, 0xe0, 0x00, 0xc0, 0xff, 0x00,
0xe0, 0x7f, 0x00, 0x00, 0x7e, 0x00, 0xc0, 0x3f, 0x00, 0x00, 0x3c, 0x00
};
static const unsigned char runAnim2_bits[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x00,
0x00, 0x00, 0x00, 0xc0, 0xff, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x01,
0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x02, 0xfe, 0xff, 0x03,
0x00, 0x00, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0xff, 0x07,
0x00, 0x00, 0xfe, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x0f,
0x00, 0x00, 0xff, 0xff, 0x81, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x00, 0x0f,
0x00, 0x00, 0xfe, 0x1f, 0x00, 0x0e, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x0c,
0x00, 0x00, 0xfc, 0x07, 0x0c, 0x0c, 0x00, 0x00, 0xfc, 0x03, 0x0c, 0x0c,
0x00, 0x00, 0xf8, 0x01, 0xc0, 0x0c, 0x00, 0x00, 0xf8, 0x01, 0xc0, 0x0f,
0x00, 0x00, 0xfc, 0x03, 0x80, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x80, 0x03,
0x00, 0x00, 0x9f, 0x0f, 0xc0, 0x01, 0x00, 0x80, 0x0f, 0x1f, 0xe0, 0x00,
0x00, 0x80, 0x07, 0xfe, 0x7c, 0x00, 0x00, 0x80, 0x03, 0xfc, 0x3f, 0x00,
0x00, 0x80, 0x03, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0x07, 0xfe, 0x0f, 0x00,
0x00, 0x00, 0x07, 0xff, 0x0f, 0x00, 0x00, 0x80, 0x07, 0xff, 0x1f, 0x00,
0x00, 0xc0, 0x07, 0xff, 0x3f, 0x00, 0x00, 0xc0, 0x83, 0xff, 0x73, 0x00,
0x00, 0xc0, 0xc1, 0xff, 0xe1, 0x00, 0x00, 0xe0, 0xc0, 0xff, 0xc0, 0x01,
0x00, 0xf0, 0xc0, 0xff, 0xc0, 0x01, 0x00, 0xf8, 0xe0, 0xff, 0xe9, 0x00,
0x00, 0xf0, 0xf0, 0xff, 0x7f, 0x00, 0x00, 0xf0, 0xf9, 0xff, 0x3f, 0x00,
0x00, 0xf8, 0xff, 0x9f, 0x17, 0x00, 0x00, 0x38, 0xff, 0x0f, 0x03, 0x00,
0x00, 0x38, 0xfe, 0x0f, 0x07, 0x00, 0x00, 0x78, 0xfc, 0x9f, 0x03, 0x00,
0x00, 0x38, 0xf8, 0xff, 0x01, 0x00, 0x00, 0x70, 0xf8, 0xff, 0x00, 0x00,
0x00, 0xe0, 0xff, 0x5f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x0f, 0x00, 0x00,
0x00, 0x80, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00,
0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00,
0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0x00, 0x00,
0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00
};
static const unsigned char runAnim3_bits[] PROGMEM = {
0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x41, 0x00,
0x00, 0x00, 0x00, 0x80, 0xff, 0x00, 0x00, 0x00, 0x06, 0x88, 0xff, 0x01,
0x00, 0x00, 0x0f, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x1f, 0xfe, 0xff, 0x07,
0x00, 0x00, 0xfe, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x0f,
0x00, 0x00, 0xfc, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x0f,
0x00, 0x00, 0xff, 0xff, 0x07, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x03, 0x0c,
0x00, 0x00, 0xfe, 0x7f, 0x00, 0x0c, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x0c,
0x00, 0x00, 0xfc, 0x1f, 0x30, 0x0c, 0x00, 0x00, 0xfc, 0x0f, 0x30, 0x0c,
0x00, 0x00, 0xf8, 0x07, 0x00, 0x0c, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x0e,
0x00, 0x00, 0xf0, 0x03, 0x00, 0x07, 0x00, 0x00, 0xf8, 0x07, 0x80, 0x03,
0x00, 0x00, 0x1c, 0x0e, 0xc0, 0x01, 0x00, 0x00, 0x0e, 0x5c, 0xe0, 0x00,
0x00, 0x00, 0x0f, 0xfc, 0x70, 0x00, 0x00, 0x80, 0x0f, 0xfc, 0x39, 0x00,
0x00, 0x00, 0x0f, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x0f, 0x30, 0x0f, 0x00,
0x00, 0x00, 0x0f, 0x30, 0x0e, 0x00, 0x00, 0x00, 0x1f, 0x78, 0x1e, 0x00,
0x00, 0x00, 0x3f, 0xf8, 0x3f, 0x00, 0x00, 0x80, 0x7f, 0xf0, 0x7f, 0x00,
0x00, 0xc0, 0xff, 0xe0, 0x79, 0x00, 0x00, 0xc0, 0xff, 0x01, 0x78, 0x00,
0x00, 0xc0, 0xff, 0x03, 0x3c, 0x00, 0x00, 0xe0, 0xff, 0x67, 0x3e, 0x00,
0x00, 0xf0, 0xff, 0xff, 0x3f, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x3f, 0x00,
0x00, 0xfc, 0xff, 0x9f, 0x79, 0x00, 0x00, 0xfe, 0xff, 0x0f, 0x38, 0x00,
0x00, 0xff, 0xff, 0x07, 0x1c, 0x00, 0x80, 0xff, 0xff, 0x03, 0x0e, 0x00,
0xc0, 0xff, 0xff, 0x01, 0x07, 0x00, 0xe0, 0xff, 0xff, 0x80, 0x03, 0x00,
0xf0, 0xff, 0xff, 0xc0, 0x01, 0x00, 0xf8, 0xff, 0xcf, 0xe1, 0x00, 0x00,
0xfc, 0xff, 0x81, 0xff, 0x00, 0x00, 0xfe, 0xff, 0x00, 0xff, 0x00, 0x00,
0xff, 0x7f, 0x00, 0x7e, 0x00, 0x00, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00,
0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00,
0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00
};
static const unsigned char runAnim4_bits[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x00,
0x00, 0x00, 0x00, 0xc0, 0xff, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x01,
0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x02, 0xfe, 0xff, 0x07,
0x00, 0x00, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xff, 0xff, 0xff, 0x0f,
0x00, 0x00, 0xfe, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x0f,
0x00, 0x00, 0xff, 0xff, 0x07, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x03, 0x0c,
0x00, 0x00, 0xfe, 0x7f, 0x00, 0x0c, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x0c,
0x00, 0x00, 0xfc, 0x1f, 0x30, 0x0c, 0x00, 0x00, 0xfc, 0x0f, 0x30, 0x0c,
0x00, 0x00, 0xf8, 0x07, 0x00, 0x0c, 0x00, 0x80, 0xf9, 0x03, 0x00, 0x0e,
0x00, 0xc0, 0xff, 0x03, 0x00, 0x07, 0x00, 0xe0, 0xff, 0x07, 0x80, 0x03,
0x00, 0x70, 0xfe, 0x0f, 0xc0, 0x01, 0x00, 0x38, 0xfe, 0x5c, 0xe0, 0x00,
0x00, 0x1c, 0x7f, 0xf8, 0x7c, 0x00, 0x00, 0x8e, 0x3f, 0xf0, 0x7f, 0x00,
0x00, 0xc7, 0x3f, 0xa0, 0xff, 0x03, 0x80, 0xe3, 0x3f, 0x00, 0xff, 0x07,
0xc0, 0xf1, 0x3f, 0x00, 0x7e, 0x0e, 0xe0, 0xf8, 0x7f, 0x10, 0x3c, 0x0e,
0xe0, 0xfc, 0xff, 0x3f, 0x18, 0x07, 0xc0, 0xcf, 0xff, 0x7f, 0x80, 0x03,
0x80, 0xc7, 0xff, 0xff, 0xc0, 0x01, 0x00, 0xc3, 0xff, 0xff, 0xe1, 0x00,
0x00, 0xc0, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x3f, 0x00,
0x00, 0xe0, 0xff, 0xff, 0x19, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x01, 0x00,
0x00, 0x80, 0xff, 0xff, 0x03, 0x00, 0x00, 0x80, 0xff, 0xff, 0x03, 0x00,
0x00, 0xf0, 0x01, 0xfe, 0x03, 0x00, 0x00, 0xf0, 0x01, 0xfe, 0x07, 0x00,
0x00, 0xf0, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x1c, 0x00,
0x00, 0xfc, 0xff, 0x7f, 0x38, 0x00, 0x00, 0xfe, 0xff, 0x3f, 0x70, 0x00,
0x00, 0xfc, 0x07, 0x1e, 0xe0, 0x00, 0x00, 0xfc, 0x03, 0x1c, 0xc0, 0x01,
0x00, 0xfe, 0x01, 0x38, 0x80, 0x0f, 0x00, 0xfc, 0x00, 0x70, 0x00, 0x0f,
0x00, 0x48, 0x00, 0xe0, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x0e,
0x00, 0x00, 0x00, 0x80, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x0f
};
static const unsigned char runAnim5_bits[] PROGMEM = {
0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x41, 0x00,
0x00, 0x00, 0x00, 0x80, 0xff, 0x00, 0x00, 0x00, 0x06, 0x88, 0xff, 0x01,
0x00, 0x00, 0x0f, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x1f, 0xfe, 0xff, 0x03,
0x00, 0x00, 0xfe, 0xff, 0xff, 0x03, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x07,
0x00, 0x00, 0xfc, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x0f,
0x00, 0x00, 0xff, 0xff, 0x01, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x00, 0x0c,
0x00, 0x00, 0xfe, 0x1f, 0x00, 0x0c, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x0c,
0x00, 0x00, 0xfc, 0x07, 0x0c, 0x0c, 0x00, 0x00, 0xfc, 0x03, 0x0c, 0x0c,
0x00, 0x00, 0xf8, 0x01, 0xc0, 0x0c, 0x00, 0x00, 0xf8, 0x01, 0xc0, 0x0f,
0x00, 0x00, 0xfc, 0x03, 0x80, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x80, 0x03,
0x00, 0x00, 0x9f, 0x0f, 0xc0, 0x01, 0x00, 0x00, 0x0f, 0x1f, 0xe0, 0x00,
0x00, 0x00, 0x07, 0xfe, 0x70, 0x00, 0x00, 0x80, 0x03, 0xfc, 0x39, 0x00,
0x00, 0xc0, 0x03, 0xfc, 0x1f, 0x00, 0x00, 0xe0, 0x07, 0xfc, 0x0f, 0x00,
0x00, 0xc0, 0x0f, 0xf8, 0x0f, 0x00, 0x00, 0xc0, 0x0f, 0xf0, 0x0f, 0x00,
0x00, 0xc0, 0x0f, 0x80, 0x0f, 0x00, 0x00, 0xc0, 0x1f, 0x00, 0x0f, 0x00,
0x00, 0xc0, 0xff, 0x00, 0x1f, 0x00, 0x00, 0xc0, 0xff, 0x81, 0x0f, 0x00,
0x00, 0xc0, 0xff, 0xff, 0x07, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x03, 0x00,
0x00, 0xe0, 0xff, 0xff, 0x01, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x00, 0x00,
0x00, 0x80, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x80, 0xff, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x01, 0x00,
0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x07, 0x00,
0x00, 0x00, 0xff, 0xff, 0x07, 0x00, 0x00, 0x80, 0xff, 0xff, 0x03, 0x00,
0x00, 0x80, 0xe7, 0x7f, 0x00, 0x00, 0x00, 0x80, 0xc3, 0x3f, 0x00, 0x00,
0x00, 0x80, 0x83, 0x3f, 0x00, 0x00, 0x00, 0x80, 0x03, 0x3f, 0x00, 0x00,
0x00, 0x80, 0x03, 0x1e, 0x00, 0x00, 0x00, 0x80, 0x07, 0x0e, 0x00, 0x00,
0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00
};
#define runAnim_x 40
#define runAnim_y 8
#define runAnim_delay 50
uint8_t scroll = 128;
int minScroll = -48;
void drawframe() {
scroll--;
if (scroll > 128 || scroll < minScroll) {
scroll = 128;
}
u8g2.updateDisplayArea(0, 0, 16, 8);
u8g2.clearBuffer();
/* tileScroll = scroll/8;
if (tileScroll < 1 || tileScroll > 10) {
u8g2.updateDisplayArea(tileScroll, 1, 6, 6);
}
else {
u8g2.updateDisplayArea(10, 1, 6, 6);
}
u8g2.clearBuffer();
*/
}
void drawRunAnim(uint8_t a) {
u8g2.drawXBMP( scroll, runAnim_y, runAnim_width, runAnim_height, runAnim1_bits);
drawframe();
delay(runAnim_delay);
u8g2.drawXBMP( scroll, runAnim_y, runAnim_width, runAnim_height, runAnim2_bits);
drawframe();
delay(runAnim_delay);
u8g2.drawXBMP( scroll, runAnim_y, runAnim_width, runAnim_height, runAnim3_bits);
drawframe();
delay(runAnim_delay);
u8g2.drawXBMP( scroll, runAnim_y, runAnim_width, runAnim_height, runAnim4_bits);
drawframe();
delay(runAnim_delay);
u8g2.drawXBMP( scroll, runAnim_y, runAnim_width, runAnim_height, runAnim5_bits);
drawframe();
delay(runAnim_delay);
}
#define ironman_x 42
#define ironman_y 0
void drawIronmanLogo(uint8_t a) {
u8g2.drawXBMP( scroll+10, ironman_y, ironman_width, ironman_height, ironman_bits);
drawframe();
delay(50);
}
void setup() {
u8g2.begin();
Serial.begin(115200);
pinMode(led, OUTPUT);
pinMode(2, INPUT_PULLUP);
}
uint8_t draw_state = 0;
void draw(void) {
switch (draw_state >> 3) {
case 0: drawRunAnim(draw_state & 7); break;
case 1: drawIronmanLogo(draw_state & 7); break;
}
}
boolean showFirstBattLevel = false;
unsigned int battLevel = 0;
unsigned int battLevelChange = 0;
unsigned int battUpdateInterval = 2000;
unsigned long previousMillis = 0;
int i = 1;
void chkBattLvl() {
unsigned int battAdcAverage = 0;
for (int i = 1; i < 10; i++) {
battAdcAverage += analogRead(battLevelPin);
}
unsigned int battAdcReading = (battAdcAverage / 10);
unsigned int battLevel = map(battAdcReading, 640, 740, 0, 10);
battLevel = constrain(battLevel, 0, 10);
if (showFirstBattLevel == false) {
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.setDrawColor(1);
u8g2.drawStr(0, 0, battLevel);
u8g2.updateDisplayArea(0, 0, 2, 2);
showFirstBattLevel = true;
}
if (battLevelChange != battLevel) {
unsigned long currentMillis = millis();
if ((unsigned long)(currentMillis - previousMillis) >= battUpdateInterval) {
previousMillis = currentMillis;
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.setDrawColor(1);
u8g2.drawStr(0, 0, battLevel);
u8g2.updateDisplayArea(0, 0, 2, 2);
delay(10);
}
}
battLevelChange = battLevel;
}
void loop() {
//digitalWrite(led, HIGH);
draw();
chkBattLvl();
Serial.println(draw_state);
draw_state++;
if ( draw_state >= 2 * 8 ) {
draw_state = 0;
Serial.println("draw_state reset");
}
//digitalWrite(led, LOW);
}
Last edited: