Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: TextLCD XBeeLib mbed-rtos mbed
Fork of Coordinateur by
Revision 6:59b0b6c1b5bb, committed 2016-04-06
- Comitter:
- vinbel93
- Date:
- Wed Apr 06 20:15:52 2016 +0000
- Parent:
- 5:08245a3e93a8
- Child:
- 7:bd9bc9fa66c7
- Commit message:
- gp2d12
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Apr 06 16:12:53 2016 +0000
+++ b/main.cpp Wed Apr 06 20:15:52 2016 +0000
@@ -11,7 +11,7 @@
AnalogIn GP2D12(p16);
//wave_player player(&DACout);
Serial pc(USBTX, USBRX);
-int octaveMult=1;
+float octaveMult=0.5;
osThreadId threadIDC5;
osThreadId threadIDG5;
@@ -30,11 +30,33 @@
// 466.16 la#
const float DO =261.63;
-const float RE =261.63;
-const float MI =261.63;
-const float FA_SHARP =261.63;
-const float SOL_SHARP =261.63;
-const float LA_SHARP =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;
+
+uint8_t GP2D12_value = 0;
+
+float dutyCycle = 0.0002;
+int lastCapt=-1;
+
+static float findPeriod(float frequency, float vibrato){
+ 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));
+ }
+ }
+
+ pc.printf("freq = %f, vib = %f, freqF = %f\n\r ", frequency, vibrato, freq);
+
+ return 1.0/freq;
+}
/** Callback function, invoked at packet reception */
static void receive_cb(const RemoteXBeeZB& remote, bool broadcast, const uint8_t *const data, uint16_t len)
@@ -53,6 +75,23 @@
capt_5 = (data[0] & 0b00001000);
capt_6 = (data[0] & 0b00000100);
+ GP2D12_value = data[1];
+
+ pc.printf("GP2D12(v1) = %x\r\n",GP2D12_value);
+
+ if(GP2D12_value < 0x50){
+ GP2D12_value = 0;
+ }else {
+ GP2D12_value -= 0x50;
+ }
+
+ pc.printf("GP2D12(v2) = %x\r\n",GP2D12_value);
+ float pourcentageGP2D12 = float(GP2D12_value) / float(0x70);
+
+ if(pourcentageGP2D12 > 1){
+ pourcentageGP2D12 = 1;
+ }
+ /*
pc.printf("\r\n%i ", capt_1);
pc.printf("%i ", capt_2);
pc.printf("%i ", capt_3);
@@ -60,28 +99,40 @@
pc.printf("%i ", capt_5);
pc.printf("%i ", capt_6);
- pc.printf("\r\n");
+ pc.printf("\r\n");*/
- pc.printf("%f\r\n",GP2D12.read());
- speaker=0.50f;
+ pc.printf("GP2D12(v3) = %x\r\n",GP2D12_value);
if(capt_1){
- //speaker=0.50f;
- speaker.period(1.0/(DO * octaveMult));
+ speaker.period(findPeriod(DO, pourcentageGP2D12));
+
+ speaker=dutyCycle;
+ lastCapt = 1;
} else if(capt_2) {
- //speaker=0.50f;
- speaker.period(1.0/(RE * octaveMult));
+ speaker.period(findPeriod(RE, pourcentageGP2D12));
+
+ speaker=dutyCycle;
+ lastCapt = 2;
} else if(capt_3) {
- //speaker=0.50f;
- speaker.period(1.0/(MI * octaveMult));
+ speaker.period(findPeriod(MI, pourcentageGP2D12));
+
+ speaker=dutyCycle;
+ lastCapt = 3;
+ pc.printf("mi \r\n");
} else if(capt_4) {
- //speaker=0.50f;
- speaker.period(1.0/(FA_SHARP * octaveMult));
+ speaker.period(findPeriod(FA_SHARP, pourcentageGP2D12));
+
+ speaker=dutyCycle;
+ lastCapt = 4;
} else if(capt_5) {
- //speaker=0.50f;
- speaker.period(1.0/(SOL_SHARP * octaveMult));
+ speaker.period(findPeriod(SOL_SHARP, pourcentageGP2D12));
+
+ speaker=dutyCycle;
+ lastCapt = 5;
} else if(capt_6) {
- //speaker=0.50f;
- speaker.period(1.0/(LA_SHARP * octaveMult));
+ speaker.period(findPeriod(LA_SHARP, pourcentageGP2D12));
+
+ speaker=dutyCycle;
+ lastCapt = 6;
} else {
speaker=0.0f;
}
@@ -134,7 +185,7 @@
}
*/
int main()
-{
+{
XBeeZB xbee = XBeeZB(p13, p14, p8, NC, NC, 9600);
/* Register callbacks */
