Projet S5 Info - Beginner

Dependencies:   TextLCD XBeeLib mbed-rtos mbed

Fork of Coordinateur-Advanced by Vincent Belanger

Files at this revision

API Documentation at this revision

Comitter:
vinbel93
Date:
Thu Apr 14 15:04:29 2016 +0000
Parent:
9:912506053afd
Commit message:
Final Beginner Version 3

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 912506053afd -r 3e598dcf9e59 main.cpp
--- a/main.cpp	Thu Apr 14 14:47:26 2016 +0000
+++ b/main.cpp	Thu Apr 14 15:04:29 2016 +0000
@@ -21,16 +21,13 @@
 bool capt_4;
 bool capt_5;
 bool capt_6;
-uint8_t GP2D12_value = 0;
 
 const float DO = 261.63;
 const float RE = 293.66;
 const float MI = 329.63;
-const float FA_SHARP = 369.99;
-const float SOL_SHARP = 415.30;
-const float LA_SHARP = 466.16;
-
-const float DEMI_TON = 0.05946;
+const float FA = 349.23;
+const float SOL = 392.00;
+const float LA = 440.00;
 
 float dutyCycle = 0.0002;
 float octaveMult = 2.0;
@@ -50,17 +47,9 @@
 int menuCount = 0;
 int itemCount = 0;
 
-static float findPeriod(float frequency, float vibrato)
+static float findPeriod(float frequency)
 {
     float freq = frequency * octaveMult;
-    if (vibrato != 0) {
-        if(vibrato < 0.5) {
-            freq = freq + (freq *  ( (0.5 - vibrato) * 2 * DEMI_TON));
-        } else {
-            freq = freq - (freq *  ( (vibrato - 0.5) * 2 * DEMI_TON));
-        }
-    }
-
     return 1.0/freq;
 }
 
@@ -90,52 +79,55 @@
     capt_5 = (data[0] & 0b00001000);
     capt_6 = (data[0] & 0b00000100);
 
-    GP2D12_value = data[1];
-
-    if(GP2D12_value < 0x50) {
-        GP2D12_value = 0;
-    } else {
-        GP2D12_value -= 0x50;
-    }
-
-    float pourcentageGP2D12 = float(GP2D12_value) / float(0x70);
-
-    if(pourcentageGP2D12 > 1) {
-        pourcentageGP2D12 = 1;
-    }
-
     if(!capt_1) {
-        speaker.period(findPeriod(DO, pourcentageGP2D12));
-
+        if (lastCapt != 1) {
+            speaker.period(findPeriod(DO));
+        }
+        
         speaker = dutyCycle;
         lastCapt = 1;
     } else if(!capt_2) {
-        speaker.period(findPeriod(RE, pourcentageGP2D12));
+        if (lastCapt != 2) {
+            speaker.period(findPeriod(RE));
+        }
 
         speaker = dutyCycle;
         lastCapt = 2;
     } else if(!capt_3) {
-        speaker.period(findPeriod(MI, pourcentageGP2D12));
+        if (lastCapt != 3) {
+            speaker.period(findPeriod(MI));
+        }
 
         speaker = dutyCycle;
         lastCapt = 3;
     } else if(!capt_4) {
-        speaker.period(findPeriod(FA_SHARP, pourcentageGP2D12));
+        if (lastCapt != 4) {
+            speaker.period(findPeriod(FA));
+        }
 
         speaker = dutyCycle;
         lastCapt = 4;
     } else if(!capt_5) {
-        speaker.period(findPeriod(SOL_SHARP, pourcentageGP2D12));
+        if (lastCapt != 5) {
+            speaker.period(findPeriod(SOL));
+        }
 
         speaker = dutyCycle;
         lastCapt = 5;
     } else if(!capt_6) {
-        speaker.period(findPeriod(LA_SHARP, pourcentageGP2D12));
+        if (lastCapt != 6) {
+            speaker.period(findPeriod(LA));
+        }
 
         speaker = dutyCycle;
         lastCapt = 6;
     } else {
-        speaker = 0.0f;
+        if (lastCapt != 0)
+        {
+            speaker = 0.0f;
+        }
+        
+        lastCapt = 0;
     }
 }