PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

95 行
3.7KB

  1. /*
  2. * GLCDexample
  3. *
  4. * Basic test code for the Arduino KS0108 GLCD library.
  5. * This code exercises a range of graphic functions supported
  6. * by the library and is an example of its use.
  7. * It also gives an indication of performance, showing the
  8. * number of frames drawn per second.
  9. */
  10. #include <ks0108.h>
  11. #include "Arial14.h" // proportional font
  12. #include "SystemFont5x7.h" // system font
  13. #include "ArduinoIcon.h" // bitmap
  14. unsigned long startMillis;
  15. unsigned int loops = 0;
  16. unsigned int iter = 0;
  17. void setup(){
  18. delay(500); // allow time for LCD to reset
  19. GLCD.Init(NON_INVERTED); // initialise the library, non inverted writes pixels onto a clear screen
  20. GLCD.ClearScreen();
  21. GLCD.DrawBitmap(ArduinoIcon, 32,0, BLACK); //draw the bitmap at the given x,y position
  22. GLCD.SelectFont(System5x7); // switch to fixed width system font
  23. countdown(5);
  24. GLCD.ClearScreen();
  25. introScreen(); // show some intro stuff
  26. GLCD.ClearScreen();
  27. }
  28. void introScreen(){
  29. GLCD.SelectFont(Arial_14); // you can also make your own fonts, see playground for details
  30. GLCD.GotoXY(20, 2);
  31. GLCD.Puts("GLCD version ");
  32. GLCD.PrintNumber(GLCD_VERSION);
  33. GLCD.DrawRoundRect(16,0,99,18, 5, BLACK); // rounded rectangle around text area
  34. GLCD.SelectFont(System5x7); // switch to fixed width system font
  35. showCharacters();
  36. countdown(5);
  37. }
  38. void showCharacters(){
  39. byte line = 3; // start on the fourth line
  40. for(byte c = 32; c <=127; c++){
  41. if( (c-32) % 20 == 0)
  42. GLCD.CursorTo(1,line++); // CursorTo is used for fixed width system font
  43. GLCD.PutChar(c);
  44. }
  45. }
  46. void drawSpinner(byte pos, byte x, byte y) {
  47. // this draws an object that appears to spin
  48. switch(pos % 8) {
  49. case 0 : GLCD.DrawLine( x, y-8, x, y+8, BLACK); break;
  50. case 1 : GLCD.DrawLine( x+3, y-7, x-3, y+7, BLACK); break;
  51. case 2 : GLCD.DrawLine( x+6, y-6, x-6, y+6, BLACK); break;
  52. case 3 : GLCD.DrawLine( x+7, y-3, x-7, y+3, BLACK); break;
  53. case 4 : GLCD.DrawLine( x+8, y, x-8, y, BLACK); break;
  54. case 5 : GLCD.DrawLine( x+7, y+3, x-7, y-3, BLACK); break;
  55. case 6 : GLCD.DrawLine( x+6, y+6, x-6, y-6, BLACK); break;
  56. case 7 : GLCD.DrawLine( x+3, y+7, x-3, y-7, BLACK); break;
  57. }
  58. }
  59. void countdown(int count){
  60. while(count--){ // do countdown
  61. GLCD.CursorTo(0,1); // first column, second row (offset is from 0)
  62. GLCD.PutChar(count + '0');
  63. delay(1000);
  64. }
  65. }
  66. void loop(){ // run over and over again
  67. iter = 0;
  68. startMillis = millis();
  69. while( millis() - startMillis < 1000){ // loop for one second
  70. GLCD.DrawRect(0, 0, 64, 61, BLACK); // rectangle in left side of screen
  71. GLCD.DrawRoundRect(68, 0, 58, 61, 5, BLACK); // rounded rectangle around text area
  72. for(int i=0; i < 62; i += 4)
  73. GLCD.DrawLine(1,1,63,i, BLACK); // draw lines from upper left down right side of rectangle
  74. GLCD.DrawCircle(32,31,30,BLACK); // draw circle centered in the left side of screen
  75. GLCD.FillRect(92,40,16,16, WHITE); // clear previous spinner position
  76. drawSpinner(loops++,100,48); // draw new spinner position
  77. //GLCD.FillRect(24,txtLINE3,14,14, WHITE); // clear text area that will be drawn below
  78. GLCD.CursorTo(5,5); // locate curser for printing text
  79. GLCD.PrintNumber(++iter); // print current iteration at the current cursor position
  80. }
  81. // display number of iterations in one second
  82. GLCD.ClearScreen(); // clear the screen
  83. GLCD.CursorTo(14,2); // positon cursor
  84. GLCD.Puts("FPS= "); // print a text string
  85. GLCD.PrintNumber(iter); // print a number
  86. }