pp
Dependencies: mbed
main.cpp
- Committer:
- NamSom
- Date:
- 2015-12-05
- Revision:
- 4:a61cdd4e7afa
- Parent:
- 3:dc88b52d526c
- Child:
- 5:60262753a05f
File content as of revision 4:a61cdd4e7afa:
#include "mbed.h" #include "DS1307.h" #include "DigitDisplay.h" #include "Game.h" DS1307 myrtc(I2C_SDA,I2C_SCL); DigitDisplay display(D7,D8); Game game; DigitalOut buzzer(D6); BusIn b(D9,D10,D11); BusOut led(D2,D3,D4,D5); AnalogIn analog_value(A2); const bool bcd[16][4] = {{0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1},{0,1,0,0},{0,1,0,1},{0,1,1,0},{0,1,1,1}, {1,0,0,0},{1,0,0,1},{1,0,1,0},{1,0,1,1},{1,1,0,0},{1,1,0,1},{1,1,1,0},{1,1,1,1}}; void DisplayTime(); int mode=0; int main() { b.mode(PullUp); int sec=45,min=59,hour=6,day=7,date=5,month=12,year=15; int n=0,opt=1,p=0,ten_hour,nu_hour,ten_min,nu_min,hour_a=7,min_a=0; float mea; int state=0; int hexnum[4]; int currenthex=0, checkbcd=0, gameround=0, changehex=1; myrtc.settime(sec,min,hour,day,date,month,year); //DisplayTime(); //display.Displayset((hour-(hour%10))/10,hour%10,(min-(min%10))/10,min%10); while(1) { mea=analog_value.read(); /*if(state==0) { mea=analog_value.read(); if(b==0b011){n=1;} else if(b==0b101){n=2;} else if(b==0b110){n=3;} else n=0; display.getButtonState(n); wait_ms(100); //printf("%d\n",mode); wait_ms(100); if(display.checkButton3()==1) { p++; if(p==10){p=0;} printf("%d\n",p); if(p%2==0){opt=1;} if(p%2==1){opt=2;} } myrtc.gettime(&sec,&min,&hour,&day,&date,&month,&year); if(opt==1) { display.setColon(1); display.Displayset((hour-(hour%10))/10,hour%10,(min-(min%10))/10,min%10); } if(opt==2) { ten_hour=(hour_a-(hour_a%10))/10; nu_hour=hour_a%10; ten_min=(min_a-(min_a%10))/10; nu_min=min_a%10; display.Displayset(ten_hour,nu_hour,ten_min,nu_min); if(display.checkButton1()==1){hour_a++;} if(display.checkButton2()==1){min_a++;} if(hour_a==24){hour_a=0;} if(min_a==60){min_a=0;} } } if(hour==hour_a&&min==min_a) else*/ if(mode==0) { //buzzer=1; state = 1; int gamelevel=game.getlevel(); if(changehex==1) { for(int i=0;i<gamelevel;i++) { hexnum[i] = game.randomHex(mea); } if(gamelevel==1) display.Displayset(0xFF,0xFF,hexnum[0],0xFF); else if(gamelevel==2) display.Displayset(0xFF,hexnum[0],hexnum[1],0xFF); else if(gamelevel==3) display.Displayset(0xFF,hexnum[0],hexnum[1],hexnum[2]); else if(gamelevel==4) display.Displayset(hexnum[0],hexnum[1],hexnum[2],hexnum[3]); changehex = 0; } if(b==0b011){n=1;} else if(b==0b101){n=2;} else if(b==0b110){n=3;} else n=0; display.getButtonState(n); if((bcd[hexnum[currenthex]][checkbcd]==0 && display.checkButton1()==1)||(bcd[hexnum[currenthex]][checkbcd]==1 && display.checkButton2()==1)) { if(checkbcd<4) checkbcd++; else { checkbcd=0; currenthex++; if(currenthex==gamelevel) { gameround++; currenthex = 0; changehex = 1; display.A(); } } } else if((bcd[hexnum[currenthex]][checkbcd]==1 && display.checkButton1()==1)||(bcd[hexnum[currenthex]][checkbcd]==0 && display.checkButton2()==1)) { checkbcd=0; game.pluslevel(); changehex = 1; display.F(); } else if(display.checkButton3()==3) { checkbcd=0; currenthex==0; } if(gameround==4) { mode=1; state=0; buzzer=0; game.resetlevel(); checkbcd=0; currenthex==0; gameround=0; changehex=1; } } printf("%f\n",mea); if(mea>=0.65){min_a=min_a+1;} } }