Bill Examples
M&MStudioBV
This commit is contained in:
parent
a7408c519a
commit
336b2b45ab
@ -0,0 +1,22 @@
|
||||
|
||||
// Click within the image to change
|
||||
// the value of the rectangle
|
||||
|
||||
int value = 20;
|
||||
|
||||
void setup(){
|
||||
size(300,400);
|
||||
stroke(value);
|
||||
background(250);
|
||||
}
|
||||
|
||||
void draw(){
|
||||
value = mouseX;
|
||||
fill(value);
|
||||
stroke(value-100);
|
||||
}
|
||||
|
||||
void mouseReleased() {
|
||||
ellipse(mouseX,mouseY,20,20);
|
||||
}
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
|
||||
int[] altitude = { 10, 20, 30, 40, 50, 40, 30, 20, 10, 0 };
|
||||
int i;
|
||||
int s = 80;
|
||||
|
||||
void setup() {
|
||||
size(800,100);
|
||||
}
|
||||
void draw(){
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,50,799,50);
|
||||
stroke(0);
|
||||
|
||||
for (i = 0; i < 9; i = i+1) {
|
||||
line(s*i,altitude[i],s*(i+1),altitude[i+1]);
|
||||
}
|
||||
|
||||
line(s*9, altitude[9], s*10-1, 50);
|
||||
|
||||
for (i = 0; i < 9; i = i+1) {
|
||||
ellipse(s*(i+1),altitude[i+1], 10, 10);
|
||||
}
|
||||
|
||||
if (mousePressed == true) {
|
||||
int pos = (mouseX+40)/s;
|
||||
altitude[pos]=mouseY;
|
||||
}
|
||||
}
|
||||
|
||||
void mouseReleased() {
|
||||
int pos = mouseX/s;
|
||||
altitude[pos]=mouseY;
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
// two-dimensional array?
|
||||
// i = 1, 8;
|
||||
// int F[], // shown an height
|
||||
// x[i], //
|
||||
|
||||
// constrain x[i]<x[i+1]??
|
||||
|
||||
int F[] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
int x[] = {1,2,3,4,5,6,7,8,9,10,11};
|
||||
int i, ibest;
|
||||
float dist;
|
||||
|
||||
void setup(){
|
||||
noFill();
|
||||
size(800,800);
|
||||
for(i=0;i<11;i=i+1){
|
||||
F[i]=int(random(-100,100));
|
||||
x[i]=80*i;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,100,width,100);
|
||||
line(0,200,width,200);
|
||||
for (i = 1; i < 10; i = i+1){
|
||||
line (i*80,0,i*80,200);
|
||||
}
|
||||
stroke(0);
|
||||
for (i = 0; i < 10;i= i+1){
|
||||
line(x[i],F[i]+100,x[i+1],F[i+1]+100);
|
||||
}
|
||||
|
||||
//test every F,x pair to see who is closest call it ibest;
|
||||
ibest = 1;
|
||||
dist = sq(F[0]+100-mouseY)+sq(x[0]-mouseX);
|
||||
for (i=1;i<10;i=i+1){
|
||||
if(dist > sq(F[i]+100-mouseY)+sq(x[i]-mouseX)){
|
||||
ibest = i;
|
||||
dist = sq(F[i]+100-mouseY)+sq(x[i]-mouseX);
|
||||
}
|
||||
}
|
||||
ellipse(x[ibest],F[ibest]+100,20,20);
|
||||
|
||||
text (Integer.toString(ibest), mouseX+10, mouseY-12);
|
||||
text (Integer.toString(F[ibest]), mouseX+10, mouseY);
|
||||
text (Integer.toString(x[ibest]), mouseX+10, mouseY+12);
|
||||
|
||||
if (mousePressed == true){
|
||||
//now use ibest to move to mouseX, mouseY
|
||||
x[ibest] = min(x[ibest+1],max(x[ibest-1],mouseX));
|
||||
F[ibest] = mouseY-100;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,83 @@
|
||||
// two-dimensional array?
|
||||
// i = 1, 8;
|
||||
// int F[], // shown an height
|
||||
// x[i], //
|
||||
|
||||
// constrain x[i]<x[i+1]??
|
||||
|
||||
int F[] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
int x[] = {1,2,3,4,5,6,7,8,9,10,11};
|
||||
int i, j, ibest;
|
||||
int s = 80;
|
||||
int n = 10;
|
||||
float dist;
|
||||
float FF; // forces interpolated
|
||||
float top; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
|
||||
|
||||
void setup(){
|
||||
noFill();
|
||||
size(800,800);
|
||||
for(i=0;i<11;i=i+1){
|
||||
F[i]=0;
|
||||
x[i]=80*i;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,100,width,100);
|
||||
line(0,200,width,200);
|
||||
for (i = 1; i < 10; i = i+1){
|
||||
line (i*80,0,i*80,200);
|
||||
}
|
||||
stroke(0);
|
||||
for (i = 0; i < 10;i= i+1){
|
||||
line(x[i],F[i]+100,x[i+1],F[i+1]+100);
|
||||
}
|
||||
|
||||
//test every F,x pair to see who is closest call it ibest;
|
||||
ibest = 1;
|
||||
dist = sq(F[0]+100-mouseY)+sq(x[0]-mouseX);
|
||||
for (i=1;i<10;i=i+1){
|
||||
if(dist > sq(F[i]+100-mouseY)+sq(x[i]-mouseX)){
|
||||
ibest = i;
|
||||
dist = sq(F[i]+100-mouseY)+sq(x[i]-mouseX);
|
||||
}
|
||||
}
|
||||
ellipse(x[ibest],F[ibest]+100,20,20);
|
||||
|
||||
text (Integer.toString(ibest), mouseX+10, mouseY-12);
|
||||
text (Integer.toString(F[ibest]), mouseX+10, mouseY);
|
||||
text (Integer.toString(x[ibest]), mouseX+10, mouseY+12);
|
||||
|
||||
if (mousePressed == true){
|
||||
//now use ibest to move to mouseX, mouseY
|
||||
x[ibest] = min(x[ibest+1],max(x[ibest-1],mouseX));
|
||||
F[ibest] = mouseY-100;
|
||||
|
||||
}
|
||||
|
||||
//plot "terrain" assuming 80 point separation of F[]'s
|
||||
pushMatrix();
|
||||
translate(0,height/2);
|
||||
/*for (i = 0; i<n; i = i+1){
|
||||
line(i*s,0,(i+1)*s,0);
|
||||
}*/
|
||||
top = 0;
|
||||
FF = F[0];
|
||||
for (i = 0; i < n; i = i+1) {
|
||||
inc = 0.001*(F[i+1]-F[i]); // increment used for plotting
|
||||
for (j = 0; j < s; j = j+1) {
|
||||
FF = FF + inc;
|
||||
top = top + FF; // j increments of inc = F diff.
|
||||
line(i*s+j,height,i*s+j,top);
|
||||
}
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,96 @@
|
||||
// arrow keys for one-pixel motion
|
||||
// two-dimensional array?
|
||||
// i = 1, 8;
|
||||
// int F[], // shown an height
|
||||
// x[i], //
|
||||
|
||||
// constrain x[i]<x[i+1]??
|
||||
|
||||
int F[] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
int x[] = {1,2,3,4,5,6,7,8,9,10,11};
|
||||
int i, j, ibest;
|
||||
int s = 80;
|
||||
int n = 10;
|
||||
float dist;
|
||||
float FF; // forces interpolated
|
||||
float top; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
|
||||
|
||||
void setup(){
|
||||
noFill();
|
||||
size(800,800);
|
||||
for(i=0;i<11;i=i+1){
|
||||
F[i]=0;
|
||||
x[i]=80*i;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,100,width,100);
|
||||
line(0,200,width,200);
|
||||
for (i = 1; i < 10; i = i+1){
|
||||
line (i*80,0,i*80,200);
|
||||
}
|
||||
stroke(0);
|
||||
for (i = 0; i < 10;i= i+1){
|
||||
line(x[i],F[i]+100,x[i+1],F[i+1]+100);
|
||||
}
|
||||
|
||||
//test every F,x pair to see who is closest call it ibest;
|
||||
ibest = 1;
|
||||
dist = sq(F[0]+100-mouseY)+sq(x[0]-mouseX);
|
||||
for (i=1;i<10;i=i+1){
|
||||
if(dist > sq(F[i]+100-mouseY)+sq(x[i]-mouseX)){
|
||||
ibest = i;
|
||||
dist = sq(F[i]+100-mouseY)+sq(x[i]-mouseX);
|
||||
}
|
||||
}
|
||||
ellipse(x[ibest],F[ibest]+100,20,20);
|
||||
|
||||
text (Integer.toString(ibest), mouseX+10, mouseY-12);
|
||||
text (Integer.toString(F[ibest]), mouseX+10, mouseY);
|
||||
text (Integer.toString(x[ibest]), mouseX+10, mouseY+12);
|
||||
|
||||
if (mousePressed == true){
|
||||
//now use ibest to move to mouseX, mouseY
|
||||
x[ibest] = min(x[ibest+1],max(x[ibest-1],mouseX));
|
||||
F[ibest] = mouseY-100;
|
||||
|
||||
}
|
||||
|
||||
//plot "terrain" assuming 80 point separation of F[]'s
|
||||
pushMatrix();
|
||||
translate(0,height/2);
|
||||
/*for (i = 0; i<n; i = i+1){
|
||||
line(i*s,0,(i+1)*s,0);
|
||||
}*/
|
||||
top = 0;
|
||||
FF = F[0];
|
||||
for (i = 0; i < n; i = i+1) {
|
||||
inc = -0.001*(F[i+1]-F[i]); // increment used for plotting
|
||||
//s = x[i+1] - x[i] + 1; // variable widths!
|
||||
s = x[i+1] - x[i]; // number of increments
|
||||
for (j = 0; j < s; j = j+1) {
|
||||
FF = FF + inc;
|
||||
top = top + FF; // j increments of inc = F diff.
|
||||
line(x[i]+j,height,x[i]+j,top);
|
||||
}
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
if (key == CODED) {
|
||||
if (keyCode == UP) --F[ibest];
|
||||
if (keyCode == DOWN) ++F[ibest];
|
||||
if (keyCode == RIGHT) ++x[ibest];
|
||||
if (keyCode == LEFT) --x[ibest];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,83 @@
|
||||
// two-dimensional array?
|
||||
// i = 1, 8;
|
||||
// int F[], // shown an height
|
||||
// x[i], //
|
||||
|
||||
// constrain x[i]<x[i+1]??
|
||||
|
||||
int F[] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
int x[] = {1,2,3,4,5,6,7,8,9,10,11};
|
||||
int i, j, ibest;
|
||||
int s = 80;
|
||||
int n = 10;
|
||||
float dist;
|
||||
float FF; // forces interpolated
|
||||
float top; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
|
||||
|
||||
void setup(){
|
||||
noFill();
|
||||
size(800,800);
|
||||
for(i=0;i<11;i=i+1){
|
||||
F[i]=0;
|
||||
x[i]=80*i;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,100,width,100);
|
||||
line(0,200,width,200);
|
||||
for (i = 1; i < 10; i = i+1){
|
||||
line (i*80,0,i*80,200);
|
||||
}
|
||||
stroke(0);
|
||||
for (i = 0; i < 10;i= i+1){
|
||||
line(x[i],F[i]+100,x[i+1],F[i+1]+100);
|
||||
}
|
||||
|
||||
//test every F,x pair to see who is closest call it ibest;
|
||||
ibest = 1;
|
||||
dist = sq(F[0]+100-mouseY)+sq(x[0]-mouseX);
|
||||
for (i=1;i<10;i=i+1){
|
||||
if(dist > sq(F[i]+100-mouseY)+sq(x[i]-mouseX)){
|
||||
ibest = i;
|
||||
dist = sq(F[i]+100-mouseY)+sq(x[i]-mouseX);
|
||||
}
|
||||
}
|
||||
ellipse(x[ibest],F[ibest]+100,20,20);
|
||||
|
||||
text (Integer.toString(ibest), mouseX+10, mouseY-12);
|
||||
text (Integer.toString(F[ibest]), mouseX+10, mouseY);
|
||||
text (Integer.toString(x[ibest]), mouseX+10, mouseY+12);
|
||||
|
||||
if (mousePressed == true){
|
||||
//now use ibest to move to mouseX, mouseY
|
||||
x[ibest] = min(x[ibest+1],max(x[ibest-1],mouseX));
|
||||
F[ibest] = mouseY - 100;
|
||||
if (mouseY < 0) F[ibest] = -100;
|
||||
if (mouseY > 200) F[ibest] = 100;
|
||||
}
|
||||
|
||||
//plot "terrain" assuming 80 point separation of F[]'s
|
||||
pushMatrix();
|
||||
translate(0,height/2);
|
||||
|
||||
top = 0;
|
||||
FF = F[0];
|
||||
for (i = 0; i < n; i = i+1) {
|
||||
s = x[i+1]-x[i]+1; // increment used for plotting
|
||||
inc = 0.01*(F[i+1]-F[i])/s;
|
||||
for (j = 0; j < s; j = j+1) {
|
||||
FF = FF + inc;
|
||||
top = top + FF; // j increments of inc = F diff.
|
||||
line(x[i]+j,height,x[i]+j,top);
|
||||
}
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,91 @@
|
||||
// two-dimensional array?
|
||||
// i = 1, 8;
|
||||
// int F[], // shown an height
|
||||
// x[i], //
|
||||
|
||||
// constrain x[i]<x[i+1]??
|
||||
|
||||
int F[] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
int x[] = {1,2,3,4,5,6,7,8,9,10,11};
|
||||
int i, j, ibest;
|
||||
int s = 80;
|
||||
int n = 10;
|
||||
float dist;
|
||||
float FF; // forces interpolated
|
||||
float top; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
|
||||
|
||||
void setup(){
|
||||
noFill();
|
||||
size(800,800);
|
||||
for(i=0;i<11;i=i+1){
|
||||
F[i]=0;
|
||||
x[i]=80*i;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,100,width,100);
|
||||
line(0,200,width,200);
|
||||
for (i = 1; i < 10; i = i+1){
|
||||
line (i*80,0,i*80,200);
|
||||
}
|
||||
stroke(0);
|
||||
for (i = 0; i < 10;i= i+1){
|
||||
line(x[i],F[i]+100,x[i+1],F[i+1]+100);
|
||||
}
|
||||
|
||||
//test every F,x pair to see who is closest call it ibest;
|
||||
ibest = 1;
|
||||
dist = sq(F[0]+100-mouseY)+sq(x[0]-mouseX);
|
||||
for (i=1;i<10;i=i+1){
|
||||
if(dist > sq(F[i]+100-mouseY)+sq(x[i]-mouseX)){
|
||||
ibest = i;
|
||||
dist = sq(F[i]+100-mouseY)+sq(x[i]-mouseX);
|
||||
}
|
||||
}
|
||||
ellipse(x[ibest],F[ibest]+100,20,20);
|
||||
|
||||
text (Integer.toString(ibest), mouseX+10, mouseY-12);
|
||||
text (Integer.toString(F[ibest]), mouseX+10, mouseY);
|
||||
text (Integer.toString(x[ibest]), mouseX+10, mouseY+12);
|
||||
|
||||
if (mousePressed == true){
|
||||
//now use ibest to move to mouseX, mouseY
|
||||
x[ibest] = min(x[ibest+1],max(x[ibest-1],mouseX));
|
||||
F[ibest] = mouseY - 100;
|
||||
if (mouseY < 0) F[ibest] = -100;
|
||||
if (mouseY > 200) F[ibest] = 100;
|
||||
}
|
||||
|
||||
//plot "terrain" assuming 80 point separation of F[]'s
|
||||
pushMatrix();
|
||||
translate(0,height/2);
|
||||
|
||||
top = 0;
|
||||
FF = F[0];
|
||||
for (i = 0; i < n; i = i+1) {
|
||||
s = x[i+1]-x[i]+1; // increment used for plotting
|
||||
inc = 0.01*(F[i+1]-F[i])/s;
|
||||
for (j = 0; j < s; j = j+1) {
|
||||
FF = FF + inc;
|
||||
top = top + FF; // j increments of inc = F diff.
|
||||
line(x[i]+j,height,x[i]+j,top);
|
||||
}
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
if (key == CODED) {
|
||||
if (keyCode == UP) --F[ibest];
|
||||
if (keyCode == DOWN) ++F[ibest];
|
||||
if (keyCode == RIGHT) ++x[ibest];
|
||||
if (keyCode == LEFT) --x[ibest];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
// Profile of forces and terrain
|
||||
|
||||
int n = 10; //number of values of F calculated for each s
|
||||
int s = 80; //number of samples for each n
|
||||
int[] F = new int[11]; //course Force values
|
||||
float[] FF = new float[800]; //fine Forces interpolated
|
||||
int i,j;
|
||||
//int s = 80;
|
||||
//int n = 10;
|
||||
int pos;
|
||||
|
||||
void setup() {
|
||||
size(800,200); // double height to see what interpolation looks like
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,50,n*s-1,50);
|
||||
stroke(0);
|
||||
|
||||
for (i = 0; i <n; i = i+1 ) {
|
||||
line(s*i, F[i], s*(i+1), F[i+1]);
|
||||
}
|
||||
|
||||
// line(s*(n-1), F[n-1], s*n, 0);
|
||||
|
||||
for (i = 0; i <9; i = i+1) {
|
||||
ellipse(s*(i+1),F[i+1], 10, 10);
|
||||
}
|
||||
|
||||
if (mousePressed == true) {
|
||||
pos = (mouseX+s/2)/s;
|
||||
F[pos]=mouseY;
|
||||
}
|
||||
// plot seg ments of curving terrain (interpolating force?)
|
||||
for (i = 0; i <n; i = i+1) {
|
||||
line(i*s,height-F[i],(i+1)*s,height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void mouseReleased(){
|
||||
for (i = 0; i<n; i = i+1){
|
||||
line(i,height,i+s,height-j);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
Ctrl c1, c2, c3;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(640, 360);
|
||||
noStroke();
|
||||
c1 = new Ctrl( 100, 100, 0);
|
||||
c2 = new Ctrl( 200, 120, 100);
|
||||
c3 = new Ctrl( 300, 130, 200);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(250);
|
||||
|
||||
c1.update(mouseX, mouseY);
|
||||
c2.update(mouseX, mouseY);
|
||||
c3.update(mouseX, mouseY);
|
||||
|
||||
c1.display();
|
||||
c2.display();
|
||||
c3.display();
|
||||
|
||||
}
|
||||
|
||||
class Ctrl {
|
||||
int x, y;
|
||||
int offset;
|
||||
|
||||
Ctrl(int tx, int ty, int to) {
|
||||
x = tx;
|
||||
y = ty;
|
||||
offset = to;
|
||||
}
|
||||
|
||||
void update(int mx, int my) {
|
||||
offset = mouseX;
|
||||
}
|
||||
void display() {
|
||||
pushMatrix();
|
||||
translate(x, y);
|
||||
fill (250);
|
||||
rotate(offset);
|
||||
fill (153);
|
||||
ellipse(offset, 0, offset/2, 2*offset);
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
//(Arduino) Profile sends pos to (Processing) ProfileFx
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
Serial.println(analogRead(A0));
|
||||
delay(100);
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
// two-dimensional array?
|
||||
// i = 1, 8;
|
||||
// int F[], // shown an height
|
||||
// x[i], //
|
||||
|
||||
// constrain x[i]<x[i+1]??
|
||||
|
||||
int F[] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
int x[] = {1,2,3,4,5,6,7,8,9,10,11};
|
||||
int i, j, ibest;
|
||||
int s = 80;
|
||||
int n = 10;
|
||||
float dist;
|
||||
float FF; // forces interpolated
|
||||
float top; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
|
||||
|
||||
void setup(){
|
||||
noFill();
|
||||
size(800,800);
|
||||
for(i=0;i<11;i=i+1){
|
||||
F[i]=0;
|
||||
x[i]=80*i;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,100,width,100);
|
||||
line(0,200,width,200);
|
||||
for (i = 1; i < 10; i = i+1){
|
||||
line (i*80,0,i*80,200);
|
||||
}
|
||||
stroke(0);
|
||||
for (i = 0; i < 10;i= i+1){
|
||||
line(x[i],F[i]+100,x[i+1],F[i+1]+100);
|
||||
}
|
||||
|
||||
//test every F,x pair to see who is closest call it ibest;
|
||||
ibest = 1;
|
||||
dist = sq(F[0]+100-mouseY)+sq(x[0]-mouseX);
|
||||
for (i=1;i<10;i=i+1){
|
||||
if(dist > sq(F[i]+100-mouseY)+sq(x[i]-mouseX)){
|
||||
ibest = i;
|
||||
dist = sq(F[i]+100-mouseY)+sq(x[i]-mouseX);
|
||||
}
|
||||
}
|
||||
ellipse(x[ibest],F[ibest]+100,20,20);
|
||||
|
||||
text (Integer.toString(ibest), mouseX+10, mouseY-12);
|
||||
text (Integer.toString(F[ibest]), mouseX+10, mouseY);
|
||||
text (Integer.toString(x[ibest]), mouseX+10, mouseY+12);
|
||||
|
||||
if (mousePressed == true){
|
||||
//now use ibest to move to mouseX, mouseY
|
||||
x[ibest] = min(x[ibest+1],max(x[ibest-1],mouseX));
|
||||
F[ibest] = mouseY - 100;
|
||||
if (mouseY < 0) F[ibest] = -100;
|
||||
if (mouseY > 200) F[ibest] = 100;
|
||||
}
|
||||
|
||||
//plot "terrain" assuming 80 point separation of F[]'s
|
||||
pushMatrix();
|
||||
translate(0,height/2);
|
||||
|
||||
top = 0;
|
||||
FF = F[0];
|
||||
for (i = 0; i < n; i = i+1) {
|
||||
s = x[i+1]-x[i]+1; // increment used for plotting
|
||||
inc = 0.01*(F[i+1]-F[i])/s;
|
||||
for (j = 0; j < s; j = j+1) {
|
||||
FF = FF + inc;
|
||||
top = top + FF; // j increments of inc = F diff.
|
||||
line(x[i]+j,height,x[i]+j,top);
|
||||
}
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
if (key == CODED) {
|
||||
if (keyCode == UP) --F[ibest];
|
||||
if (keyCode == DOWN) ++F[ibest];
|
||||
if (keyCode == RIGHT) ++x[ibest];
|
||||
if (keyCode == LEFT) --x[ibest];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,82 @@
|
||||
// Profile of forces and terrain
|
||||
|
||||
int n = 10; //number of values of F calculated for each s
|
||||
int s = 80; //number of samples for each n
|
||||
int[] F = new int[11]; // Force values [-512 to +511] scaled for plot?
|
||||
float FF; // forces interpolated
|
||||
float top; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
int i,j;
|
||||
int pos;
|
||||
int vt = 50; //vertical translation for force curve
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
size(800,800); // double height to see what interpolation looks like
|
||||
for(i=0;i<n+1;i=i+1){
|
||||
F[i]=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(200);
|
||||
|
||||
pushMatrix();
|
||||
translate(0,vt); // center force plot at vt
|
||||
stroke(150);
|
||||
line(0,0,n*s-1,0); // the zero force line
|
||||
|
||||
stroke(0); // the force segments
|
||||
for (i = 0; i <n; i = i+1 ) {
|
||||
line(s*i, F[i], s*(i+1), F[i+1]);
|
||||
}
|
||||
|
||||
for (i = 0; i <9; i = i+1) {
|
||||
ellipse(s*(i+1),F[i+1], 10, 10);
|
||||
}
|
||||
|
||||
if (mousePressed == true) {
|
||||
pos = (mouseX+s/2)/s;
|
||||
F[pos]=mouseY-vt;
|
||||
}
|
||||
|
||||
popMatrix();
|
||||
pushMatrix();
|
||||
translate(0,height/2);
|
||||
/*for (i = 0; i<n; i = i+1){
|
||||
line(i*s,0,(i+1)*s,0);
|
||||
}*/
|
||||
top = 0;
|
||||
FF = F[0];
|
||||
for (i = 0; i < n; i = i+1) {
|
||||
inc = 0.001*(F[i+1]-F[i]); // increment used for plotting
|
||||
for (j = 0; j < s; j = j+1) {
|
||||
FF = FF + inc;
|
||||
top = top + FF; // j increments of inc = F diff.
|
||||
line(i*s+j,height,i*s+j,top);
|
||||
}
|
||||
}
|
||||
popMatrix();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
void mouseReleased(){
|
||||
}
|
||||
|
||||
// plot seg ments of curving terrain (interpolating force?)
|
||||
top = 50;
|
||||
for (i = 0; i <n; i = i+1) {
|
||||
inc = (F[i+1]-F[i])/s; // increment used for plotting
|
||||
for (j = 0; j < s; j = j+1){
|
||||
top = top + inc*j; // j increments of inc = F diff.
|
||||
line(i*s,height-top,i*s,height);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,82 @@
|
||||
// Profile of forces and terrain
|
||||
|
||||
int n = 10; //number of values of F calculated for each s
|
||||
int s = 80; //number of samples for each n
|
||||
int[] F = new int[11]; // Force values [-512 to +511] scaled for plot?
|
||||
float FF; // forces interpolated
|
||||
float top; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
int i,j;
|
||||
int pos;
|
||||
int vt = 50; //vertical translation for force curve
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
size(800,800); // double height to see what interpolation looks like
|
||||
for(i=0;i<n+1;i=i+1){
|
||||
F[i]=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(200);
|
||||
|
||||
pushMatrix();
|
||||
translate(0,vt); // center force plot at vt
|
||||
stroke(150);
|
||||
line(0,0,n*s-1,0); // the zero force line
|
||||
|
||||
stroke(0); // the force segments
|
||||
for (i = 0; i <n; i = i+1 ) {
|
||||
line(s*i, F[i], s*(i+1), F[i+1]);
|
||||
}
|
||||
|
||||
for (i = 0; i <9; i = i+1) {
|
||||
ellipse(s*(i+1),F[i+1], 10, 10);
|
||||
}
|
||||
|
||||
if (mousePressed == true) {
|
||||
pos = (mouseX+s/2)/s;
|
||||
F[pos]=mouseY-vt;
|
||||
}
|
||||
|
||||
popMatrix();
|
||||
pushMatrix();
|
||||
translate(0,height/2);
|
||||
/*for (i = 0; i<n; i = i+1){
|
||||
line(i*s,0,(i+1)*s,0);
|
||||
}*/
|
||||
top = 0;
|
||||
FF = F[0];
|
||||
for (i = 0; i < n; i = i+1) {
|
||||
inc = 0.001*(F[i+1]-F[i]); // increment used for plotting
|
||||
for (j = 0; j < s; j = j+1) {
|
||||
FF = FF + inc;
|
||||
top = top + FF; // j increments of inc = F diff.
|
||||
line(i*s+j,height,i*s+j,top);
|
||||
}
|
||||
}
|
||||
popMatrix();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
void mouseReleased(){
|
||||
}
|
||||
|
||||
// plot seg ments of curving terrain (interpolating force?)
|
||||
top = 50;
|
||||
for (i = 0; i <n; i = i+1) {
|
||||
inc = (F[i+1]-F[i])/s; // increment used for plotting
|
||||
for (j = 0; j < s; j = j+1){
|
||||
top = top + inc*j; // j increments of inc = F diff.
|
||||
line(i*s,height-top,i*s,height);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
// two-dimensional array?
|
||||
// i = 1, 8;
|
||||
// int F[], // shown an height
|
||||
// x[i], //
|
||||
|
||||
// constrain x[i]<x[i+1]??
|
||||
|
||||
int F[] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
int x[] = {1,2,3,4,5,6,7,8,9,10,11};
|
||||
int i, ibest;
|
||||
float dist;
|
||||
|
||||
void setup(){
|
||||
size(800,800);
|
||||
for(i=0;i<11;i=i+1){
|
||||
F[i]=int(random(200));
|
||||
x[i]=80*i;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(190);
|
||||
for (i = 0; i < 10;i= i+1){
|
||||
line(x[i],F[i],x[i+1],F[i+1]);
|
||||
}
|
||||
|
||||
//if (mousePressed == false){
|
||||
//test every F,x pair to see who is closest call it ibest;
|
||||
ibest = 1;
|
||||
dist = sq(F[0]-mouseY)+sq(x[0]*mouseX);
|
||||
for (i=1;i<10;i=i+1){
|
||||
if(dist > sq(F[i]-mouseY)+sq(x[i]-mouseX)){
|
||||
ibest = i;
|
||||
dist = sq(F[i]-mouseY)+sq(x[i]-mouseX);
|
||||
}
|
||||
}
|
||||
ellipse(x[ibest],F[ibest],20,20);
|
||||
// }
|
||||
|
||||
if (mousePressed == true){
|
||||
//now use ibest to move to mouseX, mouseY
|
||||
F[ibest] = mouseY;
|
||||
x[ibest] = min(x[ibest+1],mouseX);
|
||||
x[ibest] = max(x[ibest-1],mouseX);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
25
software/apps/M&MStudioBV/ABSlaveMusic/ABSlaveMusic.ino
Normal file
25
software/apps/M&MStudioBV/ABSlaveMusic/ABSlaveMusic.ino
Normal file
@ -0,0 +1,25 @@
|
||||
// CenterAB - both motors
|
||||
// CenterA at xB, CenterB at xA?
|
||||
// feels like "Slave"
|
||||
|
||||
#include <Motor.h>
|
||||
#include <Music.h>
|
||||
|
||||
int duty, count, fout;
|
||||
int xA, xB, foutA, foutB;
|
||||
|
||||
void setup(){
|
||||
MotorA.init();
|
||||
MotorB.init();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
xA = analogRead(A0);
|
||||
xB = analogRead(A3);
|
||||
foutA = 6*(xB-xA); // this will peak at x=1024/6
|
||||
MotorA.torque(foutA); // 1/4 or 1/2 ?
|
||||
|
||||
foutB = 6*(xA-xB); // this will peak at x=1024/6
|
||||
MotorB.torque(foutB); // 1/4 or 1/2 ?
|
||||
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
// CenterAB - both motors
|
||||
// Freqequency1 B->Frequency2
|
||||
//CenterA at xB, CenterB at xA?
|
||||
//feels like "Slave"
|
||||
//position on A0, pwm:D9, dir:D8,D7
|
||||
//CenterB
|
||||
//position on A3, pwm:D10, dir:D11,D12
|
||||
|
||||
|
||||
#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
|
||||
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);
|
||||
// print every 1000 cycles
|
||||
if(count++>=0){
|
||||
count=-500;
|
||||
Serial.print(xA,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.print(foutA,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.print(xB,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.println(foutB,DEC);
|
||||
}
|
||||
|
||||
}
|
||||
43
software/apps/M&MStudioBV/ABslave/ABslave.ino
Normal file
43
software/apps/M&MStudioBV/ABslave/ABslave.ino
Normal file
@ -0,0 +1,43 @@
|
||||
// CenterAB - both motors
|
||||
|
||||
//CenterA at xB, CenterB at xA?
|
||||
//feels like "Double Toggle"
|
||||
//position on A0, pwm:D9, dir:D8,D7
|
||||
//CenterB
|
||||
//position on A3, pwm:D10, dir:D11,D12
|
||||
|
||||
|
||||
#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*(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 ?
|
||||
|
||||
// print every 1000 cycles
|
||||
if(count++>=0){
|
||||
count=-500;
|
||||
Serial.print(xA,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.print(foutA,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.print(xB,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.println(foutB,DEC);
|
||||
}
|
||||
|
||||
}
|
||||
74
software/apps/M&MStudioBV/Bumps4/Bumps4.ino
Normal file
74
software/apps/M&MStudioBV/Bumps4/Bumps4.ino
Normal file
@ -0,0 +1,74 @@
|
||||
//plucks - four bumps
|
||||
//three notes (400,500,600hz)
|
||||
//can't get Music.setGain1, etc to work only Music.setGain() starts all of them.
|
||||
|
||||
#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);
|
||||
|
||||
// did xold - x include 125, 375, 625, 875? or x%250 = 125
|
||||
|
||||
if (((xold <= 125) && (x > 125)) || ((xold >= 125) && (x < 125))){
|
||||
Music.setGain1(1.0f);
|
||||
//Music.setFrequency(200);
|
||||
}
|
||||
if (((xold <= 375) && (x > 375)) || ((xold >= 375) && (x < 375))){
|
||||
Music.setGain2(1.0f);
|
||||
//Music.setFrequency(250);
|
||||
}
|
||||
if (((xold <= 625) && (x > 625)) || ((xold >= 625) && (x < 625))){
|
||||
Music.setGain3(1.0f);
|
||||
//Music.setFrequency(300);
|
||||
}
|
||||
if (((xold <= 875) && (x > 875)) || ((xold >= 875) && (x < 875))){
|
||||
Music.setGain1(1.0f);
|
||||
//Music.setFrequency(400);
|
||||
}
|
||||
else{
|
||||
Music.setGain1(0.995f*Music.getGain1Float());
|
||||
Music.setGain2(0.995f*Music.getGain2Float());
|
||||
Music.setGain3(0.995f*Music.getGain3Float());
|
||||
}
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
42
software/apps/M&MStudioBV/CenterABM/CenterABM.ino
Normal file
42
software/apps/M&MStudioBV/CenterABM/CenterABM.ino
Normal file
@ -0,0 +1,42 @@
|
||||
// CenterAB - both motors
|
||||
|
||||
//CenterA
|
||||
//position on A0, pwm:D9, dir:D8,D7
|
||||
//CenterB
|
||||
//position on A3, pwm:D10, dir:D11,D12
|
||||
|
||||
|
||||
#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);
|
||||
foutA = 2*(512 - xA); // this will peak at x=1024/2
|
||||
MotorA.torque(foutA); // 1/4 or 1/2 ?
|
||||
|
||||
xB = analogRead(A3);
|
||||
foutB = (512 - xB); // this will peak at x=1024/6
|
||||
MotorB.torque(foutB); // 1/4 or 1/2 ?
|
||||
|
||||
// print every 1000 cycles
|
||||
if(count++>=0){
|
||||
count=-1000;
|
||||
Serial.print(xA,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.print(foutA,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.print(xB,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.println(foutB,DEC);
|
||||
}
|
||||
|
||||
}
|
||||
43
software/apps/M&MStudioBV/CenterABtoggle/CenterABtoggle.ino
Normal file
43
software/apps/M&MStudioBV/CenterABtoggle/CenterABtoggle.ino
Normal file
@ -0,0 +1,43 @@
|
||||
// CenterAB - both motors
|
||||
|
||||
//CenterA at xB, CenterB at xA?
|
||||
//feels like "Double Toggle"
|
||||
//position on A0, pwm:D9, dir:D8,D7
|
||||
//CenterB
|
||||
//position on A3, pwm:D10, dir:D11,D12
|
||||
|
||||
|
||||
#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 ?
|
||||
|
||||
// print every 1000 cycles
|
||||
if(count++>=0){
|
||||
count=-500;
|
||||
Serial.print(xA,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.print(foutA,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.print(xB,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.println(foutB,DEC);
|
||||
}
|
||||
|
||||
}
|
||||
34
software/apps/M&MStudioBV/FM/CenterFSR_A/CenterFSR_A.ino
Normal file
34
software/apps/M&MStudioBV/FM/CenterFSR_A/CenterFSR_A.ino
Normal file
@ -0,0 +1,34 @@
|
||||
//CenterFSR-A
|
||||
//position on A0, pwm:D9, dir:D8,D7
|
||||
//FSR on A1 and D4
|
||||
|
||||
// BUZZ! (float vs int?)
|
||||
#include "Motor.h"
|
||||
|
||||
int x, duty, fin;
|
||||
float fout;
|
||||
byte count; // used as counter
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
MotorA.init();
|
||||
//for FSR
|
||||
pinMode(A1,INPUT);
|
||||
digitalWrite(A1,HIGH);
|
||||
pinMode(4,OUTPUT);
|
||||
digitalWrite(4,LOW);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
fin = 1024 - analogRead(A1);
|
||||
x = analogRead(A0)-512;
|
||||
fout = - .004*(float(fin)*float(x));
|
||||
MotorA.torque(fout);
|
||||
if(count++ == 0){
|
||||
Serial.print(x,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.print(fin,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.println(fout,DEC);
|
||||
}
|
||||
}
|
||||
31
software/apps/M&MStudioBV/FM/FM.ino
Normal file
31
software/apps/M&MStudioBV/FM/FM.ino
Normal file
@ -0,0 +1,31 @@
|
||||
//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 = 6.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));
|
||||
}
|
||||
63
software/apps/M&MStudioBV/FM/FMGraph/FMGraph.pde
Normal file
63
software/apps/M&MStudioBV/FM/FMGraph/FMGraph.pde
Normal file
@ -0,0 +1,63 @@
|
||||
// Graphing sketch
|
||||
|
||||
|
||||
// This program takes ASCII-encoded strings
|
||||
// from the serial port at 9600 baud and graphs them. It expects values in the
|
||||
// range 0 to 1023, followed by a newline, or newline and carriage return
|
||||
|
||||
// Created 20 Apr 2005
|
||||
// Updated 18 Jan 2008
|
||||
// by Tom Igoe
|
||||
// This example code is in the public domain.
|
||||
|
||||
import processing.serial.*;
|
||||
|
||||
Serial myPort; // The serial port
|
||||
int xPos = 1; // horizontal position of the graph
|
||||
|
||||
void setup () {
|
||||
// set the window size:
|
||||
size(400, 300);
|
||||
|
||||
// List all the available serial ports
|
||||
println(Serial.list());
|
||||
// I know that the first port in the serial list on my mac
|
||||
// is always my Arduino, so I open Serial.list()[0].
|
||||
// Open whatever port is the one you're using.
|
||||
myPort = new Serial(this, Serial.list()[0], 9600);
|
||||
// don't generate a serialEvent() unless you get a newline character:
|
||||
myPort.bufferUntil('\n');
|
||||
// set inital background:
|
||||
background(0);
|
||||
}
|
||||
void draw () {
|
||||
// everything happens in the serialEvent()
|
||||
}
|
||||
|
||||
void serialEvent (Serial myPort) {
|
||||
// get the ASCII string:
|
||||
String inString = myPort.readStringUntil('\n');
|
||||
|
||||
if (inString != null) {
|
||||
// trim off any whitespace:
|
||||
inString = trim(inString);
|
||||
// convert to an int and map to the screen height:
|
||||
float inByte = float(inString);
|
||||
inByte = map(inByte, 0, 1023, 0, height);
|
||||
|
||||
// draw the line:
|
||||
stroke(127,34,255);
|
||||
line(xPos, height, xPos, height - inByte);
|
||||
|
||||
// at the edge of the screen, go back to the beginning:
|
||||
if (xPos >= width) {
|
||||
xPos = 0;
|
||||
background(0);
|
||||
}
|
||||
else {
|
||||
// increment the horizontal position:
|
||||
xPos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
97
software/apps/M&MStudioBV/FSR/Bumps4FSR/Bumps4FSR.ino
Normal file
97
software/apps/M&MStudioBV/FSR/Bumps4FSR/Bumps4FSR.ino
Normal file
@ -0,0 +1,97 @@
|
||||
//plucks - four bumps
|
||||
//three notes (400,500,600hz)
|
||||
//can't get Music.setGain1, etc to work only Music.setGain() starts all of them.
|
||||
//requires FSR attached to A
|
||||
|
||||
#define NUM_OSCILLATORS 3
|
||||
#define BIT_DEPTH 8
|
||||
|
||||
#include <Music.h>
|
||||
#include <Motor.h>
|
||||
|
||||
int x, xold, xt; // input position x, output force F
|
||||
float K = 20; // slope constant
|
||||
byte count; //for print count-down
|
||||
float fin; // scaled to be 0.0 - 1.0
|
||||
float fout; // from FSR
|
||||
|
||||
void setup(){
|
||||
Music.init();
|
||||
Music.setFrequency1(200);
|
||||
Music.setFrequency2(250);
|
||||
Music.setFrequency3(300);
|
||||
|
||||
//FSR-A
|
||||
pinMode(A1,INPUT);
|
||||
digitalWrite(A1,HIGH); //set pull-up
|
||||
pinMode(4,OUTPUT);
|
||||
digitalWrite(4,LOW);
|
||||
//FSR-B
|
||||
pinMode(A4,INPUT);
|
||||
digitalWrite(A4,HIGH); //set pull-up
|
||||
pinMode(5,OUTPUT);
|
||||
digitalWrite(5,LOW);
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
MotorA.init();
|
||||
|
||||
Serial.begin(9600);
|
||||
x = analogRead(A0); // initialize x
|
||||
}
|
||||
|
||||
void loop(){
|
||||
xold = x;
|
||||
x = analogRead(A0);
|
||||
|
||||
// did xold - x include 125, 375, 625, 875? or x%250 = 125
|
||||
|
||||
if (((xold <= 125) && (x > 125)) || ((xold >= 125) && (x < 125))){
|
||||
Music.setGain1(fin*fin);
|
||||
Music.setFrequency1(200);
|
||||
}
|
||||
if (((xold <= 375) && (x > 375)) || ((xold >= 375) && (x < 375))){
|
||||
Music.setGain2(fin*fin);
|
||||
//Music.setFrequency(250);
|
||||
}
|
||||
if (((xold <= 625) && (x > 625)) || ((xold >= 625) && (x < 625))){
|
||||
Music.setGain3(fin*fin);
|
||||
//Music.setFrequency(300);
|
||||
}
|
||||
if (((xold <= 875) && (x > 875)) || ((xold >= 875) && (x < 875))){
|
||||
Music.setGain1(fin*fin);
|
||||
Music.setFrequency1(400);
|
||||
}
|
||||
else{
|
||||
Music.setGain1(0.995f*Music.getGain1());
|
||||
Music.setGain2(0.995f*Music.getGain2());
|
||||
Music.setGain3(0.995f*Music.getGain3());
|
||||
}
|
||||
fin = 1000 - analogRead(A1); // invert and shift
|
||||
fin = max (0, fin); // make sure it's > 0
|
||||
fin = min (1023, fin); // and < 1023
|
||||
fin = fin/1000; // scale 0-1.0
|
||||
fin = fin*fin; //square it for more effect near 1.0.
|
||||
xt = x % 250; //same force for each 250 ranage
|
||||
fout = 0;
|
||||
if (xt > 60) fout = - K * (xt - 60);
|
||||
if (xt > 80) fout = - K * (100 - xt);
|
||||
if (xt > 120) fout = K * (140 - xt);
|
||||
if (xt > 140) fout = 0;
|
||||
fout = fout * fin;
|
||||
MotorA.torque(fout);
|
||||
|
||||
|
||||
// print every 256 cycles
|
||||
if(count++==0){
|
||||
Serial.print(x);
|
||||
Serial.print(" ");
|
||||
Serial.print(xt);
|
||||
Serial.print(" ");
|
||||
Serial.print(fin);
|
||||
Serial.print(" ");
|
||||
Serial.println(fout);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
// FSR A and B
|
||||
// stick-slip
|
||||
|
||||
#include <Motor.h>
|
||||
int xA, finA, foutA; //fout gets too big if fout=fin*x;
|
||||
float x, fin, fout;
|
||||
byte c;
|
||||
|
||||
void setup(){
|
||||
//FSR-A
|
||||
pinMode(A1,INPUT);
|
||||
digitalWrite(A1,HIGH); //set pull-up
|
||||
pinMode(4,OUTPUT);
|
||||
digitalWrite(4,LOW);
|
||||
//FSR-B
|
||||
pinMode(A4,INPUT);
|
||||
digitalWrite(A4,HIGH); //set pull-up
|
||||
pinMode(5,OUTPUT);
|
||||
digitalWrite(5,LOW);
|
||||
|
||||
//Motors
|
||||
MotorA.init();
|
||||
MotorB.init();
|
||||
|
||||
Serial.begin(9600);
|
||||
}
|
||||
void loop(){
|
||||
x = 512 - analogRead(A0); //in:[0,1023] out: [-512,511]
|
||||
fin = 1024 - analogRead(A1); //in:[1023,0] out [0,1023]
|
||||
fout = x*fin/500;
|
||||
MotorA.torque(fout);
|
||||
|
||||
x = 512 - analogRead(A3); //in:[0,1023] out: [-512,511]
|
||||
fin = 1024 - analogRead(A4); //in:[1023,0] out [0,1023]
|
||||
fout = x*fin/500;
|
||||
MotorB.torque(fout);
|
||||
}
|
||||
20
software/apps/M&MStudioBV/FSR/FSR_AB_test/FSR_AB_test.ino
Normal file
20
software/apps/M&MStudioBV/FSR/FSR_AB_test/FSR_AB_test.ino
Normal file
@ -0,0 +1,20 @@
|
||||
// FSR A and B test
|
||||
void setup(){
|
||||
//FSR-A
|
||||
pinMode(A1,INPUT);
|
||||
digitalWrite(A1,HIGH); //set pull-up
|
||||
pinMode(4,OUTPUT);
|
||||
digitalWrite(4,LOW);
|
||||
//FSR-B
|
||||
pinMode(A4,INPUT);
|
||||
digitalWrite(A4,HIGH); //set pull-up
|
||||
pinMode(5,OUTPUT);
|
||||
digitalWrite(5,LOW);
|
||||
|
||||
Serial.begin(9600);
|
||||
}
|
||||
void loop(){
|
||||
Serial.print(analogRead(A1));
|
||||
Serial.print(" ");
|
||||
Serial.println(analogRead(A4));
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
void setup(){
|
||||
pinMode(A1,INPUT);
|
||||
pinMode(4,OUTPUT);
|
||||
digitalWrite(4,LOW); //sets ground
|
||||
digitalWrite(A1,HIGH); //sets pull-up
|
||||
}
|
||||
void loop(){
|
||||
digitalWrite(A1,LOW);
|
||||
digitalWrite(4,HIGH);
|
||||
delay(1000);
|
||||
digitalWrite(A1,HIGH);
|
||||
digitalWrite(4,LOW);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
//does D4 actually go 5v to GND?
|
||||
//yes, if D4 is OUTPUT.
|
||||
36
software/apps/M&MStudioBV/FSR/HumpFSR_A/HumpFSR_A.ino
Normal file
36
software/apps/M&MStudioBV/FSR/HumpFSR_A/HumpFSR_A.ino
Normal file
@ -0,0 +1,36 @@
|
||||
//HumpFSR-A
|
||||
//same as CenterFSR-A with sign reversal
|
||||
//position on A0, pwm:D9, dir:D8,D7
|
||||
//FSR on A1 and D4
|
||||
|
||||
// BUZZ! (float vs int?)
|
||||
#include "Motor.h"
|
||||
|
||||
int x, duty, fin;
|
||||
float fout;
|
||||
byte count; // used as counter
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
MotorA.init();
|
||||
//for FSR
|
||||
pinMode(A1,INPUT);
|
||||
digitalWrite(A1,HIGH);
|
||||
pinMode(4,OUTPUT);
|
||||
digitalWrite(4,LOW);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
fin = 1024 - analogRead(A1);
|
||||
x = analogRead(A0)-512;
|
||||
fout = .004*(float(fin)*float(x));
|
||||
duty = min(1023,fout);
|
||||
MotorA.torque(fout);
|
||||
if(count++ == 0){
|
||||
Serial.print(x,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.print(fin,DEC);
|
||||
Serial.print(" ");
|
||||
Serial.println(fout,DEC);
|
||||
}
|
||||
}
|
||||
33
software/apps/M&MStudioBV/FSR/SandFSR_A/SandFSR_A.ino
Normal file
33
software/apps/M&MStudioBV/FSR/SandFSR_A/SandFSR_A.ino
Normal file
@ -0,0 +1,33 @@
|
||||
#include "Motor.h"
|
||||
|
||||
int x; //position
|
||||
float fin; //from hall-sensor [ wired GND to A1 ]
|
||||
float fout; //force
|
||||
int duty; // max 1024
|
||||
byte c; // counter to send data every 256 cycles
|
||||
|
||||
void setup(){
|
||||
MotorA.init();
|
||||
pinMode(A1,INPUT); //used for FSR [A1 to D4]
|
||||
pinMode(4,OUTPUT); //used for FSR as GND
|
||||
digitalWrite(A1,HIGH); //enable pull-up resistor
|
||||
digitalWrite(4,LOW); //GND for FSR
|
||||
//TimerOne
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
fin = analogRead(A1) - 1000;
|
||||
//fout = random(fin);
|
||||
fout = 2*fin + random(fin); // range [0,4096];
|
||||
fout = fout/3;
|
||||
MotorA.torque(fout);
|
||||
// Timer1.pwm(9,duty); //output force
|
||||
|
||||
if(c++==0){
|
||||
Serial.print(fin);
|
||||
Serial.print(" ");
|
||||
Serial.println(fout);
|
||||
}
|
||||
}
|
||||
|
||||
BIN
software/apps/M&MStudioBV/Gran/GongRoarCockShort.wav
Normal file
BIN
software/apps/M&MStudioBV/Gran/GongRoarCockShort.wav
Normal file
Binary file not shown.
13
software/apps/M&MStudioBV/Gran/GranFlash.rtf
Normal file
13
software/apps/M&MStudioBV/Gran/GranFlash.rtf
Normal file
@ -0,0 +1,13 @@
|
||||
{\rtf1\ansi\ansicpg1252\cocoartf1138\cocoasubrtf510
|
||||
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
|
||||
{\colortbl;\red255\green255\blue255;}
|
||||
\margl1440\margr1440\vieww10800\viewh8400\viewkind0
|
||||
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
|
||||
|
||||
\f0\fs24 \cf0 32K flash program memory 8-bit bytes\
|
||||
8K/sec = 4 seconds\
|
||||
\
|
||||
use 20K ?\
|
||||
\
|
||||
granular synthesis is like wave-table synthesis but with playing only a selection and windowing it\
|
||||
the stored wave-table could be a piece of bird-call and you could play a piece by feeling it - i.e. create a "haptic-landscape" that let's you feel what part of the wave you are on.}
|
||||
55
software/apps/M&MStudioBV/PluckOverlap/PluckOverlap.ino
Normal file
55
software/apps/M&MStudioBV/PluckOverlap/PluckOverlap.ino
Normal file
@ -0,0 +1,55 @@
|
||||
// Pluck over-lap
|
||||
// BV 3 Feb 13
|
||||
// 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;
|
||||
x = analogRead(A3) - 512;
|
||||
if (forward){
|
||||
if (x<=0) f = 0;
|
||||
if (x>0 && x<w) f = - slope*x;
|
||||
if (x>w){
|
||||
f = 0;
|
||||
forward = false;
|
||||
Serial.println("pluck forward");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x>0) f = 0;
|
||||
if (x<0 && x>-w) f = - slope*x;
|
||||
if (x < -w){
|
||||
f = 0;
|
||||
forward = true;
|
||||
Serial.println("pluck back");
|
||||
}
|
||||
}
|
||||
fout = int(f);
|
||||
//MotorA.torque(fout);
|
||||
MotorB.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,51 @@
|
||||
//PluckOverlapHalf
|
||||
// BV 3 Feb 13
|
||||
// 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;
|
||||
x = analogRead(A3) - 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);
|
||||
MotorB.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,126 @@
|
||||
// ProfileFx
|
||||
// receives pos from Arduino
|
||||
//
|
||||
//
|
||||
// int F[],x[i], shown as height F[x] "profile"
|
||||
// then as slope of "terrain" dT = F[x]
|
||||
|
||||
|
||||
// constrains x[i]<x[i+1] -100<F<+100
|
||||
|
||||
int pos; //position from Arduino
|
||||
int F[] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
int x[] = {1,2,3,4,5,6,7,8,9,10,11};
|
||||
int i, j, ibest;
|
||||
int s = 80;
|
||||
int n = 10;
|
||||
float dist;
|
||||
float FF; // forces interpolated
|
||||
float top; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
|
||||
import processing.serial.*;
|
||||
int lf = 10; // Linefeed in ASCII
|
||||
String myString = null;
|
||||
Serial myPort; // The serial port
|
||||
|
||||
void setup(){
|
||||
|
||||
println(Serial.list()); // List all the available serial ports:
|
||||
myPort = new Serial(this, Serial.list()[0], 9600); // Open the port you are using at the rate you want:
|
||||
myPort.clear();
|
||||
// Throw out the first reading, in case we started reading
|
||||
// in the middle of a string from the sender.
|
||||
myString = myPort.readStringUntil(lf);
|
||||
myString = null;
|
||||
|
||||
noFill();
|
||||
size(800,800);
|
||||
for(i=0;i<11;i=i+1){
|
||||
F[i]=0;
|
||||
x[i]=80*i;
|
||||
}
|
||||
}
|
||||
|
||||
void draw( ){
|
||||
|
||||
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,100,width,100);
|
||||
line(0,200,width,200);
|
||||
for (i = 1; i < 10; i = i+1){
|
||||
line (i*80,0,i*80,200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
stroke(0);
|
||||
for (i = 0; i < 10;i= i+1){
|
||||
line(x[i],F[i]+100,x[i+1],F[i+1]+100);
|
||||
}
|
||||
|
||||
//test every F,x pair to see who is closest call it ibest;
|
||||
ibest = 1;
|
||||
dist = sq(F[0]+100-mouseY)+sq(x[0]-mouseX);
|
||||
for (i=1;i<10;i=i+1){
|
||||
if(dist > sq(F[i]+100-mouseY)+sq(x[i]-mouseX)){
|
||||
ibest = i;
|
||||
dist = sq(F[i]+100-mouseY)+sq(x[i]-mouseX);
|
||||
}
|
||||
}
|
||||
ellipse(x[ibest],F[ibest]+100,20,20);
|
||||
|
||||
text (Integer.toString(ibest), mouseX+10, mouseY-12);
|
||||
text (Integer.toString(F[ibest]), mouseX+10, mouseY);
|
||||
text (Integer.toString(x[ibest]), mouseX+10, mouseY+12);
|
||||
|
||||
if (mousePressed == true){
|
||||
//now use ibest to move to mouseX, mouseY
|
||||
x[ibest] = min(x[ibest+1],max(x[ibest-1],mouseX));
|
||||
F[ibest] = mouseY - 100;
|
||||
if (mouseY < 0) F[ibest] = -100;
|
||||
if (mouseY > 200) F[ibest] = 100;
|
||||
}
|
||||
|
||||
//plot "terrain" assuming 80 point separation of F[]'s
|
||||
pushMatrix();
|
||||
translate(0,height/2);
|
||||
|
||||
top = 0;
|
||||
FF = F[0];
|
||||
for (i = 0; i < n; i = i+1) {
|
||||
s = x[i+1]-x[i]+1; // increment used for plotting
|
||||
inc = 0.01*(F[i+1]-F[i])/s;
|
||||
for (j = 0; j < s; j = j+1) {
|
||||
FF = FF + inc;
|
||||
top = top + FF; // j increments of inc = F diff.
|
||||
line(x[i]+j,height,x[i]+j,top);
|
||||
}
|
||||
}
|
||||
popMatrix();
|
||||
|
||||
//receive pos from Arduino
|
||||
while (myPort.available() > 0) {
|
||||
myString = myPort.readStringUntil(lf);
|
||||
if (myString != null) {
|
||||
myString = trim(myString);
|
||||
pos = int(myString);
|
||||
}
|
||||
}
|
||||
// draw pos cursor
|
||||
stroke(150);
|
||||
line(pos,200,pos,800);
|
||||
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
if (key == CODED) {
|
||||
if (keyCode == UP) --F[ibest];
|
||||
if (keyCode == DOWN) ++F[ibest];
|
||||
if (keyCode == RIGHT) ++x[ibest];
|
||||
if (keyCode == LEFT) --x[ibest];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
20
software/apps/M&MStudioBV/Pulse/Pulse.ino
Normal file
20
software/apps/M&MStudioBV/Pulse/Pulse.ino
Normal file
@ -0,0 +1,20 @@
|
||||
//"Pulse" - small duration positive then negative force
|
||||
// parameters: F1, T1, D1, F2, T2, D2
|
||||
#include <Motor.h>
|
||||
|
||||
void setup(){
|
||||
MotorB.init();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
//for (int i; i < 512; i + 100){
|
||||
MotorB.torque(10);
|
||||
delay (20);
|
||||
MotorB.torque(0);
|
||||
delay (150);
|
||||
MotorB.torque(-50);
|
||||
delay (40);
|
||||
MotorB.torque(0);
|
||||
delay (750);
|
||||
//}
|
||||
}
|
||||
34
software/apps/M&MStudioBV/Pulse_Beat/Pulse_Beat.ino
Normal file
34
software/apps/M&MStudioBV/Pulse_Beat/Pulse_Beat.ino
Normal file
@ -0,0 +1,34 @@
|
||||
//"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(){
|
||||
MotorB.init();
|
||||
Music.init();
|
||||
|
||||
Music.setWaveform(SINE);
|
||||
Music.enableEnvelope();
|
||||
Music.setAttack(10);
|
||||
Music.setDecay(10);
|
||||
Music.setRelease(10);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
//for (int i; i < 512; i + 100){
|
||||
MotorB.torque(40);
|
||||
Music.noteOn(map(analogRead(A3),0,1023,30,60));
|
||||
delay (20);
|
||||
Music.noteOff();MotorB.torque(0);
|
||||
delay (150);
|
||||
MotorB.torque(-70);
|
||||
Music.noteOn(map(analogRead(A3),0,1023,35,65));
|
||||
delay (40);
|
||||
Music.noteOff();MotorB.torque(0);
|
||||
MotorB.torque(0);
|
||||
delay (750);
|
||||
//}
|
||||
}
|
||||
17
software/apps/M&MStudioBV/ReadA0A1/ReadA0A1.ino
Normal file
17
software/apps/M&MStudioBV/ReadA0A1/ReadA0A1.ino
Normal file
@ -0,0 +1,17 @@
|
||||
//read position A0 FSR A1
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
pinMode(A0,INPUT);
|
||||
//for FSR
|
||||
pinMode(A1,INPUT);
|
||||
digitalWrite(A1,HIGH);
|
||||
pinMode(4,OUTPUT);
|
||||
digitalWrite(4,LOW);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
Serial.print(analogRead(A0));
|
||||
Serial.print(" ");
|
||||
Serial.println(analogRead(A1));
|
||||
}
|
||||
54
software/apps/M&MStudioBV/WallPluck_in/WallPluck_in.ino
Normal file
54
software/apps/M&MStudioBV/WallPluck_in/WallPluck_in.ino
Normal file
@ -0,0 +1,54 @@
|
||||
//Wall
|
||||
//need some mass so it "bounces"?
|
||||
|
||||
#include <Motor.h>
|
||||
#include <Music.h>
|
||||
|
||||
int x;
|
||||
boolean inside;
|
||||
int Fout;
|
||||
int wave;
|
||||
int Fmax = 4023;
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
MotorA.init();
|
||||
|
||||
Music.init();
|
||||
Music.setWaveform(0);//8bit 0 = sine.
|
||||
Music.setGain(0.0f);
|
||||
Music.setFrequency(200);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// waiting for "return" or "line-feed"
|
||||
while (Serial.available()) {
|
||||
wave = Serial.parseInt();
|
||||
if (Serial.read() == '\n') {
|
||||
Serial.print("I received: ");
|
||||
Serial.println(wave, DEC);
|
||||
if (wave > 16) wave = 16;
|
||||
if (wave < 0) wave - 0;
|
||||
Music.setWaveform(wave);
|
||||
}
|
||||
} x = analogRead(A0)-512;
|
||||
if(x < 0){
|
||||
Fout = -20*x;
|
||||
MotorA.torque(Fout);
|
||||
Music.setGain(1.0f); //contact silences music?
|
||||
//Music.setGain(float(x/200));
|
||||
inside = true;
|
||||
}
|
||||
else{
|
||||
if (inside){ //first time outside
|
||||
inside = false; //start note
|
||||
Music.setGain(1.0f);
|
||||
}
|
||||
if(x>10){
|
||||
Music.setGain(0.998f*Music.getGainFloat());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
54
software/apps/M&MStudioBV/WallPluck_out/WallPluck_out.ino
Normal file
54
software/apps/M&MStudioBV/WallPluck_out/WallPluck_out.ino
Normal file
@ -0,0 +1,54 @@
|
||||
//Wall
|
||||
//need some mass so it "bounces"?
|
||||
|
||||
#include <Music.h>
|
||||
#define BIT_DEPTH 8 // gives us 16 Waveforms
|
||||
|
||||
#include <Motor.h>
|
||||
|
||||
int x;
|
||||
boolean inside;
|
||||
int Fout;
|
||||
int wave;
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
MotorA.init();
|
||||
|
||||
Music.init();
|
||||
Music.setWaveform(1);//8bit
|
||||
Music.setGain(0.0f);
|
||||
Music.setFrequency(200);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// waiting for "return" or "line-feed"
|
||||
while (Serial.available()) {
|
||||
wave = Serial.parseInt();
|
||||
if (Serial.read() == '\n') {
|
||||
Serial.print("I received: ");
|
||||
Serial.println(wave, DEC);
|
||||
if (wave > 16) wave = 16;
|
||||
if (wave < 0) wave - 0;
|
||||
Music.setWaveform(wave);
|
||||
}
|
||||
} x = analogRead(A0)-512;
|
||||
if(x < 0){
|
||||
Fout = -20*x;
|
||||
MotorA.torque(Fout);
|
||||
Music.setGain(0.0f); //contact silences music
|
||||
inside = true;
|
||||
}
|
||||
else{
|
||||
if (inside){ //first time outside
|
||||
inside = false; //start note
|
||||
Music.setGain(1.0f);
|
||||
}
|
||||
if(x>10){
|
||||
Music.setGain(0.998f*Music.getGain());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
22
software/apps/M&MStudioBV/motortestM/motortestM.ino
Normal file
22
software/apps/M&MStudioBV/motortestM/motortestM.ino
Normal file
@ -0,0 +1,22 @@
|
||||
//motortest
|
||||
//.5 sec forward, .5 sec back
|
||||
|
||||
#include <Motor.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
MotorA.init();
|
||||
MotorB.init();
|
||||
MotorA.torque(40); // small force for Plank
|
||||
MotorB.torque(200); // need 200 for Fader
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
MotorA.direction(FORWARD);
|
||||
MotorB.direction(FORWARD);
|
||||
delay(500);
|
||||
MotorA.direction(BACKWARD);
|
||||
MotorB.direction(BACKWARD);
|
||||
delay(500);
|
||||
}
|
||||
27
software/apps/M&MStudioBV/plotOsc/plotOsc.pde
Normal file
27
software/apps/M&MStudioBV/plotOsc/plotOsc.pde
Normal file
@ -0,0 +1,27 @@
|
||||
// step response of second order system
|
||||
// m mass, k spring, b damping
|
||||
|
||||
float xPos = 0.0;
|
||||
float yPos = 0.0;
|
||||
float xVel = 0.0;
|
||||
float T = 0.1;
|
||||
float koverm = 0.1;
|
||||
float boverm = 0.01;
|
||||
|
||||
int x, y; // variables at mouse- and screen-resolution
|
||||
|
||||
void setup() { // setup() runs once
|
||||
size(800, 500);
|
||||
frameRate(30);
|
||||
}
|
||||
|
||||
void draw() { // draw() loops forever, until stopped
|
||||
xPos = width/2;
|
||||
xVel = 0.0;
|
||||
background(204);
|
||||
for(int y=0; y < height; y = y +1) {
|
||||
xVel += koverm * (mouseX - xPos) * T - boverm * xVel; //a=F/m
|
||||
xPos += xVel * T;
|
||||
point(xPos, y);
|
||||
}
|
||||
}
|
||||
30
software/apps/Motor/pos_FSR_AB_test/pos_FSR_AB_test.ino
Normal file
30
software/apps/Motor/pos_FSR_AB_test/pos_FSR_AB_test.ino
Normal file
@ -0,0 +1,30 @@
|
||||
//position and force reporting
|
||||
//sends A0 (MotorA), A1 (ForceA)
|
||||
//sends A3 (MotorB), A4 (ForceB)
|
||||
// to Serial Monitor
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
//set up for FSR A1 to D4
|
||||
pinMode(A1,INPUT);
|
||||
pinMode(4,OUTPUT);
|
||||
digitalWrite(4,LOW);
|
||||
digitalWrite(A1,HIGH); //internal pull-up
|
||||
//set up for FSR A4 to D5
|
||||
pinMode(A4,INPUT);
|
||||
pinMode(5,OUTPUT);
|
||||
digitalWrite(5,LOW);
|
||||
digitalWrite(A4,HIGH); //internal pull-up
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(analogRead(A0)); //positionA
|
||||
Serial.print(" ");
|
||||
Serial.print(analogRead(A1)); //positionA
|
||||
Serial.print(" ");
|
||||
Serial.print(analogRead(A3)); //positionA
|
||||
Serial.print(" ");
|
||||
Serial.println(analogRead(A4)); //forceA
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user