Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. #include \"mbed.h\"
  2.  
  3. Serial pc( USBTX, USBRX );
  4.  
  5. #include \"lcd_lib.h\"
  6.  
  7. // two dimensional array with fixed size font
  8. extern uint8_t font8x8[ 256 ][ 8 ];
  9.  
  10. void printChar(char zn, char a, char b, int color){
  11. a = (int)a;
  12. b = (int)b;
  13. for (int y = 0; y < 8; y++){
  14. for (int x = 0; x < 8; x++){
  15. if (font8x8[zn][y] & (1 << x))
  16. {
  17. LCD_put_pixel(x + a, y + b, color);
  18. }
  19. }
  20. }
  21. }
  22.  
  23. void printString(char *zn, char a, char b, int color){
  24. a = (int)a;
  25. b = (int)b;
  26. int len_str = strlen(zn);
  27.  
  28. for (int c = 0; c < len_str; c++){
  29. for (int y = 0; y < 8; y++){
  30. for (int x = 0; x < 8; x++){
  31. if (font8x8[zn[c]][y] & (1 << x))
  32. {
  33. LCD_put_pixel(c * 8 + x + a, y + b, color);
  34. }
  35. }
  36. }
  37. }
  38. }
  39.  
  40.  
  41.  
  42.  
  43. void kruznice(char x0, char y0, char polomer, int color){
  44. x0 = (int)x0;
  45. y0 = (int)y0;
  46. polomer = (int)polomer;
  47. int x = polomer-1;
  48. int y = 0;
  49. int dx = 1;
  50. int dy = 1;
  51. int err = dx - (polomer << 1);
  52.  
  53. while (x >= y)
  54. {
  55. LCD_put_pixel(x0 + x, y0 + y, color);
  56. LCD_put_pixel(x0 + y, y0 + x, color);
  57. LCD_put_pixel(x0 - y, y0 + x, color);
  58. LCD_put_pixel(x0 - x, y0 + y, color);
  59. LCD_put_pixel(x0 - x, y0 - y, color);
  60. LCD_put_pixel(x0 - y, y0 - x, color);
  61. LCD_put_pixel(x0 + y, y0 - x, color);
  62. LCD_put_pixel(x0 + x, y0 - y, color);
  63.  
  64. if (err <= 0)
  65. {
  66. y++;
  67. err += dy;
  68. dy += 2;
  69. }
  70. if (err > 0)
  71. {
  72. x--;
  73. dx += 2;
  74. err += (-polomer << 1) + dx;
  75. }
  76. }
  77. }
  78.  
  79. void line(char x1, char y1, char x2, char y2, int color){
  80. x1 = (int)x1;
  81. x2 = (int)x2;
  82. y1 = (int)y1;
  83. y2 = (int)y2;
  84. int dx, dy, p, x, y;
  85. dx=x2-x1;
  86. dy=y2-y1;
  87. x=x1;
  88. y=y1;
  89. p=2*dy-dx;
  90.  
  91. while(x<x2){
  92. if(p>=0){
  93. LCD_put_pixel(x,y,color);
  94. y=y+1;
  95. p=p+2*dy-2*dx;
  96. }
  97. else{
  98. LCD_put_pixel(x,y,color);
  99. p=p+2*dy;
  100. }
  101. x=x+1;
  102. }
  103.  
  104. }
  105.  
  106. int RGB(int R, int G, int B){
  107. R >>= 3;
  108. G >>= 2;
  109. B >>= 3;
  110. int barva = ((R << 11) | (G << 5) | B);
  111.  
  112. return barva;
  113. }
  114.  
  115. int transformX(int X){ //prevest kruznici, tak at stred kruznice je v 0,0 coz je uprostred LCD
  116. X = 0 + 160;
  117. return X;
  118. }
  119.  
  120. int transformY(int y)
  121. {
  122. y = 120 + 0;
  123. return Y;
  124. }
  125.  
  126.  
  127. int main()
  128. {
  129. LCD_init(); // LCD initialization
  130.  
  131. LCD_clear(); // LCD clear screen
  132.  
  133. //CTime curTime = CTime::GetCurrentTime(); // jsem jen zkoušel aktuální čas
  134. //ts = curTime.GetSecond();
  135. //tm = curTime.GetMinute();
  136. //th = curTime.GetHour();
  137.  
  138. double X, Y, uhel;
  139.  
  140. int prvky[] = {1,2,3,4,5,6,7,8,9,10,11,12}; // hodiny
  141.  
  142. kruznice(transformX(0), transformY(0), 90, RGB(0, 255, 0));
  143.  
  144. double x2, y2;
  145. const int angle = 6;
  146. for(int i = 0; i < 60; i++)
  147. {
  148. double radians = angle * 3.14 / 180; // prevod do radianu
  149. X2 = 160 + 90*sin(i*radians); // goniometricke funkce, aby si zjistil ty koncove body
  150. Y2 = 120 - 90*cos(i*radians);
  151. line(160, 120, X2, Y2, RGB(255, 255, 255));
  152. }
  153.  
  154. double x, y, uhel;
  155. for (int i = 0; i<12; i++) {
  156. uhel = 30 * 3.14 / 180;
  157. X = 160 + 90*sin(i * uhel);
  158. Y = 120 - 90*cos(i * uhel);
  159. if (i==0) {
  160. printChar(prvky[0], X, Y, RGB(255,255,255));}
  161. else {
  162. printChar(prvky[i], X, Y, RGB(255,255,255));
  163. }
  164.  
  165. }
  166.  
  167.  
  168. return 0;
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement