TEI Studio
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// 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);
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
@@ -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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,51 @@
|
||||
// Theremin
|
||||
// A: pitch, B: volume
|
||||
// or visa versa ??????????
|
||||
|
||||
|
||||
#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);
|
||||
//Music.setFrequency(xA);
|
||||
|
||||
xB = analogRead(A0);
|
||||
volume = -float(xB)/256.; // B position
|
||||
volume = pow(10,volume);
|
||||
Music.setGain(volume);
|
||||
//Music.setGain(0.5);
|
||||
|
||||
if(c++==0){
|
||||
Serial.print(xA);
|
||||
Serial.print(" ");
|
||||
Serial.print(p);
|
||||
Serial.print(" ");
|
||||
Serial.print(frequency);
|
||||
Serial.print(" ");
|
||||
Serial.print(xB);
|
||||
Serial.print(" ");
|
||||
Serial.println(volume);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.getGain());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user