Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: TextLCD mbed MultiSerial Pswitch_Lib
Revision 10:8b49bbf4c0c9, committed 2014-10-16
- Comitter:
- lilac0112_1
- Date:
- Thu Oct 16 11:00:30 2014 +0000
- Parent:
- 9:39d3392a9587
- Commit message:
- Add new a bit data.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Oct 04 02:28:38 2014 +0000
+++ b/main.cpp Thu Oct 16 11:00:30 2014 +0000
@@ -12,9 +12,27 @@
enum COMPASS{NORTH=0, EAST, SOUTH, WEST};
enum COLOR{YELLOW=0, RED, GREEN, BLUE};
+
+#define INITIAL_TIME 180
+
+LocalFileSystem local("local");
+
+Ticker Watch;
+
+uint8_t GivenTime=INITIAL_TIME;
+
+char *FileName = "/local/GIVEN180.txt";
+char *format = "%d\n";
+FILE *fp;
+
+void TickTack(void);
+
+
+
+
+
uint8_t INdata[DATA_NUM]={0}, EXdata[DATA_NUM]={0};
uint8_t count=0;
-//uint8_t watch;
bool SW;
void SetUp();
@@ -37,6 +55,23 @@
TextLCD lcd(p26, p25, p24, p23, p22, p21, TextLCD::LCD16x2); // rs, e, d4-d7
int main() {
+ /*fp = fopen(FileName, "r");
+ if (fp) {
+ fscanf(fp, format, &GivenTime);
+ fclose(fp);
+ }
+ fp = fopen(FileName, "w");
+ if (fp) {
+ fprintf(fp, format, GivenTime);
+ fclose(fp);
+ }
+
+ if((GivenTime == 0)||(GivenTime > 180)) GivenTime = INITIAL_TIME;
+ */
+ Watch.attach(TickTack, 1);
+
+
+
SetUp();
@@ -48,17 +83,25 @@
YLED=!Toggle.read();
}
- if(YLED&&SW) lcd.cls(), lcd.printf("Pause Mode\n"), SW=0;
- if((!YLED)&&(!SW)) lcd.cls(), lcd.printf("Run Mode\n"), SW=1;
+ if(YLED&&SW) lcd.locate(0, 0), lcd.printf("Setting Mode\n"), SW=0, Watch.detach();
+ if((!YLED)&&(!SW)) lcd.locate(0, 0), lcd.printf("Run Mode \n"), SW=1, Watch.attach(TickTack, 1);
if(Toggle.read()){
+
+
EXdata[0] = LinkBit(!CrossKey[YELLOW][LEFT], !CrossKey[RED][LEFT], !CrossKey[GREEN][LEFT], !CrossKey[BLUE][LEFT],
!CrossKey[YELLOW][RIGHT], !CrossKey[RED][RIGHT], !CrossKey[GREEN][RIGHT], !CrossKey[BLUE][RIGHT]);
- EXdata[1] = LinkBit(0, 0, 0, 0, !SideKey[INDEX][LEFT], !SideKey[MIDDLE][LEFT], !SideKey[INDEX][RIGHT], !SideKey[MIDDLE][RIGHT]);
+ EXdata[1] = LinkBit(0, 0, 0, 1, !SideKey[INDEX][LEFT], !SideKey[MIDDLE][LEFT], !SideKey[INDEX][RIGHT], !SideKey[MIDDLE][RIGHT]);
}else{
- EXdata[0] = EXdata[1] = 0x00;
+ EXdata[0] = 0x00;
+ EXdata[1] = 0x00;
+
+ /*if((GivenTime!=INITIAL_TIME)&&(LinkBit(0, 0, 0, 0, !SideKey[INDEX][LEFT], !SideKey[MIDDLE][LEFT], !SideKey[INDEX][RIGHT], !SideKey[MIDDLE][RIGHT])==0xF)){
+ GivenTime = INITIAL_TIME;
+ lcd.locate(0, 1), lcd.printf("%d:%02d \n", GivenTime/60, GivenTime%60);
+ }*/
}
LED = Toggle*LinkBit(0, 0, 0, 0, !SideKey[INDEX][LEFT], !SideKey[MIDDLE][LEFT], !SideKey[INDEX][RIGHT], !SideKey[MIDDLE][RIGHT]);
@@ -68,11 +111,12 @@
void SetUp(void){
-
+ //SW = !Toggle;
- lcd.printf("Hello World!\n");
- if(!Toggle.read()) lcd.cls(), lcd.printf("Pause Mode\n"), SW=0;
- if(Toggle.read()) lcd.cls(), lcd.printf("Run Mode\n"), SW=1;
+ if(!Toggle) lcd.locate(0, 0), lcd.printf("Setting Mode\n"), SW=0;
+ else lcd.locate(0, 0), lcd.printf("Run Mode \n"), SW=1;
+
+ lcd.locate(0, 1), lcd.printf("%d:%02d \n", GivenTime/60, GivenTime%60);
CrossKey[NORTH][RIGHT].mode(PullUp);
CrossKey[EAST][RIGHT].mode(PullUp);
@@ -98,4 +142,23 @@
void illumination(void){//literally
count++;
LED = count;
+}
+
+
+
+void TickTack(void){
+ if(!Toggle) return;
+ lcd.locate(0, 1);
+
+ if(GivenTime==0){
+ lcd.printf("GameSet! \n");
+ Watch.detach();
+ }
+ else{
+ GivenTime--;
+ /*fp = fopen(FileName, "w");
+ fprintf(fp, format, GivenTime);
+ fclose(fp);*/
+ lcd.printf("%d:%02d \n", GivenTime/60, GivenTime%60);
+ }
}
\ No newline at end of file