Advertisement
Rauthag

LCD1

Sep 23rd, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #include \"mbed.h\"
  2. #include <iostream>
  3. #include <sstream>
  4. #include <bitset>
  5. #include <string>
  6. Serial pc( USBTX, USBRX );
  7.  
  8. #include \"lcd_lib.h\"
  9.  
  10. // two dimensional array with fixed size font
  11. extern uint8_t font8x8[ 256 ][ 8 ];
  12.  
  13.  
  14.  
  15. class Bod
  16. {
  17. public:
  18. Bod( int x, int y, int barva ): x0( x ), y0( y ), rgb(barva) {};
  19. void kresli( int x = 0, int y = 0 ) { LCD_put_pixel( x0 + x, y0 + y, rgb ); }
  20.  
  21. int x0, y0;
  22. int rgb;
  23. };
  24.  
  25. class Usecka : public Bod{
  26. public:
  27. Usecka (int a, int b, int c, int d, int barva): Bod(a,c,barva), a( a ), b( b ),c(c),d(d){};
  28. void draw(){
  29. int dx,dy,p,x,y;
  30. dx=b-a;
  31. dy=d-c;
  32.  
  33. x=a;
  34. y=c;
  35.  
  36. p=2*dy-dx;
  37.  
  38. while(x<b)
  39. {
  40. if(p>=0)
  41. {
  42. Bod::kresli(+x,+y);
  43. y=y+1;
  44. p=p+2*dy-2*dx;
  45. }
  46. else
  47. {
  48. Bod::kresli(x,y);
  49. p=p+2*dy;
  50. }
  51. x=x+1;
  52. }
  53. }
  54. int a,b,c,d,rgb;
  55. };
  56.  
  57. class Znak {
  58. public:
  59. Znak(char c, int rgb, int offset):c ( c ),rgb(rgb),offset(offset){};
  60. void draw(){
  61. for(int x = 0; x < 8; x++){
  62.  
  63. for(int y = 0; y <8; y++){
  64. if(font8x8[ int(c) ][ x ] & ( 1 << y )){
  65. LCD_put_pixel(y,x+offset,rgb);
  66. }
  67. else{
  68. LCD_put_pixel(y,x+offset,65535);
  69. }
  70.  
  71. }
  72.  
  73. }
  74. }
  75. char c;
  76. int rgb,offset;
  77. };
  78.  
  79. int main()
  80. {
  81. LCD_init(); // LCD initialization
  82.  
  83. LCD_clear(); // LCD clear screen
  84.  
  85. pc.baud(115200);
  86. printf(\"ahoj\");
  87. int cervena = 0xF800;
  88. Znak cha(\'C\',cervena,0);
  89. cha.draw();
  90. Znak chb(\'A\',cervena,8);
  91. chb.draw();
  92. Znak chc(\'U\',cervena,16);
  93. chc.draw();
  94. Usecka cara(5,180,5,180,cervena);
  95. cara.draw();
  96.  
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement