Final version of project

Dependencies:   FSR LSM9DS1_Library_cal USBMIDI mbed

Fork of LSM9DS1_Demo_wCal by jim hamblen

Files at this revision

API Documentation at this revision

Comitter:
KrissyHam
Date:
Fri Apr 29 13:28:40 2016 +0000
Parent:
3:de36d456f684
Commit message:
Added more comments, cleaned up extraneous lines

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r de36d456f684 -r f0cd8d252c08 main.cpp
--- a/main.cpp	Fri Apr 29 13:23:44 2016 +0000
+++ b/main.cpp	Fri Apr 29 13:28:40 2016 +0000
@@ -7,12 +7,6 @@
 #define PI 3.14159
 #define BUFFERSIZE 6
 
-// Earth's magnetic field varies by location. Add or subtract
-// a declination to get a more accurate heading. Calculate
-// your's here:
-// http://www.ngdc.noaa.gov/geomag-web/#declination
-#define DECLINATION -4.94 // Declination (degrees) in Atlanta,GA.
-
 // FSR
 FSR fsr_kick(p20, 10); // Pin 20 is used as the AnalogIn pin and a 10k resistor is used as a voltage divider
 FSR fsr_hh(p19, 10); // Pin 19 is used as the AnalogIn pin and a 10k resistor is used as a voltage divider
@@ -45,7 +39,6 @@
 float y_accel = 0;
 float y_accel2 = 0;
 
-
 int resetIndex = BUFFERSIZE - 2;
 float average[BUFFERSIZE] = {0};
 int avg_index = 0;
@@ -83,14 +76,12 @@
 float hit_volume = 0;
 float hit_volume2 = 0;
 
-
 enum StateType {FRONT, SIDE, HIT};
 enum StateType2 {FRONT2, SIDE2, HIT2};
 
 StateType state = FRONT;   // Initial state is FRONT
 StateType2 state2 = FRONT2;
 
-
 void show_message(MIDIMessage msg) {
     switch (msg.type()) {
         case MIDIMessage::NoteOnType:
@@ -113,10 +104,11 @@
 
 int main()
 {
-     
     midi.attach(show_message);         // call back for messages received 
     pc.baud(9600);
     pc.printf("Hello world!\n");
+    
+    // Initialize IMUs
     IMU.begin();
     if (!IMU.begin()) {
         pc.printf("Failed to communicate with LSM9DS1 - first.\n");
@@ -129,7 +121,7 @@
     }
     IMU2.calibrate(1);    
     
-    t.start();
+    t.start(); // start timer
     
     while(1) {
         
@@ -157,7 +149,9 @@
         * FSR detection
         */
         
+        // Check if values from FSRs are above a threshold (to detect hit)
         if (fsr_kick.readRaw() > 0.3){
+            // Sound will only play if foot is not on FSR (eliminates continuous noise playing if pedal is held down)
             if (kicked == false){
                 midi.write(MIDIMessage::NoteOn(45, fsr_kick.readRaw() * 127 + 30, 10)); // Play a kick, map the volume and boost the amplitude, channel 10
                 }
@@ -179,7 +173,6 @@
         */
         
         // First IMU
-        
         total -= average[avg_index];
         average[avg_index] = IMU.calcGyro(IMU.gy);
         total += average[avg_index];
@@ -197,11 +190,13 @@
             avg_index2 = 0;
         } else {
             avg_index2++;
-        }        
+        }              
         
         /**
-        * Detect downward hit
+        * Hit detection
         */
+        
+        // Detect downward hit
          if (IMU.calcGyro(IMU.gy) > 35) {
             detectHit = 1; 
         }
@@ -210,11 +205,6 @@
             detectHit2 = 1; 
         }
         
-        
-        /**
-        * Check all conditions for hit
-        */
-        
         // Map gyroscope value ranges to volume ranges
         hit_volume = (runningAvg + 245) * (127) / (490);            
         hit_volume2 = (runningAvg2 + 245) * (127) / (490) + 15;