ChineseCharactersDisplay.ino 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*Coding by wjxjmj*/
  2. #include <Arduino.h>
  3. #include <U8g2lib.h>
  4. #define BtnPin 35
  5. #define BuzzerPin 26
  6. U8G2_SH1107_64X128_F_4W_HW_SPI u8g2(U8G2_R0,14, /* dc=*/ 27, /* reset=*/ 33);
  7. int btnState;
  8. int oledState;
  9. unsigned long initTime;
  10. unsigned long duration; /* Turn off the oled screen if no button is pushed in duration time */
  11. void setup() {
  12. u8g2.begin();
  13. u8g2.setFont(u8g2_font_wqy12_t_gb2312); /*12*12 Chinese characters using GB2312*/
  14. u8g2.enableUTF8Print();
  15. pinMode(BtnPin, INPUT_PULLUP);
  16. attachInterrupt(BtnPin,pressed,FALLING); /*Chech if the button is pushed using interrupt*/
  17. pinMode(BuzzerPin, OUTPUT);
  18. digitalWrite(BuzzerPin, LOW);/*Keep the buzzer quiet*/
  19. btnState=0;
  20. oledState=0;
  21. duration=15000; /*keep screen on in 15 second*/
  22. delay(500);
  23. initTime=millis();
  24. }
  25. void pressed()
  26. {
  27. btnState=1;
  28. }
  29. void draw(void)
  30. {
  31. u8g2.firstPage();
  32. do {
  33. /*Chinese characters strings*/
  34. u8g2.setColorIndex(1);
  35. u8g2.drawUTF8(2,14*1+4," 道忽思");
  36. u8g2.drawUTF8(2,14*2+4," ,已君");
  37. u8g2.drawUTF8(2,14*3+4,"古 努晚令");
  38. u8g2.drawUTF8(2,14*4+4,"诗 力。人");
  39. u8g2.drawUTF8(2,14*5+4,"十 加弃老");
  40. u8g2.drawUTF8(2,14*6+4,"九 餐捐,");
  41. u8g2.drawUTF8(2,14*7+4,"首 饭勿岁");
  42. u8g2.drawUTF8(2,14*8+4," 。复月");
  43. /*Some punctuations are missing, draw them using u8g2 api
  44. Upper quotation marks for title of books */
  45. u8g2.drawFrame(0+2,14*2-1,12,5);
  46. u8g2.drawFrame(0+2,14*2+1,10,3);
  47. u8g2.setColorIndex(0);
  48. u8g2.drawFrame(0+2,14*2+2,9,2);
  49. /*Lower quotation marks for title of books */
  50. u8g2.setColorIndex(1);
  51. u8g2.drawFrame(0+1,14*8-3,12,5);
  52. u8g2.drawFrame(0+3,14*8-3,10,3);
  53. u8g2.setColorIndex(0);
  54. u8g2.drawFrame(0+4,14*8-3,9,2);
  55. } while( u8g2.nextPage() );
  56. }
  57. void loop() {
  58. if(btnState==1)
  59. {
  60. oledState=(oledState+1)%2;
  61. if(oledState==1)u8g2.noDisplay();/*turn off screen if it is on*/
  62. else u8g2.display(); /*and vice versa*/
  63. initTime=millis();/*renew the time if button is pushed*/
  64. btnState=0; /*ready for next push of button*/
  65. }
  66. if (millis()-initTime>duration)esp_deep_sleep_start(); /*Entering power save mode*/
  67. draw();
  68. delay(1);
  69. }