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.
Revision 18:c93c501ed1c0, committed 2015-04-30
- Comitter:
- jordaahh
- Date:
- Thu Apr 30 18:29:35 2015 +0000
- Parent:
- 17:f56dd50acf2d
- Child:
- 19:baa140ab4490
- Commit message:
- writes but doesn't read
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Apr 30 15:44:24 2015 +0000
+++ b/main.cpp Thu Apr 30 18:29:35 2015 +0000
@@ -34,6 +34,8 @@
int i=24; // initial coordinates for player object
int j=42;
+// initial value for score
+int score = 0;
// timer to regularly read the joystick
@@ -115,7 +117,7 @@
//frequency array for song
float frequency[]= {880,880,0,0,440,880,0,0,440,880,600,1047,0,0,0,0,880,880,0,0,440,880,0,0,440,880,600,587,0,0,0,0,0};
-float frequency2[]= {600,600,400,400,200,0};
+float frequency2[]= {600,600,400,400,200};
// function prototypes
@@ -129,12 +131,13 @@
void menu();
void playGame();
void TimeAndDate();
-void writeDataToFile(int data);
+void writeDataToFile();
void BandVMenu();
void brightness();
void volume();
void tone();
void deadTone();
+void readDataFromFile();
int main()
{
@@ -302,7 +305,6 @@
int x = 0; // wall starts from the coordinates (0,0)
int y = 0;
int z = 30;
- int score = 0;
int a = 0;
int b = 47;
int d = 30;
@@ -312,6 +314,7 @@
int q = 83;
int w = 0;
int e = 24;
+ score = 0;
lcd.printString("GO!",35,2);
wait(1);
@@ -434,7 +437,9 @@
j=j;
}
if (lcd.getPixel(i,j-1)) {
- writeDataToFile(score); // write current value to disk
+ readDataFromFile();
+ writeDataToFile(); // write current value to disk
+
clearCells();
int m = 1;
lcd.printString("game over",1,2);
@@ -496,7 +501,9 @@
}
}
if (lcd.getPixel(i+1,j-1)) {
- writeDataToFile(score); // write current value to disk
+ readDataFromFile();
+ writeDataToFile(); // write current value to disk
+
clearCells();
int m = 1;
lcd.printString("game over",1,2);
@@ -557,7 +564,9 @@
}
}
if (lcd.getPixel(i+2,j-1)) {
- writeDataToFile(score); // write current value to disk
+ readDataFromFile();
+ writeDataToFile(); // write current value to disk
+
clearCells();
int m = 1;
lcd.printString("game over",1,2);
@@ -616,7 +625,9 @@
}
}
if (lcd.getPixel(i,j)) {
- writeDataToFile(score); // write current value to disk
+ readDataFromFile();
+ writeDataToFile(); // write current value to disk
+
clearCells();
int m = 1;
lcd.printString("game over",1,2);
@@ -678,7 +689,9 @@
}
}
if (lcd.getPixel(i+1,j)) {
- writeDataToFile(score); // write current value to disk
+ readDataFromFile();
+ writeDataToFile(); // write current value to disk
+
clearCells();
int m = 1;
lcd.printString("game over",1,2);
@@ -739,7 +752,9 @@
}
}
if (lcd.getPixel(i+2,j)) {
- writeDataToFile(score); // write current value to disk
+ readDataFromFile();
+ writeDataToFile(); // write current value to disk
+
clearCells();
int m = 1;
lcd.printString("game over",1,2);
@@ -1076,20 +1091,25 @@
}
}
-void writeDataToFile(int data)
+void writeDataToFile()
{
- char str[14];
-
- FILE *fp = fopen("/local/score.csv", "a"); // open 'score.txt'
+
+ FILE *fp = fopen("/local/score.csv", "w"); // open 'score.txt'
// if the file doesn't exist it is created, if it exists, data is appended to the end
- fprintf(fp,"%i\n",data); // print string to file
+ fprintf(fp,"%i",score); // print string to file
fclose(fp); // close file
-
+}
+
+ void readDataFromFile()
+ {
+ char Buffer[14];
+
FILE *fp2 = fopen("/local/score.csv", "r"); // open 'score.txt'
- fscanf (fp2, "%s", str);
+ fscanf (fp2, "%i",score);
+ sprintf(Buffer,"%i", score);
fclose(fp2); // close file
- lcd.printString(str,0,0);
- wait(3);// close file
+ lcd.printString(Buffer,0,0);
+ wait(3);
}
@@ -1100,7 +1120,7 @@
if(FLAG3==1) {
FLAG3 = 0;
buz.period(1/(frequency[u])); // set PWM period
- buz=0.7;
+ buz=0.2;
u++;
}
if( u > 30) {
@@ -1116,7 +1136,7 @@
if(FLAG3==1) {
FLAG3 = 0;
buz.period(1/(frequency2[l])); // set PWM period
- buz=0.7;
+ buz=0.2;
l++;
}
if( l > 6) {