mbed1

Dependencies:   4DGL SDFileSystem mbed-rtos mbed

Fork of drums by Yusuf Kuris

Files at this revision

API Documentation at this revision

Comitter:
ckabuloglu
Date:
Sun Apr 30 00:55:41 2017 +0000
Parent:
2:5daa4d35a676
Commit message:
mbed1

Changed in this revision

Note/note.cpp Show annotated file Show diff for this revision Revisions of this file
Note/note.h Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
Song/song.cpp Show annotated file Show diff for this revision Revisions of this file
Song/song.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 5daa4d35a676 -r 54d4226a7d5e Note/note.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Note/note.cpp	Sun Apr 30 00:55:41 2017 +0000
@@ -0,0 +1,65 @@
+#include "mbed.h"
+#include "note.h"
+#include "TFT_4DGL.h"
+
+#define RATIO   0.66
+#define minY    130
+#define maxY    430
+
+// extern Serial pc;
+extern TFT_4DGL screen;
+
+// Initate an empty note
+Note::Note() {
+    // Do nothing
+}
+
+// Initiate the note object with a certain type
+Note::Note(int t) {
+    type = t;
+    if (t == 1) {
+        x = 276.0;
+        color = 0xFF0000;
+    } else if (t == 2) {
+        x = 314.0;
+        color = 0x00FF00;
+    } else if (t == 3) {
+        x = 358.0;
+        color = 0x0000FF;
+    }
+    y = 130.0;
+    w = 12.0;
+    h = w * RATIO;
+    speed = 38.0;
+    consumed = 0;
+}
+
+Note::~Note() {
+    // deletes the node  
+}
+
+void Note::updatePosition() {
+    y += speed;
+    if (type == 1) {
+        x += -0.14 * speed;
+    } else if (type == 3) {
+        x += 0.14 * speed;
+    }
+    w = 12.0 * (1 + (y - 130.0) / 300.0);
+    h = w * RATIO;
+}
+
+void Note::drawNote() {
+    float oldX = x;
+    float oldY = y;
+    float oldW = w;
+    float oldH = h;
+    updatePosition();
+    screen.ellipse((int)oldX, (int)oldY, (int)oldW, (int)oldH, 0xD38A41);
+    if (y > 420) {
+        consumed = 1;
+//      delete this;
+        return;  
+    }
+    screen.ellipse((int)x, (int)y, (int)w, (int)h, color);
+}
\ No newline at end of file
diff -r 5daa4d35a676 -r 54d4226a7d5e Note/note.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Note/note.h	Sun Apr 30 00:55:41 2017 +0000
@@ -0,0 +1,44 @@
+#ifndef NOTE_H__
+#define NOTE_H__
+
+#define MIN_Y 130
+#define MAX_Y 430
+
+class Note {
+    public:
+    
+        // Type of the note (1,2,3) - (left, center, right)
+        int type;
+        
+        // Position accros the fret
+        float x,y;
+        
+        // Sizes of the displayed note
+        float w,h;
+        
+        // Speed of the the note
+        int speed;
+        
+        // Color of the note
+        int color;
+        
+        // Flag showing if the note is already consumed
+        int consumed;
+    
+        // Constructor of the note, no args
+        Note();
+        
+        // Constructor of the note, initiate with type
+        Note(int t);
+        
+        // Destructor for the note
+        ~Note();
+        
+        // Update the position of the note based on its speed
+        void updatePosition();
+        
+        // Draw the note with its current stats on the screen
+        void drawNote();
+  
+};
+#endif
\ No newline at end of file
diff -r 5daa4d35a676 -r 54d4226a7d5e SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Sun Apr 30 00:55:41 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/SDFileSystem/#8db0d3b02cec
diff -r 5daa4d35a676 -r 54d4226a7d5e Song/song.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Song/song.cpp	Sun Apr 30 00:55:41 2017 +0000
@@ -0,0 +1,18 @@
+#include "mbed.h"
+#include "song.h"
+
+Song::Song(int id) {
+    songId = id;
+
+    static const int arr[192] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 0,
+                                1, 0, 1, 0, 2, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 0,
+                                1, 0, 1, 0, 2, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 0,
+                                1, 0, 1, 0, 2, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 0,
+                                1, 0, 1, 0, 2, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 0,
+                                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};
+                                  
+    vector<int> vec (arr, arr + sizeof(arr) / sizeof(arr[0]) );
+    length = vec.size();
+    notes = vec;                            
+    timing = 0.1; 
+}
\ No newline at end of file
diff -r 5daa4d35a676 -r 54d4226a7d5e Song/song.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Song/song.h	Sun Apr 30 00:55:41 2017 +0000
@@ -0,0 +1,25 @@
+#ifndef SONG_H__
+#define SONG_H__
+
+#include <vector>
+
+class Song {
+    public:
+        // ID of the song to be played
+        int songId;
+        
+        // The notes that will be coming, type's of notes(1,2,3) that determine
+        // if a beat needs to be hit or not, 0's mean no hit, (4 means end of the
+        // song)
+        std::vector<int> notes;
+        
+        // The length of the array
+        int length;
+        
+        // BPM value, or the time value between two notes
+        float timing;
+        
+        // Construct a song with a certain ID
+        Song(int id);
+};
+#endif
diff -r 5daa4d35a676 -r 54d4226a7d5e main.cpp
--- a/main.cpp	Wed Apr 26 19:43:51 2017 +0000
+++ b/main.cpp	Sun Apr 30 00:55:41 2017 +0000
@@ -1,117 +1,165 @@
-//
-// TFT_4DGL is a class to drive 4D Systems TFT touch screens
-//
-// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
-//
-// TFT_4DGL is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
+#include "mbed.h"
+#include "rtos.h"
+#include "TFT_4DGL.h"
+#include "note.h"
+#include "song.h"
+#include <vector>
+
+
+// Define all the ports
+// Serial pc(USBTX, USBRX);
+TFT_4DGL screen(p9,p10,p11); // serial tx, serial rx, reset pin;
+AnalogIn r1(p18);
+AnalogIn r2(p19);
+AnalogIn r3(p20);
+DigitalOut musicOn(p22);
+DigitalIn button(p21);
+
+// Define objects
+// Ticker beatCounter;
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+
+Thread t1;
+Mutex stdio_mutex;
+
+// Define and initiate global variables
+std::vector<Note> noteArr; 
+int beatNumber = 0;
+char buffer[2];
+int skipped = 0;
+int temp;
+int score = 0;
+Song s = Song(1);
+//float r1;
+//float r2;
+//float r3;
+
+void initiateScreen() {
+    // Initiate the screen and the background
+    screen.baudrate(3000000);
+    screen.display_control(0x0c, 0x01);
+    screen.background_color(0x000000);
+    
+    // Draw the frame
+    screen.rectangle(192, 120, 447, 450, 0xD38A41);
+    screen.line(256, 120, 192, 450, 0x96411F);
+    screen.line(296, 120, 277, 450, 0x96411F);
+    screen.line(332, 120, 362, 450, 0x96411F);
+    screen.line(372, 120, 447, 450, 0x96411F);
+    screen.triangle(192, 120, 192, 450, 256, 120, 0x000000);
+    screen.triangle(372, 120, 447, 450, 447, 120, 0x000000);
+    screen.rectangle(447, 120, 450, 450, 0x000000);
+    
+    screen.rectangle(256, 100, 296, 120, 0xFF0000);
+    screen.rectangle(296, 100, 332, 120, 0x00FF00);
+    screen.rectangle(332, 100, 372, 120, 0x0000FF);
+    
+//    screen.rectangle(192,450,277,470,0xFF0000);
+//    screen.rectangle(277,450,362,470,0x00FF00);
+//    screen.rectangle(362,450,447,470,0x0000FF);
+    
+    // Define the points
+    screen.graphic_string("POINTS:", 30, 100, FONT_8X8, WHITE, 2, 2);
+    screen.graphic_string("ROCK YOU", 430, 100, FONT_8X8, WHITE, 2, 2);
+    
+}
+
+void beatMover() {
+    while (true) {
+        // Check if the song is ended
+        if (beatNumber < s.length) {
+            // Read the next beat (0,1,2,3)
+            temp = s.notes[beatNumber++];
+            // Check if there's a beat/note (not 0)
+            if (temp) {
+                // If beat/note exists, create the object for it and push
+                // it to the array of current notes on the screen
+                Note n1 = Note(temp);
+                noteArr.push_back(n1);
+            }   
+            //beatNumber++;
+                
+            for(int i = skipped; i < noteArr.size(); i++) {
+                if (noteArr[i].consumed) {
+                    skipped += 1;
+                } else {
+                    stdio_mutex.lock();
+                    noteArr[i].drawNote();
+                    stdio_mutex.unlock();
+                }
+            }
+        } else {
+             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() {
 //
-// TFT_4DGL is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with TFT_4DGL.  If not, see <http://www.gnu.org/licenses/>.
-
-#include "mbed.h"
-#include "TFT_4DGL.h"
-
-// overwrite 4DGL library screen size settings in TFT_4DGL.h
-#define SIZE_X  479
-#define SIZE_Y  639
-//
-
-TFT_4DGL ecran(p9,p10,p11); // serial tx, serial rx, reset pin;
-Timer t;
+//}
 
 int main() {
-//    char s[500];
-//    int x = 0, y = 0, status, xc = 0, yc = 0;
-
-    ecran.baudrate(128000);
-// added - Set Display to 640 by 480 mode
-    ecran.display_control(0x0c, 0x01);
+    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);
     
-//    ecran.background_color(DGREY);
-
-    ecran.rectangle(192, 120, 447, 450, 0xD38A41);
-    ecran.line(256, 120, 192, 450, 0x96411F);
-    ecran.line(296, 120, 277, 450, 0x96411F);
-    ecran.line(332, 120, 362, 450, 0x96411F);
-    ecran.line(372, 120, 447, 450, 0x96411F);
-    ecran.triangle(192, 120, 192, 450, 256, 120, 0x000000);
-    ecran.triangle(372, 120, 447, 450, 447, 120, 0x000000);
-    ecran.rectangle(447, 120, 450, 450, 0x000000);
+    musicOn = 0;
+    while(!musicOn) {
+        if(button) {
+            musicOn = 1;
+        }    
+    }
+    
+    // Initiate the screen and the main graphics
+    initiateScreen();
+    
+    t1.start(beatMover);
+    // t2.start(checkHits);
     
-    ecran.ellipse(314, 132, 12, 8, 0xFF0000);
-    ecran.ellipse(276, 132, 12, 8, 0x0000FF);
-    ecran.ellipse(352, 132, 12, 8, 0x00FF00);
-    
-    int i = 0;
-    double x = 276;
-    double x3 = 352;
-    int y = 132;
-    int x2 = 314;
-    int y2 = 132;
-    int y3 = 132;
-    int x_len = 12;
-    int y_len = 8;
-    while(i < 70) {
-        i += 1;
-        if (i % 8 == 0) {
-            x_len += 1;
-            y_len += 1;
+        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;
         }
-        y2 += 4;
-        y3 += 4;
-        y += 4;
-        x -= 0.5091;
-        x3 += 0.5091;
-        ecran.ellipse(x2, y2, x_len, y_len, 0xFF0000);
-        ecran.ellipse(x, y, x_len, y_len, 0x0000FF);
-        ecran.ellipse(x3, y3, x_len, y_len, 0x00FF00);
-        wait(0.1);
-        ecran.ellipse(x2, y2, x_len, y_len, 0xD38A41);
-        ecran.ellipse(x, y, x_len, y_len, 0xD38A41);
-        ecran.ellipse(x3, y3, x_len, y_len, 0xD38A41);
-    }  
-    
-//
-    //ecran.background_color(DGREY);
-//    ecran.circle(120, 160, 80, 0xFF00FF);
-//    ecran.triangle(120, 100, 40, 300, 200, 270, 0x0000FF);
-//    ecran.line(0, 0, 239, 319, 0xFF0000);
-//    ecran.rectangle(50, 50, 200, 90, 0x00FF00);
-//    ecran.ellipse(100, 250, 80, 30, 0xFFFF00);
-//    ecran.pixel(120, 160, BLACK);
-//    ecran.read_pixel(120, 170);
-//    ecran.screen_copy(50, 50, 200, 200, 100, 100);
-//    ecran.pen_size(WIREFRAME);
-//    ecran.circle(120, 160, 60, BLACK);
-//    ecran.set_font(FONT_8X8);
-//    ecran.text_mode(TRANSPARENT);
-//    ecran.text_char('B', 9, 8, BLACK);
-//    ecran.text_char('I',10, 8, BLACK);
-//    ecran.text_char('G',11, 8, BLACK);
-//    ecran.graphic_char('G', 120, 120, BLACK, 4, 4);
-//    ecran.text_string("This is a test of string", 2, 12, FONT_8X8, WHITE);
-//    ecran.graphic_string("This is a test of graphic string", 20, 200, FONT_8X8, WHITE, 2, 2);
-//    ecran.text_button("OK", UP, 40, 260, 0xFF0000, FONT_8X8, BLACK, 2, 2);
-//
-//  // delete touch screen demo - no touch on uVGA II
-//    ecran.cls();
-//    int x = -54;
-//    int y = -54;
-//    ecran.background_color(BLACK);
-//    ecran.circle(x, y, 60, 0xD6A34F);
-//    while(1) {
-//        ecran.circle(x, y, 60, 0xD6A34F);
-//        x = x + 10;
-//        y = y + 10;
-//        ecran.circle(x, y, 60, 0xD6A34F);
-//    }
-//        
+        sprintf(buffer,"%d",score);
+        stdio_mutex.lock();
+        screen.text_string(buffer, 5, 7, FONT_8X8, WHITE);
+        stdio_mutex.unlock();
+        // Thread::wait(0.01); 
+    }
+
 }
\ No newline at end of file
diff -r 5daa4d35a676 -r 54d4226a7d5e mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Sun Apr 30 00:55:41 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
diff -r 5daa4d35a676 -r 54d4226a7d5e mbed.bld
--- a/mbed.bld	Wed Apr 26 19:43:51 2017 +0000
+++ b/mbed.bld	Sun Apr 30 00:55:41 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da
+https://mbed.org/users/mbed_official/code/mbed/builds/794e51388b66
\ No newline at end of file