Goldsmiths
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
//"Pulse" - small duration positive then negative force
|
||||
// parameters: F1, T1, D1, F2, T2, D2
|
||||
|
||||
#define BIT_DEPTH 12
|
||||
|
||||
#include <Motor.h>
|
||||
#include <Music.h>
|
||||
|
||||
void setup(){
|
||||
MotorA.init();
|
||||
Music.init();
|
||||
|
||||
Music.setWaveform(SINE);
|
||||
Music.enableEnvelope();
|
||||
Music.setAttack(10);
|
||||
Music.setDecay(10);
|
||||
Music.setRelease(10);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
MotorA.torque(200);
|
||||
Music.noteOn(map(analogRead(A3),0,1023,30,60));
|
||||
delay (20);
|
||||
Music.noteOff();MotorA.torque(0);
|
||||
delay (150);
|
||||
MotorA.torque(-200);
|
||||
Music.noteOn(map(analogRead(A3),0,1023,35,65));
|
||||
delay (40);
|
||||
Music.noteOff();MotorA.torque(0);
|
||||
MotorA.torque(0);
|
||||
delay (750);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Center - both motors A and B
|
||||
// feels like "Double Toggle"!
|
||||
|
||||
#include <Motor.h>
|
||||
|
||||
int duty, count, fout;
|
||||
int xA, xB, foutA, foutB;
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
MotorA.init();
|
||||
MotorB.init();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
xA = analogRead(A0);
|
||||
xB = analogRead(A3);
|
||||
foutA = 6*(xB-512); // this will peak at x=1024/6
|
||||
MotorA.torque(foutA); // 1/4 or 1/2 ?
|
||||
|
||||
foutB = 6*(xA-512); // this will peak at x=1024/6
|
||||
MotorB.torque(foutB); // 1/4 or 1/2 ?
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// CenterAB - both motors
|
||||
// xA->Freqequency1, xB->Frequency2
|
||||
//CenterA at xB, CenterB at xA
|
||||
//feels like "Slave"
|
||||
|
||||
#include <Motor.h>
|
||||
#include <Music.h>
|
||||
#define BIT_DEPTH 8
|
||||
#define NUM_OSCILLATORS 2
|
||||
|
||||
int duty, count, fout;
|
||||
int xA, xB, foutA, foutB;
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
MotorA.init();
|
||||
MotorB.init();
|
||||
Music.init();
|
||||
Music.setWaveform1(0);//8bit default?
|
||||
Music.setWaveform2(0);
|
||||
Music.setGain1(1.0f);
|
||||
Music.setGain2(1.0f);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
xA = analogRead(A0);
|
||||
Music.setFrequency1(map (xA, 0, 1023, 40, 2000));
|
||||
|
||||
xB = analogRead(A3);
|
||||
Music.setFrequency2(map (xB, 0, 1023, 40, 2000));
|
||||
|
||||
foutA = -6*(xA-xB); // this will peak at x=1024/6
|
||||
MotorA.torque(foutA); // 1/4 or 1/2 ?
|
||||
|
||||
foutB = -6*(xB-xA); // this will peak at x=1024/6
|
||||
MotorB.torque(foutB); // 1/4 or 1/2 ?
|
||||
|
||||
Music.setGain(float(abs(xA-xB))/1024.0f);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Theremin
|
||||
// A: pitch, B: volume
|
||||
|
||||
#include <Music.h>
|
||||
int xA, xB; //10bit A/D gives 0-1023
|
||||
float p; //midi note number 0-127
|
||||
double frequency, volume;
|
||||
byte c; //print every 256 cycles
|
||||
|
||||
void setup(){
|
||||
Music.init();
|
||||
Serial.begin(9600);
|
||||
}
|
||||
void loop(){
|
||||
xA = analogRead(A3); // A position
|
||||
p = float(xA)/8; //pitch (midi)
|
||||
|
||||
p = 80.*(p/128.)+20.;
|
||||
// p = map(p, 0,127,20,100);
|
||||
//linear mapping of p
|
||||
//The map() function uses integer math so will
|
||||
//not generate fractions, when the math might
|
||||
//indicate that it should do so. Fractional
|
||||
//remainders are truncated, and are not rounded
|
||||
//or averaged.
|
||||
//
|
||||
frequency = pow(2,((p-69.)/12.))*440; //midi 69 -> 440hz
|
||||
Music.setFrequency(frequency);
|
||||
|
||||
xB = analogRead(A0);
|
||||
volume = -float(xB)/256.; // B position
|
||||
volume = pow(10,volume);
|
||||
Music.setGain(volume);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
//Pluck: one pluck at x=512
|
||||
|
||||
int x, fout, count;
|
||||
float f;
|
||||
float w = 50; //width of pluck
|
||||
float h = 500; //height of pluck
|
||||
float slope = h/w;
|
||||
boolean forward = true;
|
||||
|
||||
#include <Motor.h>
|
||||
|
||||
void setup(){
|
||||
MotorA.init();
|
||||
MotorB.init();
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
x = analogRead(A0) - 512;
|
||||
if (forward){
|
||||
if (x <= - w/2) f = 0;
|
||||
if (x > -w/2 && x< w/2) f = - slope*(x + w/2);
|
||||
if (x > w/2){
|
||||
f = 0;
|
||||
forward = false;
|
||||
Serial.println("pluck forward");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x > w/2) f = 0;
|
||||
if (x < w/2 && x > -w/2) f = - slope*(x - w/2);
|
||||
if (x < -w/2){
|
||||
f = 0;
|
||||
forward = true;
|
||||
Serial.println("pluck back");
|
||||
}
|
||||
}
|
||||
fout = int(f);
|
||||
MotorA.torque(fout);
|
||||
|
||||
if(count++>=0){
|
||||
count=-1000; // wait 1000 loops before print
|
||||
Serial.print(x,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.println(fout,DEC);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
//Plucks - four bumps / three notes (400,500,600hz)
|
||||
#define NUM_OSCILLATORS 3
|
||||
#include <Music.h>
|
||||
#include <Motor.h>
|
||||
|
||||
int x, xold, xt, F; // input position x, output force F
|
||||
int K = 10; // slope constant
|
||||
byte count; //for print count-down
|
||||
|
||||
void setup(){
|
||||
Music.init();
|
||||
Music.setFrequency1(200);
|
||||
Music.setFrequency2(250);
|
||||
Music.setFrequency3(300);
|
||||
|
||||
MotorA.init();
|
||||
|
||||
Serial.begin(9600);
|
||||
x = analogRead(A0); // initialize x
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
xold = x;
|
||||
x = analogRead(A0);
|
||||
|
||||
if (((xold <= 125) && (x > 125)) || ((xold >= 125) && (x < 125))){
|
||||
Music.setGain1(1.0f);
|
||||
}
|
||||
if (((xold <= 375) && (x > 375)) || ((xold >= 375) && (x < 375))){
|
||||
Music.setGain2(1.0f);
|
||||
}
|
||||
if (((xold <= 625) && (x > 625)) || ((xold >= 625) && (x < 625))){
|
||||
Music.setGain3(1.0f);
|
||||
}
|
||||
if (((xold <= 875) && (x > 875)) || ((xold >= 875) && (x < 875))){
|
||||
Music.setGain1(1.0f);
|
||||
}
|
||||
else{
|
||||
Music.setGain1(0.995f*Music.getGain1());
|
||||
Music.setGain2(0.995f*Music.getGain2());
|
||||
Music.setGain3(0.995f*Music.getGain3());
|
||||
}
|
||||
|
||||
|
||||
|
||||
xt = x % 250; //same force for each 250 ranage
|
||||
F = 0;
|
||||
if (xt > 60) F = - K * (xt - 60);
|
||||
if (xt > 80) F = - K * (100 - xt);
|
||||
if (xt > 120) F = K * (140 - xt);
|
||||
if (xt > 140) F = 0;
|
||||
MotorA.torque(F);
|
||||
|
||||
|
||||
// print every 256 cycles
|
||||
if(count++==0){
|
||||
Serial.print(x);
|
||||
Serial.print(" ");
|
||||
Serial.print(xt);
|
||||
Serial.print(" ");
|
||||
Serial.println(F);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
This sketch runs with Processing sketch Oscilloscope.pde
|
||||
*/
|
||||
|
||||
#include <Motion.h>
|
||||
#include <Motor.h>
|
||||
#include <Music.h>
|
||||
|
||||
char buf[16] = "";
|
||||
|
||||
char b = 'x';
|
||||
String inputString = "";
|
||||
boolean stringComplete = false;
|
||||
|
||||
float k, m, d;
|
||||
|
||||
int cnt = 0;
|
||||
|
||||
void setup() {
|
||||
|
||||
// MOTOR
|
||||
MotorA.init();
|
||||
|
||||
// MUSIC
|
||||
Music.init();
|
||||
|
||||
// MOTION
|
||||
MotionA.init(INPUTA0);
|
||||
MotionA.k = 5.2f; // spring
|
||||
MotionA.m = 1.0f; // mass
|
||||
MotionA.d = 8.02f; // damping
|
||||
|
||||
// Serial
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
MotionA.update_mass_spring_damper();
|
||||
|
||||
MotorA.torque(MotionA.F);
|
||||
|
||||
int f = map(abs(MotionA.F), 0, 512, 64, 76);
|
||||
Music.noteOn(f);
|
||||
|
||||
cnt++;
|
||||
|
||||
if(cnt == 10) {
|
||||
sprintf(buf, "%d %d %d %d", (int)MotionA.F, (int)MotionA.V, (int)MotionA.X, (int)MotionA.Xin);
|
||||
Serial.println(buf);
|
||||
cnt = 0;
|
||||
}
|
||||
|
||||
if(stringComplete) {
|
||||
if(b == 'k') {
|
||||
MotionA.k = convertToFloat(inputString);
|
||||
} else if(b == 'm') {
|
||||
MotionA.m = convertToFloat(inputString);
|
||||
} else if(b == 'd') {
|
||||
MotionA.d = convertToFloat(inputString);
|
||||
}
|
||||
b = 'x';
|
||||
stringComplete = false;
|
||||
inputString = "";
|
||||
}
|
||||
}
|
||||
|
||||
void serialEvent() {
|
||||
while (Serial.available()) {
|
||||
char inChar = (char)Serial.read();
|
||||
if(inChar == 'k' || inChar == 'm' || inChar == 'd') {
|
||||
b = inChar;
|
||||
} else {
|
||||
if (inChar == ';') {
|
||||
stringComplete = true;
|
||||
} else
|
||||
inputString += inChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float convertToFloat(String str) {
|
||||
char buf[16] = "";
|
||||
str.toCharArray(buf, str.length() + 1);
|
||||
return atof(buf);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//FM synthes of a sort
|
||||
//hang on! (it's unstable and wants to limit cycle)
|
||||
|
||||
#include <Music.h>
|
||||
#define BIT_DEPTH 8 // gives us 16 Waveforms
|
||||
|
||||
#include <Motor.h>
|
||||
|
||||
byte cnt;
|
||||
float xf, vf; //
|
||||
float k = 10.0; // increase FM frequency
|
||||
float b = 0.40; // increase
|
||||
float Tf = .030 ; //integration time
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
Music.init();
|
||||
Music.setWaveform(0);
|
||||
Music.setGain(1.0f);
|
||||
MotorA.init();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
xf += vf * Tf;
|
||||
vf += (k * (analogRead(A0) - xf) - b*vf) * Tf;
|
||||
Music.setFrequency(100+vf);
|
||||
Music.setGain(.001*abs(vf));
|
||||
MotorA.torque(-500+xf);
|
||||
//if(cnt++==0)Serial.println(.001*abs(vf));
|
||||
}
|
||||
Reference in New Issue
Block a user