#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI
//IMÁGENES:
// https://marlinfw.org/tools/u8glib/converter.html
const unsigned char nada[] PROGMEM = {
B00000000,B00000011,B10000000,B00000000,B00000000,B00111000,B00000000,
B00000000,B00000011,B11000000,B00000000,B00000000,B01111000,B00000000,
B00000000,B00000001,B11100000,B00000000,B00000000,B11110000,B00000000,
B00000000,B00000000,B11110000,B00000000,B00000001,B11100000,B00000000,
B00000000,B00000000,B01111000,B00000000,B00000011,B11000000,B00000000,
B00000000,B00000000,B00111100,B00000000,B00000111,B10000000,B00000000,
B00000000,B00000000,B00011110,B00000000,B00001111,B00000000,B00000000,
B00000000,B00000000,B00001111,B00000000,B00011110,B00000000,B00000000,
B00000000,B00000000,B00000111,B10000000,B00111100,B00000000,B00000000,
B00000000,B00000000,B00000011,B11000000,B01111000,B00000000,B00000000,
B00000000,B00000000,B00000001,B11100000,B11110000,B00000000,B00000000,
B00000000,B00000000,B00000000,B11110001,B11100000,B00000000,B00000000,
B00000000,B00000000,B00000000,B01111011,B11000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00111111,B10000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00011111,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00011111,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00111111,B10000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B01111011,B11000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B11110001,B11100000,B00000000,B00000000,
B00000000,B00000000,B00000001,B11100000,B11110000,B00000000,B00000000,
B00000000,B00000000,B00000011,B11000000,B01111000,B00000000,B00000000,
B00000000,B00000000,B00000111,B10000000,B00111100,B00000000,B00000000,
B00000000,B00000000,B00001111,B00000000,B00011110,B00000000,B00000000,
B00000000,B00000000,B00011110,B00000000,B00001111,B00000000,B00000000,
B00000000,B00000000,B00111100,B00000000,B00000111,B10000000,B00000000,
B00000000,B00000000,B01111000,B00000000,B00000011,B11000000,B00000000,
B00000000,B00000000,B11110000,B00000000,B00000001,B11100000,B00000000,
B00000000,B00000001,B11100000,B00000000,B00000000,B11110000,B00000000,
B00000000,B00000011,B11000000,B00000000,B00000000,B01111000,B00000000,
B00000000,B00000011,B10000000,B00000000,B00000000,B00111000,B00000000
};
const unsigned char llegada[] PROGMEM = {
0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x01, 0xe0,
0xff, 0xff, 0xff, 0xff, 0x80, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01, 0xe0, 0xff, 0xff,
0xff, 0xfe, 0x00, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xf8,
0x00, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x01,
0xe0, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x01, 0xe0, 0xff, 0xff, 0xff, 0x80, 0x00, 0x01, 0xe0, 0xff,
0xff, 0xff, 0x00, 0x00, 0x01, 0xe0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x01, 0xe0, 0xff, 0xff, 0xff,
0x00, 0x00, 0x01, 0xe0, 0xff, 0xff, 0xff, 0x80, 0x00, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xc0, 0x00,
0x01, 0xe0, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x01, 0xe0,
0xff, 0xff, 0xff, 0xf8, 0x00, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x01, 0xe0, 0xff, 0xff,
0xff, 0xfe, 0x00, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xff,
0x80, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x01, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x01,
0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00
};
const unsigned char izql[] PROGMEM = {};
const unsigned char izq90[] PROGMEM = {};
const unsigned char izqc[] PROGMEM = {};
const unsigned char derl[] PROGMEM = {};
const unsigned char der90[] PROGMEM = {};
const unsigned char derc[] PROGMEM = {};
const unsigned char recto[] PROGMEM = {
B00000000, B00000000, B00000000, B00001000, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B00011100, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B00111110, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B11111111, B10000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B11111111, B10000000, B00000000, B00000000,
B00000000, B00000000, B00000001, B11111111, B11000000, B00000000, B00000000,
B00000000, B00000000, B00000011, B11111111, B11100000, B00000000, B00000000,
B00000000, B00000000, B00000111, B11111111, B11110000, B00000000, B00000000,
B00000000, B00000000, B00001111, B11111111, B11110000, B00000000, B00000000,
B00000000, B00000000, B00001111, B11111111, B11111000, B00000000, B00000000,
B00000000, B00000000, B00011111, B11111111, B11111100, B00000000, B00000000,
B00000000, B00000000, B00111111, B11111111, B11111110, B00000000, B00000000,
B00000000, B00000000, B01111111, B11111111, B11111111, B00000000, B00000000,
B00000000, B00000000, B01111111, B11111111, B11111111, B00000000, B00000000,
B00000000, B00000000, B11111111, B11111111, B11111111, B10000000, B00000000,
B00000000, B00000001, B11111111, B11111111, B11111111, B11000000, B00000000,
B00000000, B00000011, B11111110, B01111111, B00011111, B11100000, B00000000,
B00000000, B00000011, B11110000, B01111111, B00000111, B11100000, B00000000,
B00000000, B00000011, B11000000, B01111111, B00000001, B11100000, B00000000,
B00000000, B00000001, B00000000, B01111111, B00000000, B00100000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B01111111, B00000000, B00000000, B00000000,
B00000000, B00000000, B00000000, B00111110, B00000000, B00000000, B00000000
};
const unsigned char test[] PROGMEM = {
B00000000,B00000000,B00000000,B01111111,B10000000,B00000000,B00000000,
B00000000,B00000000,B00000001,B11111111,B11100000,B00000000,B00000000,
B00000000,B00000000,B00000111,B11000000,B01111000,B00000000,B00000000,
B00000000,B00000000,B00001110,B00000000,B00011100,B00000000,B00000000,
B00000000,B00000000,B00011000,B00000000,B00000110,B00000000,B00000000,
B00000000,B00000000,B00110000,B01111111,B10000011,B00000000,B00000000,
B00000000,B00000000,B01100011,B11000000,B11110001,B10000000,B00000000,
B00000000,B00000000,B11000010,B00000000,B00010000,B11000000,B00000000,
B00000000,B00000000,B11000110,B00000000,B00011000,B11000000,B00000000,
B00000000,B00000001,B10000100,B00000000,B00001000,B01100000,B00000000,
B00000000,B00000001,B10000100,B00000000,B00001000,B01100000,B00000000,
B00000000,B00000011,B10011100,B00000000,B00001000,B01100000,B00000000,
B00000000,B00000011,B00010000,B00000000,B00001110,B00110000,B00000000,
B00000000,B00000011,B00010000,B00000000,B00000010,B00110000,B00000000,
B00000000,B00000011,B00010000,B00000000,B00000010,B00110000,B00000000,
B00000000,B00000011,B00011100,B00000000,B00000010,B00110000,B00000000,
B00000000,B00000011,B00000100,B00000000,B00001110,B00110000,B00000000,
B00000000,B00000011,B00000100,B00000000,B00001000,B00110000,B00000000,
B00000000,B00000011,B00000100,B00000000,B00001000,B01100000,B00000000,
B00000000,B00000001,B10000110,B00000000,B00011000,B01100000,B00000000,
B00000000,B00000001,B10000010,B00000000,B00010000,B01100000,B00000000,
B00000000,B00000000,B11000010,B00000000,B00010000,B11000000,B00000000,
B00000000,B00000000,B11000011,B00000000,B00110000,B11000000,B00000000,
B00000000,B00000000,B01100001,B10000000,B01100001,B10000000,B00000000,
B00000000,B00000000,B00110000,B11111111,B11000011,B00000000,B00000000,
B00000000,B00000000,B00011000,B00000000,B00000110,B00000000,B00000000,
B00000000,B00000000,B00001110,B00000000,B00011100,B00000000,B00000000,
B00000000,B00000000,B00000111,B11000000,B11111000,B00000000,B00000000,
B00000000,B00000000,B00000001,B11111111,B11100000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00111111,B00000000,B00000000,B00000000
};
char metros[] = " 100 m";
char minutos[] = " 28";
char kmh[] = "777";
int flecha = 0;
int incomingByte = 0;
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
//u8g.setFont(u8g_font_unifont);
u8g.setFont(u8g_font_courB10);
u8g.drawStr(0, 15, metros);
u8g.drawStr(96, 10, "ETA:");
u8g.drawStr(55, 24, minutos);
u8g.drawStr(101, 24, "min");
u8g.drawStr(60, 63, kmh);
u8g.drawStr(92, 63, "Km/h");
switch (flecha) {
case 0:
u8g.drawBitmapP( 0, 18, 7, 48, nada);
break;
case 1:
u8g.drawBitmapP( 0, 18, 7, 48, llegada);
break;
case 2:
u8g.drawBitmapP( 0, 18, 7, 48, izql);
break;
case 3:
u8g.drawBitmapP( 0, 18, 7, 48, izq90);
break;
case 4:
u8g.drawBitmapP( 0, 18, 7, 48, izqc);
break;
case 5:
u8g.drawBitmapP( 0, 18, 7, 48, derl);
break;
case 6:
u8g.drawBitmapP( 0, 18, 7, 48, der90);
break;
case 7:
u8g.drawBitmapP( 0, 18, 7, 48, derc);
break;
case 8:
u8g.drawBitmapP( 0, 18, 7, 48, recto);
break;
case 9:
u8g.drawBitmapP( 0, 18, 7, 48, test);
break;
default:
u8g.drawBitmapP( 0, 18, 7, 48, nada);
break;
}
}
void setup(void) {
Serial.begin(9600); // Any baud rate should work
Serial.println("Puerto serie iniciado.\n");
}
void loop(void) {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
byte comando = Serial.read();
switch (comando) {
case 'F':
flecha = Serial.parseInt();
Serial.println(flecha);
break;
case 'M':
Serial.readBytes(metros, 6);
Serial.println(metros);
break;
case 'T':
Serial.readBytes(minutos, 4);
Serial.println(minutos);
break;
case 'K':
Serial.readBytes(kmh, 3);
Serial.println(kmh);
break;
}
}
// picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
// rebuild the picture after some delay
delay(500);
}