Rhavecilla

Hello_World_U8G2_SPI

Jul 29th, 2021
1,022
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Program ID: Hello_World_U8G2_SPI_Demo
  3.  * Program by: Thesis Help
  4.  *             www.facebook.com/helpyouonurthesis
  5.  *            
  6.  *             Coode excerpt from U8g2
  7.  *             Copyright (c) 2012, olikraus@gmail.com
  8.  *             All rights reserved.
  9.  *             https://github.com/olikraus/u8g2
  10.  *            
  11.  *             LCD is a ST7920 128 x 64 Graphical. This piece of code
  12.  *             demonstrate using the LCD using the SPI bus. This means using only 3 pins in your
  13.  *             microcontroller.
  14.  *
  15.  */
  16.  
  17.  
  18. // Load the library,
  19. #include "U8g2lib.h"
  20.  
  21.  
  22. // setup u8g object, devices with all constructor calls is here:
  23. // https://github.com/olikraus/u8glib/wiki/device
  24. U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, 13, 11, 10, 8);
  25.  
  26.  
  27. void setup(void) {
  28.   u8g2.begin();
  29. }
  30.  
  31. void loop(void) {
  32.   static int number = 0;
  33.   char theNumber[8];
  34.   itoa(number, theNumber, 10);
  35.  
  36.   // picture loop
  37.   u8g2.firstPage();  
  38.   do {
  39.     u8g2.drawFrame(102,10,20,25);
  40.     u8g2.setFont(u8g2_font_ncenB18_tf);
  41.     u8g2.drawStr(5, 20, "Hello");
  42.     u8g2.drawStr(5, 43, "World!");
  43.     u8g2.drawStr(105, 32, theNumber);
  44.     u8g2.setFont(u8g2_font_6x10_tf);
  45.     u8g2.drawStr(5,52, "www.facebook.com/");
  46.     u8g2.drawStr(5,62, "helpyouonurthesis");
  47.   } while( u8g2.nextPage() );
  48.  
  49.   number++;
  50.  
  51.   if (number > 9){
  52.     number = 0;
  53.   }
  54.  
  55.   // Some delay before redrawing.
  56.   delay(500);
  57. }
  58.  
RAW Paste Data