main.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "u8g2.h"
  2. #include <stdio.h>
  3. /*
  4. * This example uses the Bitmap device to draw to an in-memory buffer
  5. * and writes the result to a TGA file. This can for example be used to
  6. * make screenshots of an application normally running on an Arduino.
  7. */
  8. u8g2_t u8g2;
  9. int main(void)
  10. {
  11. u8g2_SetupBitmap(&u8g2, &u8g2_cb_r0, 128, 64);
  12. u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
  13. u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
  14. u8g2_SetFont(&u8g2, u8g2_font_helvB08_tr);
  15. u8g2_ClearBuffer(&u8g2);
  16. // Here, you can call other code to actually draw things, such as
  17. // existing application code to generate a screenshot
  18. u8g2_DrawStr(&u8g2, 10, 30, "Hello, world!");
  19. u8g2_SendBuffer(&u8g2);
  20. u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "small.tga");
  21. // This changes size, but also resets other stuff like font
  22. u8g2_SetupBitmap(&u8g2, &u8g2_cb_r0, 128, 128);
  23. u8g2_SetFont(&u8g2, u8g2_font_helvB08_tr);
  24. u8g2_ClearBuffer(&u8g2);
  25. // Here, you can call other code to actually draw things, such as
  26. // existing application code to generate a screenshot
  27. u8g2_DrawStr(&u8g2, 10, 30, "Hello, world!");
  28. u8g2_DrawStr(&u8g2, 10, 100, "Hello, larger world!");
  29. u8g2_SendBuffer(&u8g2);
  30. u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "large.tga");
  31. return 0;
  32. }