#include <U8glib.h> //8 bit per operation width - 8 height - 1
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST);
// ' gauge_bg', 72x64px
const unsigned char epd_bitmap__gauge_bg [] PROGMEM = {
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, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0f, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x01, 0x80, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x01, 0x0c, 0x00,
0x00, 0x00, 0x00, 0x08, 0x10, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x30, 0x08, 0x00, 0x02,
0x01, 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x80, 0x77,
0x80, 0x06, 0x78, 0x20, 0x00, 0x00, 0x01, 0x00, 0x84, 0x80, 0x09, 0x48, 0x10, 0x00, 0x00, 0x02,
0x00, 0xe4, 0x80, 0x06, 0x48, 0x08, 0x00, 0x00, 0x04, 0x00, 0x94, 0x80, 0x09, 0x48, 0x04, 0x00,
0x00, 0x08, 0x00, 0x94, 0x80, 0x09, 0x48, 0x02, 0x00, 0x00, 0x18, 0x00, 0x67, 0x80, 0x06, 0x78,
0x03, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x4c, 0x00,
0x00, 0x00, 0x00, 0x00, 0x06, 0x40, 0x00, 0x86, 0x97, 0x80, 0x00, 0x00, 0xbd, 0xec, 0x20, 0x00,
0x80, 0x94, 0x80, 0x00, 0x00, 0xa5, 0x20, 0x20, 0x01, 0x00, 0xf4, 0x80, 0x00, 0x00, 0xa5, 0x20,
0x10, 0x01, 0x00, 0x14, 0x80, 0x00, 0x00, 0xa5, 0x20, 0x10, 0x01, 0x00, 0x14, 0x80, 0x00, 0x00,
0xa5, 0x20, 0x10, 0x02, 0x00, 0x17, 0x80, 0x00, 0x00, 0xbd, 0xe0, 0x08, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x02, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04, 0x04, 0x0e, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x01, 0x48,
0x00, 0x00, 0x00, 0x0b, 0x9e, 0x04, 0x04, 0x02, 0x48, 0x00, 0x00, 0x00, 0x08, 0x52, 0x04, 0x04,
0x04, 0x48, 0x00, 0x00, 0x00, 0x08, 0x92, 0x04, 0x04, 0xe8, 0x48, 0x00, 0x00, 0x00, 0x09, 0x12,
0xe4, 0x04, 0x0f, 0x78, 0x00, 0x00, 0x00, 0x0a, 0x12, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0b, 0xde, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x02, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x0f, 0x00, 0x00, 0x02, 0x97,
0x80, 0x10, 0x00, 0x80, 0x09, 0x00, 0x00, 0x02, 0x94, 0x80, 0x20, 0x00, 0x80, 0x09, 0x00, 0x00,
0x02, 0xf4, 0x80, 0x20, 0x00, 0x40, 0x09, 0x00, 0x00, 0x02, 0x14, 0x80, 0x40, 0x00, 0x40, 0x09,
0x00, 0x00, 0x02, 0x14, 0x80, 0x40, 0x00, 0x20, 0x0f, 0x00, 0x00, 0x02, 0x17, 0x80, 0x80, 0x00,
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x01, 0x01,
0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x00,
0x00, 0x44, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 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
};
// ' logo', 16x6px
const unsigned char epd_bitmap__logo [] PROGMEM = {
0x00, 0x00, 0x85, 0x39, 0x85, 0x29, 0x87, 0x39, 0x85, 0x39, 0xe5, 0x29
};
// ' center_outline', 8x8px
const unsigned char epd_bitmap__center_outline [] PROGMEM = {
0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00
};
// ' center_fill', 8x8px
const unsigned char epd_bitmap__center_fill [] PROGMEM = {
0x00, 0x3c, 0x7e, 0x7e, 0x7e, 0x7e, 0x3c, 0x00
};
// ' 0', 16x28px
const unsigned char epd_bitmap__0 [] PROGMEM = {
0x0f, 0xff, 0x1f, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xfc, 0x3f,
0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f,
0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfe, 0xff, 0xfc, 0xff, 0xf8
};
// ' 1', 16x28px
const unsigned char epd_bitmap__1 [] PROGMEM = {
0x01, 0xf8, 0x03, 0xf8, 0x07, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8,
0x01, 0xf8, 0x01, 0xf8, 0x01, 0xf8, 0x01, 0xf8, 0x01, 0xf8, 0x01, 0xf8, 0x01, 0xf8, 0x01, 0xf8,
0x01, 0xf8, 0x01, 0xf8, 0x01, 0xf8, 0x01, 0xf8, 0x01, 0xf8, 0x01, 0xf8, 0x01, 0xf8, 0x01, 0xf8,
0x01, 0xf8, 0x01, 0xf8, 0x01, 0xf8, 0x01, 0xf8
};
// ' 2 ', 16x28px
const unsigned char epd_bitmap__2_ [] PROGMEM = {
0x0f, 0xfe, 0x1f, 0xff, 0x3f, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xfc, 0x3f,
0xfc, 0x3f, 0x00, 0x3f, 0x00, 0x7f, 0x00, 0xff, 0x01, 0xfe, 0x03, 0xfc, 0x07, 0xf8, 0x1f, 0xf0,
0x3f, 0xe0, 0x7f, 0xc0, 0xff, 0x00, 0xfe, 0x00, 0xfc, 0x00, 0xfc, 0x00, 0xfc, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
// ' 3', 16x28px
const unsigned char epd_bitmap__3 [] PROGMEM = {
0x0f, 0xfe, 0x3f, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x3f, 0xf8, 0x3f,
0xf8, 0x3f, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0xfe, 0x01, 0xfc, 0x01, 0xf8, 0x01, 0xff, 0x01, 0xff,
0x00, 0xff, 0x00, 0x3f, 0x00, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xfc, 0x3f, 0xff, 0xff,
0x7f, 0xff, 0x3f, 0xfe, 0x1f, 0xfc, 0x0f, 0xf8
};
// ' 4', 16x28px
const unsigned char epd_bitmap__4 [] PROGMEM = {
0x00, 0x70, 0x00, 0x78, 0x00, 0xfc, 0x00, 0xfe, 0x01, 0xff, 0x03, 0xff, 0x03, 0xff, 0x07, 0xff,
0x07, 0xff, 0x0f, 0xff, 0x0f, 0xbf, 0x1f, 0xbf, 0x1f, 0x3f, 0x3f, 0x3f, 0x3e, 0x3f, 0x7e, 0x3f,
0x7c, 0x3f, 0xfc, 0x3f, 0xff, 0xff, 0x7f, 0xff, 0x3f, 0xff, 0x3f, 0xff, 0x1f, 0xff, 0x00, 0x3f,
0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3f
};
// ' 5', 16x28px
const unsigned char epd_bitmap__5 [] PROGMEM = {
0x7f, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xfc, 0x00, 0xfc, 0x00,
0xfc, 0x00, 0xfc, 0x00, 0xfe, 0x00, 0xff, 0xf0, 0xff, 0xf8, 0xff, 0xfc, 0xff, 0xfe, 0xff, 0xff,
0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x7f, 0xff, 0xff,
0xff, 0xff, 0x7f, 0xff, 0x3f, 0xff, 0x1f, 0xff
};
// ' 6', 16x28px
const unsigned char epd_bitmap__6 [] PROGMEM = {
0x0f, 0xfe, 0x1f, 0xff, 0x3f, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xfc, 0x3f,
0xfc, 0x3f, 0xfc, 0x00, 0xfc, 0x00, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x7f, 0xff, 0xff,
0xff, 0xfe, 0xff, 0xfc, 0xff, 0xf8, 0xff, 0xf0
};
// ' 7', 16x28px
const unsigned char epd_bitmap__7 [] PROGMEM = {
0xff, 0xf0, 0xff, 0xf8, 0xff, 0xfc, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x3f, 0xf8, 0x7e,
0xf8, 0x7e, 0x00, 0xfc, 0x00, 0xfc, 0x00, 0xfc, 0x01, 0xf8, 0x01, 0xf8, 0x01, 0xf8, 0x03, 0xf0,
0x03, 0xf0, 0x07, 0xf0, 0x07, 0xe0, 0x07, 0xe0, 0x0f, 0xc0, 0x0f, 0xc0, 0x0f, 0xc0, 0x1f, 0x80,
0x1f, 0x80, 0x3f, 0x80, 0x3f, 0x00, 0x3f, 0x00
};
// ' 8 ', 16x28px
const unsigned char epd_bitmap__8_ [] PROGMEM = {
0x0f, 0xfe, 0x1f, 0xff, 0x3f, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xfc, 0x3f,
0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3e, 0xff, 0xfc, 0xff, 0xf8, 0x1f, 0xff, 0x7f, 0xff,
0xff, 0xff, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfe, 0xff, 0xfc, 0xff, 0xf8
};
// ' 9 ', 16x28px
const unsigned char epd_bitmap__9_ [] PROGMEM = {
0x07, 0xff, 0x1f, 0xff, 0x3f, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xfc, 0x3f,
0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x00, 0x3f, 0x00, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfe, 0xff, 0xfc, 0xff, 0xf8
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 832)
const int epd_bitmap_allArray_LEN = 10;
const unsigned char* epd_bitmap_allArray[10] = {
epd_bitmap__0,
epd_bitmap__1,
epd_bitmap__2_,
epd_bitmap__3,
epd_bitmap__4,
epd_bitmap__5,
epd_bitmap__6,
epd_bitmap__7,
epd_bitmap__8_,
epd_bitmap__9_
};
// ' mph', 16x7px
const unsigned char epd_bitmap__mph [] PROGMEM = {
0x00, 0x00, 0x8b, 0xd2, 0xda, 0x52, 0xab, 0xde, 0x8a, 0x12, 0x8a, 0x12, 0x8a, 0x12
};
int speed = 0;
char speed_string[10]; //array of char
int length ;
int digit_start_position;
int needle_angle;
int needle_start_X;
int needle_start_Y;
int needle_end_X;
int needle_end_Y;
int needle_center_X = 37;
int needle_center_Y = 36;
int needle_radius_big = 12;
int needle_radius_small = 7;
//second needle to increase line thickness
int needle_offset_X;
int needle_offset_Y;
void setup()
{
u8g.setFont(u8g_font_tpssb);
u8g.setColorIndex(1);
}
void loop()
{
speed = map(analogRead(A0), 0, 1023, 0, 140);
itoa(speed, speed_string,10);
length = strlen(speed_string);
digit_start_position = 97 - (length * 8); //center of 1 digit is 8. width is 16.
needle_angle = map(speed,0, 140, 45, 270+45);
needle_start_X = needle_radius_big * -sin(radians(needle_angle)) + needle_center_X;
needle_start_Y = needle_radius_big * cos(radians(needle_angle)) + needle_center_Y;
needle_end_X = needle_radius_small* -sin(radians(needle_angle + 180)) + needle_center_X;
needle_end_Y = needle_radius_small * cos(radians(needle_angle + 180)) + needle_center_Y;
if((needle_angle > 45 && needle_angle < 135) || (needle_angle > 255 && needle_angle < 315))
{
needle_offset_X = 0;
needle_offset_Y = 1;
}
else
{
needle_offset_X = 1;
needle_offset_Y = 0;
}
u8g.firstPage();
do
{
for(int i=0; i<length; i++)
{
u8g.drawBitmapP( digit_start_position + (18*i) , 20, 16/8, 28, epd_bitmap_allArray[speed_string[i] - 48] ); //each digit is 16 + 2(gap)
} //itoa convert to ASCII code. 0 start from 48
//u8g.drawStr(90,10,speed_string); //each loop start from digit_start_position. distance from start position increase by 18*i
u8g.drawLine(needle_start_X, needle_start_Y, needle_end_X, needle_end_Y);
u8g.drawLine(needle_start_X + needle_offset_X, needle_start_Y + needle_offset_Y, needle_end_X + needle_offset_X, needle_end_Y + needle_offset_Y); //needle thickness
u8g.drawBitmapP( 0, 0, 72/8, 64, epd_bitmap__gauge_bg );
u8g.drawBitmapP( 27, 55, 16/8, 6, epd_bitmap__logo );
u8g.setColorIndex(0);
u8g.drawBitmapP(33, 33, 8/8, 8,epd_bitmap__center_fill );
u8g.setColorIndex(1);
u8g.drawBitmapP( 33, 33, 8/8, 8, epd_bitmap__center_outline );
u8g.drawBitmapP( 90, 55, 16/8, 7, epd_bitmap__mph );
}while(u8g.nextPage());
}