for jorge

Dependencies:   MMA8451Q mbed nRF24L01P

Fork of nRF24L01P_Hello_World by Owen Edwards

Files at this revision

API Documentation at this revision

Comitter:
supershiu
Date:
Tue Mar 14 19:36:33 2017 +0000
Parent:
1:5be2682710c6
Commit message:
for jorge

Changed in this revision

MMA8451Q.lib 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.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 5be2682710c6 -r 020a3715aac4 MMA8451Q.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Tue Mar 14 19:36:33 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
diff -r 5be2682710c6 -r 020a3715aac4 main.cpp
--- a/main.cpp	Wed Jan 19 23:53:19 2011 +0000
+++ b/main.cpp	Tue Mar 14 19:36:33 2017 +0000
@@ -1,75 +1,365 @@
 #include "mbed.h"
+#include "MMA8451Q.h"
 #include "nRF24L01P.h"
-
-Serial pc(USBTX, USBRX); // tx, rx
-
-nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10);    // mosi, miso, sck, csn, ce, irq
+#include <string>
 
-DigitalOut myled1(LED1);
-DigitalOut myled2(LED2);
-
-int main() {
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+#define TRANSFER_SIZE   1
 
-// The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's
-//  "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019)
-//  only handles 4 byte transfers in the ATMega code.
-#define TRANSFER_SIZE   4
+nRF24L01P my_nrf24l01p(PTD2, PTD3, PTC5, PTA4, PTC8, PTA12);    // mosi, miso, sck, csn, ce, irq
+DigitalOut tx(PTD5);
+DigitalOut rx(PTA13);
+DigitalIn press(PTB0);
+
 
-    char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
-    int txDataCnt = 0;
-    int rxDataCnt = 0;
-
-    my_nrf24l01p.powerUp();
+int funcx(float y);  //Function to dtermine angle
+string funcp(int, char);
+string funcp(int p, char c);
+Serial pc(USBTX, USBRX);
 
-    // Display the (default) setup of the nRF24L01+ chip
-    pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency() );
-    pc.printf( "nRF24L01+ Output power : %d dBm\r\n",  my_nrf24l01p.getRfOutputPower() );
-    pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
-    pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
-    pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );
+float Y;
+int x;
+string z;
+float p;
+
 
-    pc.printf( "Type keys to test transfers:\r\n  (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE );
-
+int main(){
+    MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
+    char rxData[TRANSFER_SIZE];
+    int rxDataCnt = 0;
+    my_nrf24l01p.powerUp();
     my_nrf24l01p.setTransferSize( TRANSFER_SIZE );
-
     my_nrf24l01p.setReceiveMode();
     my_nrf24l01p.enable();
-
-    while (1) {
-
-        // If we've received anything over the host serial link...
-        if ( pc.readable() ) {
-
-            // ...add it to the transmit buffer
-            txData[txDataCnt++] = pc.getc();
+    pc.printf("receiver\n");
 
-            // If the transmit buffer is full
-            if ( txDataCnt >= sizeof( txData ) ) {
+    
+    while (1){
+        p = press.read();
+        Y = abs(acc.getAccY()); //Get gyroscope readings
+        x =funcx(Y); //Call function to determine angle based on gyroscoe readings
+        
+        if (p && my_nrf24l01p.readable()){//transmitter not sending signal when open string.
+        //if (my_nrf24l01p.readable()){
+            rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) );
+            for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ){
+                //pc.putc( rxData[i] );
+                z = funcp(x, rxData[i]);
+                pc.printf("%s\n", z);
+            }
+            rx = !rx;
+        }
+        
+        //z=funcp(x,rxData[i]); what is this?????????????????????????????????????????????????????????????????????
+        
+    }
+}
 
-                // Send the transmitbuffer via the nRF24L01+
-                my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
-
-                txDataCnt = 0;
-            }
+//Function used to determine the angle for note 
+int funcx(float y){
+    int a;
+    if (y < 0.25000)       
+        {
+            a=1;
+        }
+else if (y > 0.25001 && y < 0.5000)
+        {
+            a=2;
+        } 
+else if (y > 0.50001 && y < 0.7500)
+        {
+            a=3;
+        }
+else
+        {
+            a=4;
+        }
+        //pc.printf("%i     ",a);
+        return a; 
+}
 
-            // Toggle LED1 (to help debug Host -> nRF24L01+ communication)
-            myled1 = !myled1;
+//Final function used to dtermine what string to send to the phone//
+string funcp(int p, char c){ 
+    string str; // Final string output 
+    
+    if(p == 1)
+    {
+        if(c == 'r')
+        {
+            str = "G string D flat"; 
+            //return str;
+        }
+        if(c == 'e')
+        {
+            str = "G string C flat"; 
+            //return str;
+        }
+        if(c == 'w')
+        {
+            str = "G string B flat"; 
+            //return str;
+        }
+        if(c == 'q')
+        {
+            str = "G string A flat"; 
+            //return str;
+        }
+        if(c == 'f')
+        {
+            str = "G string D"; 
+            //return str;
+        }
+        if(c == 'd')
+        {
+            str = "G string C"; 
+            //return str;
+        }
+        if(c == 's')
+        {
+            str = "G string B"; 
+            //return str;
+        }
+        if(c == 'a')
+        {
+            str = "G string A"; 
+            //return str;
+        }
+        if(c == 'v')
+        {
+            str = "G string D sharp"; 
+            //return str;
+        }
+        if(c == 'c')
+        {
+            str = "G string C sharp"; 
+            //return str;
+        }
+        if(c == 'x')
+        {
+            str = "G string B sharp"; 
+            //return str;
+        }
+        if(c == 'z')
+        {
+            str = "G string A sharp"; 
+            //return str;
+        } 
+        if(c == '0')
+        {
+            str = "Open G string";
+            return str; 
+        }
+          
+    }
+    if(p == 2)
+    {
+        str = "Open D";
+        if(c == 'r')
+        {
+            str = "D string A flat"; 
+            //return str;
+        }
+        if(c == 'e')
+        {
+            str = "D string G flat"; 
+            //return str;
+        }
+        if(c == 'w')
+        {
+            str = "D string F flat"; 
+            //return str;
+        }
+        if(c == 'q')
+        {
+            str = "D string E flat"; 
+            //return str;
+        }
+        if(c == 'f')
+        {
+            str = "D string A"; 
+            //return str;
         }
-
-        // If we've received anything in the nRF24L01+...
-        if ( my_nrf24l01p.readable() ) {
-
-            // ...read the data into the receive buffer
-            rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) );
-
-            // Display the receive buffer contents via the host serial link
-            for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) {
-
-                pc.putc( rxData[i] );
-            }
-
-            // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
-            myled2 = !myled2;
+        if(c == 'd')
+        {
+            str = "D string G"; 
+            //return str;
+        }
+        if(c == 's')
+        {
+            str = "D string F"; 
+            //return str;
+        }
+        if(c == 'a')
+        {
+            str = "D string E"; 
+            //return str;
+        }
+        if(c == 'v')
+        {
+            str = "D string A sharp"; 
+            //return str;
+        }
+        if(c == 'c')
+        {
+            str = "D string G sharp"; 
+            //return str;
+        }
+        if(c == 'x')
+        {
+            str = "D string F sharp"; 
+            //return str;
+        }
+        if(c == 'z')
+        {
+            str = "D string E sharp"; 
+            //return str;
+        }    
+        if(c == '0')
+        {
+            str = "Open D string";
+            return str; 
+        } 
+    }
+    if(p == 3)
+    {
+        str = "Open A";
+        if(c == 'r')
+        {
+            str = "A string E flat"; 
+            //return str;
+        }
+        if(c == 'e')
+        {
+            str = "A string D flat"; 
+            //return str;
+        }
+        if(c == 'w')
+        {
+            str = "A string C flat"; 
+            //return str;
+        }
+        if(c == 'q')
+        {
+            str = "A string B flat"; 
+            //return str;
+        }
+        if(c == 'f')
+        {
+            str = "A string E"; 
+            //return str;
+        }
+        if(c == 'd')
+        {
+            str = "A string D"; 
+            //return str;
+        }
+        if(c == 's')
+        {
+            str = "A string C"; 
+            //return str;
+        }
+        if(c == 'a')
+        {
+            str = "A string B"; 
+            //return str;
+        }
+        if(c == 'v')
+        {
+            str = "A string E sharp"; 
+            //return str;
+        }
+        if(c == 'c')
+        {
+            str = "A string D sharp"; 
+            //return str;
+        }
+        if(c == 'x')
+        {
+            str = "A string C sharp"; 
+            //return str;
+        }
+        if(c == 'z')
+        {
+            str = "A string B sharp"; 
+            //return str;
+        }    
+        if(c == '0')
+        {
+            str = "Open A string";
+            return str; 
         }
     }
-}
+    if(p == 4)
+    {
+        str = "Open E";
+        if(c == 'r')
+        {
+            str = "E string B flat"; 
+            //return str;
+        }
+        if(c == 'e')
+        {
+            str = "E string A flat"; 
+            //return str;
+        }
+        if(c == 'w')
+        {
+            str = "E string G flat"; 
+            //return str;
+        }
+        if(c == 'q')
+        {
+            str = "E string F flat"; 
+            //return str;
+        }
+        if(c == 'f')
+        {
+            str = "E string B"; 
+            //return str;
+        }
+        if(c == 'd')
+        {
+            str = "E string A"; 
+            //return str;
+        }
+        if(c == 's')
+        {
+            str = "E string G"; 
+            //return str;
+        }
+        if(c == 'a')
+        {
+            str = "E string F"; 
+            //return str;
+        }
+        if(c == 'v')
+        {
+            str = "E string B sharp"; 
+            //return str;
+        }
+        if(c == 'c')
+        {
+            str = "E string A sharp"; 
+            //return str;
+        }
+        if(c == 'x')
+        {
+            str = "E string G sharp"; 
+            //return str;
+        }
+        if(c == 'z')
+        {
+            str = "E string F sharp"; 
+            //return str;
+        }   
+        if(c == '0')
+        {
+            str = "Open E string";
+            return str; 
+        }  
+    }
+    
+    
+    
+    return str;
+}
\ No newline at end of file
diff -r 5be2682710c6 -r 020a3715aac4 mbed.bld
--- a/mbed.bld	Wed Jan 19 23:53:19 2011 +0000
+++ b/mbed.bld	Tue Mar 14 19:36:33 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e
+http://mbed.org/users/mbed_official/code/mbed/builds/e1686b8d5b90
\ No newline at end of file