Advertisement
JosipFranjic

Untitled

May 24th, 2019
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. #include "mbed.h"
  2. #include "math.h"
  3.  
  4. #define dp23 P0_0
  5. const int tabela[] = {
  6. 0x40 ,
  7. 0x79 ,
  8. 0x24 ,
  9. 0x30 ,
  10. 0x19 ,
  11. 0x12 ,
  12. 0x02 ,
  13. 0x78 ,
  14. 0x00 ,
  15. 0x10
  16. };
  17. DigitalOut enable(dp14);
  18. BusOut d(dp23,dp24,dp25);
  19. BusOut r(dp16,dp15,dp17,dp18);
  20. BusIn k(dp9,dp10,dp11,dp13);
  21. BusOut out(dp23,dp24,dp25,dp26,dp27,dp1,dp2);
  22. DigitalOut dot(dp4);
  23. int v;
  24. Ticker tast;
  25. Ticker isp;
  26. int cifra=0;
  27. int cifre[2]={0,0};
  28. int operacija=0;
  29. bool mode=0;
  30. float rezultat=0;
  31. double fact(int n){
  32. int facto=1;
  33. for (int c = 1; c <= n; c++)
  34. facto = facto * c;
  35. return facto;
  36. }
  37. double paw(int a,int n){
  38. int ret=a;
  39. for(int i=1;i<n;i++)ret*=ret;
  40. return ret;
  41. }
  42. double korjen(double a){
  43. return pow(2.71828,log(a)/2);
  44. }
  45. double kubkorjen(double a){
  46. return pow(2.71828,log(a)/3);
  47. }
  48. float sinus(int a){
  49. return (a-paw(a,3)/fact(3)+paw(a,5)/fact(5)-paw(a,7)/fact(7));
  50. }
  51. float kosinus(int a){
  52. return korjen(1-sinus(a)*sinus(a));
  53. }
  54. void Reset(){
  55. cifra=0;
  56. cifre[0]=0;cifre[1]=0;
  57. operacija=0;
  58. rezultat=0;
  59. }
  60. void DodajCifru(){
  61. if(rezultat!=0)Reset();
  62. if(cifre[cifra]>999)return;
  63. cifre[cifra]= cifre[cifra]*10+v;
  64. }
  65.  
  66. void Ispisi(){
  67. float broj1;
  68. if(rezultat>999)rezultat=999;
  69. if(rezultat==0)broj1=cifre[cifra];
  70. else broj1=rezultat;
  71. if(int(broj1)==broj1||broj1>=100){
  72. int broj=int(broj1);
  73. out=tabela[broj%10];
  74. d=6;
  75. broj/=10;
  76. wait_ms(8);
  77. out=tabela[broj%10];
  78. d=5;
  79. broj/=10;
  80. wait_ms(8);
  81. out=tabela[broj%10];
  82. d=3;
  83. wait_ms(8);
  84. d=7;
  85. }else{
  86. broj1=broj1*10;
  87. int broj=int(broj1);
  88. out=tabela[broj%10];
  89. d=6;
  90. broj/=10;
  91. wait_ms(8);
  92. out=tabela[broj%10];
  93. d=5;
  94. dot=0;
  95. broj/=10;
  96. wait_ms(8);
  97. out=tabela[broj%10];
  98. d=3;
  99. wait_ms(8);
  100. d=7;
  101. dot=1;
  102. }
  103. }
  104. void IspisiRezultat(){
  105. if(operacija==0)return;
  106. if(mode==0){
  107. if(operacija==65){
  108. rezultat=cifre[0]+cifre[1];
  109. return;
  110. }
  111. if(operacija==66){
  112. rezultat=abs(cifre[0]-cifre[1]);
  113. return;
  114. }
  115. if(operacija==67){
  116. rezultat=cifre[0]*cifre[1];
  117. return;
  118. }
  119. if(operacija==68){
  120. rezultat=cifre[0]/cifre[1];
  121. return;
  122. }
  123. }
  124. if(mode==1){
  125. if(operacija==65){
  126. rezultat=sinus(cifre[0]);
  127. return;
  128. }
  129. if(operacija==66){
  130. rezultat=kosinus(cifre[0]);
  131. return;
  132. }
  133. if(operacija==67){
  134. rezultat=korjen(cifre[0]);
  135. return;
  136. }
  137. if(operacija==68){
  138. rezultat=kubkorjen(cifre[0]);
  139. return;
  140. }
  141.  
  142. }
  143. }
  144.  
  145. void t(){
  146. v=-1;
  147. r=1;
  148. if(k==1)v=1;
  149. if(k==2)v=2;
  150. if(k==4)v=3;
  151. if(k==8)v=65;
  152. r=2;
  153. if(k==1)v=4;
  154. if(k==2)v=5;
  155. if(k==4)v=6;
  156. if(k==8)v=66;
  157. r=4;
  158. if(k==1)v=7;
  159. if(k==2)v=8;
  160. if(k==4)v=9;
  161. if(k==8)v=67;
  162. r=8;
  163. if(k==1)v=41;
  164. if(k==2)v=0;
  165. if(k==4)v=43;
  166. if(k==8)v=68;
  167. wait(0.05);
  168. if(v==-1)return;
  169. if(v>=0&&v<=9)DodajCifru();
  170. if(v==43)IspisiRezultat();
  171. if(v>=65&&v<=68){operacija=v;cifra=1;if(mode==1)IspisiRezultat();}
  172. if(v==41){mode=!mode;Reset();}
  173. return;
  174. }
  175.  
  176. int main() {
  177. enable=1;
  178. tast.attach(&t,0.01);
  179. isp.attach(&Ispisi,0.01);
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement