Kode Program
/*
Copyright (c) 2016, olikraus@gmail.com
All rights reserved.
*/
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
/*
draw unicode for https://en.wikipedia.org/wiki/Devanagari
Adjust the glyph position as good as possible for the unicode font.
Report missing or wrong glyph adjustments here:
https://github.com/olikraus/u8g2/issues/584
precondition:
u8g2_SetFont(&u8g2, u8g2_font_unifont_t_devanagari);
u8g2_SetFontMode(&u8g2, 1);
Font direction command is NOT supported
*/
u8g2_uint_t u8g2_draw_unifont_devanagari(u8g2_uint_t x, u8g2_uint_t y, const char *str)
{
uint16_t e;
u8g2_uint_t delta, sum;
u8g2.getU8g2()->u8x8.next_cb = u8x8_utf8_next;
u8x8_utf8_init(u8g2.getU8x8());
sum = 0;
for(;;)
{
e = u8g2.getU8g2()->u8x8.next_cb(u8g2.getU8x8(), (uint8_t)*str);
if ( e == 0x0ffff )
break;
str++;
if ( e != 0x0fffe )
{
switch(e)
{
/* many more glyphs and corrections are missing */
/* please report to https://github.com/olikraus/u8g2/issues/584 */
case 0x093e: x-= 12; break;
case 0x093f: x-= 19; break;
case 0x0941: x-= 10; y+=3; break; // move down
case 0x0947: x-= 12; break;
case 0x094d: x-= 10; break;
}
delta = u8g2.drawGlyph(x, y, e);
switch(e)
{
case 0x0941: x-= 3; y -=3; break; // revert the y shift
case 0x094d: x-= 8; break;
}
x += delta;
sum += delta;
}
}
return sum;
}
void setup(void) {
u8g2.begin();
}
void loop(void) {
/* Set the unifont with Devanagari glyphs */
u8g2.setFont(u8g2_font_unifont_t_devanagari);
/* Important: do not write background pixel */
u8g2.setFontMode(1);
u8g2.firstPage();
do {
u8g2_draw_unifont_devanagari(0,24,"नमस्ते दुनिया"); // Hello World
} while ( u8g2.nextPage() );
}
Hasil