Changes to Music.h and Music.cpp

This commit is contained in:
Jakob Bak
2013-01-30 18:45:25 +01:00
parent 37f714e3d3
commit 8b24803aa2
4 changed files with 840 additions and 788 deletions
@@ -1,25 +1,30 @@
//Center two motors control two frequencies. (jb&bv 25Jan13)
//Center
//uses a variable force (pwm duty)
//If it feels like a mountain - pushing away from center, then
//reverse the motor leads or the sign of forceA or forceB
//reverse the motor leads
//or for a quick fix in the code: change if(f < 0) to if (f > 0)
// notes to me (bv)
//#define NUM_OSCILLATORS 3
//#include "config.h"
#include <Motor.h>
#include <Music.h>
#include <Midi.h>
#include "Motor.h"
#include "Music.h"
int posA, posB; // position from analogRead
int forceA, forceB; // computed from pos and k
int kA = 2; // spring constant
int kB = 2; // spring constant
int kA = -5; // spring constant
int kB = 1; // spring constant
//int duty; // pwm duty for Timer1 (range 0 - 1023) 10-bit resolution
void setup()
{
MotorA.init();
Music.init(); // 12-bit sine default (see .cpp file)
//Music.setWaveform(0); // only works with 8bit waveforms
Music.init();
Music.setWaveform(1); // only works with 8bit waveforms
//Music.setGain2(0);
//Music.setGain3(0);
Midi.init();
}
void loop()
@@ -30,12 +35,18 @@ void loop()
Music.setFrequency1(posA);
Music.setFrequency2(posB);
//Music.setDetune((posB/8)/5120.0);
forceA = - kA * (512 - posA); // check wiring???
forceA = kA * (512 - posA);
forceB = kB * (512 - posB);
//duty = abs(force);
//duty = min(512, duty);
MotorA.torque(forceA); // forceA [-512 to +511] ???
MotorA.torque(forceA);
MotorB.torque(forceB);
Midi.checkMidi();
}