From 8600cbd3e0616869468a7ad7d3a8e779f4a7724b Mon Sep 17 00:00:00 2001 From: Bill Verplank Date: Tue, 29 Jan 2013 12:09:22 +0100 Subject: [PATCH] Bill's Music mess --- .../Center_with_2_oscillators.ino | 19 ++++++++----------- software/lib/MMM/Music.cpp | 2 +- software/lib/MMM/Music.h | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/software/apps/Motion/Center_with_2_oscillators/Center_with_2_oscillators.ino b/software/apps/Motion/Center_with_2_oscillators/Center_with_2_oscillators.ino index 27aa14e..c85b09b 100644 --- a/software/apps/Motion/Center_with_2_oscillators/Center_with_2_oscillators.ino +++ b/software/apps/Motion/Center_with_2_oscillators/Center_with_2_oscillators.ino @@ -1,9 +1,11 @@ -//Center +//Center two motors control two frequencies. (jb&bv 25Jan13) //uses a variable force (pwm duty) //If it feels like a mountain - pushing away from center, then -//reverse the motor leads +//reverse the motor leads or the sign of forceA or forceB //or for a quick fix in the code: change if(f < 0) to if (f > 0) +// notes to me (bv) + #include "Motor.h" #include "Music.h" @@ -16,8 +18,8 @@ int kB = 2; // spring constant void setup() { MotorA.init(); - Music.init(); - Music.setWaveform(0); // only works with 8bit waveforms + Music.init(); // 12-bit sine default (see .cpp file) + //Music.setWaveform(0); // only works with 8bit waveforms } void loop() @@ -29,16 +31,11 @@ void loop() Music.setFrequency1(posA); Music.setFrequency2(posB); - forceA = - kA * (512 - posA); + forceA = - kA * (512 - posA); // check wiring??? forceB = kB * (512 - posB); - //duty = abs(force); - //duty = min(512, duty); - MotorA.torque(forceA); + MotorA.torque(forceA); // forceA [-512 to +511] ??? MotorB.torque(forceB); - - //if(force < 0) MotorA.direction(FORWARD); - //else MotorA.direction(BACKWARD); } diff --git a/software/lib/MMM/Music.cpp b/software/lib/MMM/Music.cpp index c40d0b7..27d96bb 100644 --- a/software/lib/MMM/Music.cpp +++ b/software/lib/MMM/Music.cpp @@ -360,7 +360,7 @@ void MMusic::setGain3(uint16_t value) float MMusic::getGainFloat() { - return float(gain); + return float(gain)/65535.0; } diff --git a/software/lib/MMM/Music.h b/software/lib/MMM/Music.h index c4515d9..21f13b1 100644 --- a/software/lib/MMM/Music.h +++ b/software/lib/MMM/Music.h @@ -31,7 +31,7 @@ // SHOULD BE 1, 2 or 3 // //////////////////////////////////// -#define NUM_OSCILLATORS 2 +#define NUM_OSCILLATORS 3 //edited BV 29Jan13. // current sample rate is 15625 as defined in the init() section