drum

Dependencies:   4DGL SDFileSystem mbed-rtos mbed

Fork of drums by Can Kabuloglu

Files at this revision

API Documentation at this revision

Comitter:
ykuris3
Date:
Mon May 01 00:31:47 2017 +0000
Parent:
3:54d4226a7d5e
Commit message:
drum;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 54d4226a7d5e -r d135d66c55e2 main.cpp
--- a/main.cpp	Sun Apr 30 00:55:41 2017 +0000
+++ b/main.cpp	Mon May 01 00:31:47 2017 +0000
@@ -21,8 +21,8 @@
 DigitalOut led2(LED2);
 DigitalOut led3(LED3);
 
-Thread t1;
-Mutex stdio_mutex;
+//Thread t1;
+//Mutex stdio_mutex;
 
 // Define and initiate global variables
 std::vector<Note> noteArr; 
@@ -66,10 +66,56 @@
     
 }
 
-void beatMover() {
-    while (true) {
+//void beatMover() {
+//    
+//}   
+
+//void checkHits() {
+//
+//}
+
+int main() {
+    button.mode(PullDown);    
+    screen.text_string("DRUM HERO 1.0", 15, 8, FONT_8X8, WHITE);  
+    screen.text_string("PRESS THE BUTTON", 14, 16, FONT_8X8, WHITE);
+    screen.text_string("TO START", 18, 19, FONT_8X8, WHITE);    
+    musicOn = 0;
+    while(!musicOn) {
+        if(button) {
+            musicOn = 1;
+        }    
+    }    
+    // Initiate the screen and the main graphics
+    initiateScreen();    
+    //t1.start(beatMover);
+    // t2.start(checkHits);
+    while (true) {        
         // Check if the song is ended
         if (beatNumber < s.length) {
+            if (r1 > 0.1) {
+                screen.rectangle(192,450,277,470,0xFF0000);
+                led1 = 1;
+//              if (screen.read_pixel(230, 420) == 0xFF0000) {
+//                  score++;
+//              }
+            } else if (r2 > 0.1) {
+                screen.rectangle(277,450,362,470,0x00FF00);
+                led2 = 1;
+//              if (screen.read_pixel(320, 420) == 0x00FF00) {
+//                  score++;
+//              }
+            } else if (r3 > 0.1) {
+                screen.rectangle(362,450,447,470,0x0000FF);
+                led3 = 1;
+//              if (screen.read_pixel(405, 420) == 0x0000FF) {
+//                  score++;
+//              }
+            } else {
+                screen.rectangle(192,450,447,470,0x000000);
+                led1 = 0;
+                led2 = 0;
+                led3 = 0;
+            }
             // Read the next beat (0,1,2,3)
             temp = s.notes[beatNumber++];
             // Check if there's a beat/note (not 0)
@@ -79,87 +125,27 @@
                 Note n1 = Note(temp);
                 noteArr.push_back(n1);
             }   
-            //beatNumber++;
-                
-            for(int i = skipped; i < noteArr.size(); i++) {
+            //beatNumber++;                
+            for (int i = skipped; i < noteArr.size(); i++) {
                 if (noteArr[i].consumed) {
                     skipped += 1;
                 } else {
-                    stdio_mutex.lock();
+                    //stdio_mutex.lock();
                     noteArr[i].drawNote();
-                    stdio_mutex.unlock();
+                    //stdio_mutex.unlock();
                 }
             }
         } else {
-             stdio_mutex.lock();
+             //stdio_mutex.lock();
              screen.rectangle(0,0,640,480,0x000000);
              screen.graphic_string("GAME OVER", 20, 200, FONT_8X8, WHITE, 2, 2);
-             stdio_mutex.unlock();
-             wait(30); 
-               
-        }
-        // Thread::wait(0.1);
-    }
-}   
-
-//void checkHits() {
-//
-//}
-
-int main() {
-    button.mode(PullDown);
-    
-    screen.text_string("DRUM HERO 1.0", 15, 8, FONT_8X8, WHITE);  
-    screen.text_string("PRESS THE BUTTON", 14, 16, FONT_8X8, WHITE);
-    screen.text_string("TO START", 18, 19, FONT_8X8, WHITE);
-    
-    musicOn = 0;
-    while(!musicOn) {
-        if(button) {
-            musicOn = 1;
-        }    
-    }
-    
-    // Initiate the screen and the main graphics
-    initiateScreen();
-    
-    t1.start(beatMover);
-    // t2.start(checkHits);
-    
-        while(true) {
-//        r1 = drum1.read();
-//        r2 = drum2.read();
-//        r3 = drum3.read();
-        
-        if (r1 > 0.1) {
-            // screen.rectangle(192,450,277,470,0xFF0000);
-            led1 = 1;
-//            if (screen.read_pixel(230, 420) == 0xFF0000) {
-//                score++;
-//            }
-        } else if (r2 > 0.1) {
-            // screen.rectangle(277,450,362,470,0x00FF00);
-            led2 = 1;
-//            if (screen.read_pixel(320, 420) == 0x00FF00) {
-//                score++;
-//            }
-        } else if (r3 > 0.1) {
-            // screen.rectangle(362,450,447,470,0x0000FF);
-            led3 = 1;
-//            if (screen.read_pixel(405, 420) == 0x0000FF) {
-//                score++;
-//            }
-        } else {
-            // screen.rectangle(192,450,447,470,0x000000);
-            led1 = 0;
-            led2 = 0;
-            led3 = 0;
+             //stdio_mutex.unlock();
+             wait(30);               
         }
         sprintf(buffer,"%d",score);
-        stdio_mutex.lock();
+        //stdio_mutex.lock();
         screen.text_string(buffer, 5, 7, FONT_8X8, WHITE);
-        stdio_mutex.unlock();
-        // Thread::wait(0.01); 
+        //stdio_mutex.unlock();
+        wait(0.4);
     }
-
 }
\ No newline at end of file