Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mbed.h"
- #include "math.h"
- #define dp23 P0_0
- const int tabela[] = {
- 0x40 ,
- 0x79 ,
- 0x24 ,
- 0x30 ,
- 0x19 ,
- 0x12 ,
- 0x02 ,
- 0x78 ,
- 0x00 ,
- 0x10
- };
- DigitalOut enable(dp14);
- BusOut d(dp23,dp24,dp25);
- BusOut r(dp16,dp15,dp17,dp18);
- BusIn k(dp9,dp10,dp11,dp13);
- BusOut out(dp23,dp24,dp25,dp26,dp27,dp1,dp2);
- DigitalOut dot(dp4);
- int v;
- Ticker tast;
- Ticker isp;
- int cifra=0;
- int cifre[2]={0,0};
- int operacija=0;
- bool mode=0;
- float rezultat=0;
- double fact(int n){
- int facto=1;
- for (int c = 1; c <= n; c++)
- facto = facto * c;
- return facto;
- }
- double paw(int a,int n){
- int ret=a;
- for(int i=1;i<n;i++)ret*=ret;
- return ret;
- }
- double korjen(double a){
- return pow(2.71828,log(a)/2);
- }
- double kubkorjen(double a){
- return pow(2.71828,log(a)/3);
- }
- float sinus(int a){
- return (a-paw(a,3)/fact(3)+paw(a,5)/fact(5)-paw(a,7)/fact(7));
- }
- float kosinus(int a){
- return korjen(1-sinus(a)*sinus(a));
- }
- void Reset(){
- cifra=0;
- cifre[0]=0;cifre[1]=0;
- operacija=0;
- rezultat=0;
- }
- void DodajCifru(){
- if(rezultat!=0)Reset();
- if(cifre[cifra]>999)return;
- cifre[cifra]= cifre[cifra]*10+v;
- }
- void Ispisi(){
- float broj1;
- if(rezultat>999)rezultat=999;
- if(rezultat==0)broj1=cifre[cifra];
- else broj1=rezultat;
- if(int(broj1)==broj1||broj1>=100){
- int broj=int(broj1);
- out=tabela[broj%10];
- d=6;
- broj/=10;
- wait_ms(8);
- out=tabela[broj%10];
- d=5;
- broj/=10;
- wait_ms(8);
- out=tabela[broj%10];
- d=3;
- wait_ms(8);
- d=7;
- }else{
- broj1=broj1*10;
- int broj=int(broj1);
- out=tabela[broj%10];
- d=6;
- broj/=10;
- wait_ms(8);
- out=tabela[broj%10];
- d=5;
- dot=0;
- broj/=10;
- wait_ms(8);
- out=tabela[broj%10];
- d=3;
- wait_ms(8);
- d=7;
- dot=1;
- }
- }
- void IspisiRezultat(){
- if(operacija==0)return;
- if(mode==0){
- if(operacija==65){
- rezultat=cifre[0]+cifre[1];
- return;
- }
- if(operacija==66){
- rezultat=abs(cifre[0]-cifre[1]);
- return;
- }
- if(operacija==67){
- rezultat=cifre[0]*cifre[1];
- return;
- }
- if(operacija==68){
- rezultat=cifre[0]/cifre[1];
- return;
- }
- }
- if(mode==1){
- if(operacija==65){
- rezultat=sinus(cifre[0]);
- return;
- }
- if(operacija==66){
- rezultat=kosinus(cifre[0]);
- return;
- }
- if(operacija==67){
- rezultat=korjen(cifre[0]);
- return;
- }
- if(operacija==68){
- rezultat=kubkorjen(cifre[0]);
- return;
- }
- }
- }
- void t(){
- v=-1;
- r=1;
- if(k==1)v=1;
- if(k==2)v=2;
- if(k==4)v=3;
- if(k==8)v=65;
- r=2;
- if(k==1)v=4;
- if(k==2)v=5;
- if(k==4)v=6;
- if(k==8)v=66;
- r=4;
- if(k==1)v=7;
- if(k==2)v=8;
- if(k==4)v=9;
- if(k==8)v=67;
- r=8;
- if(k==1)v=41;
- if(k==2)v=0;
- if(k==4)v=43;
- if(k==8)v=68;
- wait(0.05);
- if(v==-1)return;
- if(v>=0&&v<=9)DodajCifru();
- if(v==43)IspisiRezultat();
- if(v>=65&&v<=68){operacija=v;cifra=1;if(mode==1)IspisiRezultat();}
- if(v==41){mode=!mode;Reset();}
- return;
- }
- int main() {
- enable=1;
- tast.attach(&t,0.01);
- isp.attach(&Ispisi,0.01);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement