Goldsmiths
This commit is contained in:
parent
d938b31e91
commit
05fc0c94af
@ -1,34 +0,0 @@
|
|||||||
//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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,63 +0,0 @@
|
|||||||
// 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++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,55 +0,0 @@
|
|||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,54 +0,0 @@
|
|||||||
//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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,54 +0,0 @@
|
|||||||
//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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,43 +0,0 @@
|
|||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,259 +0,0 @@
|
|||||||
String[] knobName = {"FREQ1",
|
|
||||||
"SEMI1",
|
|
||||||
"DETUNE1",
|
|
||||||
"GAIN1",
|
|
||||||
"WAVE1",
|
|
||||||
"FREQ2",
|
|
||||||
"SEMI2",
|
|
||||||
"DETUNE2",
|
|
||||||
"GAIN2",
|
|
||||||
"WAVE2",
|
|
||||||
"FREQ3",
|
|
||||||
"SEMI3",
|
|
||||||
"DETUNE3",
|
|
||||||
"GAIN3",
|
|
||||||
"WAVE3",
|
|
||||||
"ATTACK",
|
|
||||||
"DECAY",
|
|
||||||
"SUSTAIN",
|
|
||||||
"RELEASE",
|
|
||||||
"DETUNE_ALL",
|
|
||||||
"WAVE_ALL"
|
|
||||||
};
|
|
||||||
|
|
||||||
String[] waveform = {"SINE",
|
|
||||||
"SQUARE",
|
|
||||||
"PULSE",
|
|
||||||
"TRIANGLE",
|
|
||||||
"SAW",
|
|
||||||
"FUZZ",
|
|
||||||
"DIGI1",
|
|
||||||
"DIGI2",
|
|
||||||
"DIGI3",
|
|
||||||
"DIGI4",
|
|
||||||
"NOISE",
|
|
||||||
"DIGI6",
|
|
||||||
"TAN1",
|
|
||||||
"TAN2",
|
|
||||||
"TAN3",
|
|
||||||
"TAN4"
|
|
||||||
};
|
|
||||||
|
|
||||||
byte[] knobMidiCC = {10,11,12,13,14,20,21,22,23,24,30,31,32,33,34,114,115,116,117,4,5};
|
|
||||||
|
|
||||||
|
|
||||||
void freq1(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 0;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + (int)(pow(2,(knobValue[knob]-69)/12.0)*440) + " Hz");
|
|
||||||
//(2^((p-69)/12))*440
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void semi1(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 1;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
int semi =(knobValue[knob]+24)*2+16;
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)semi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void detune1(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 2;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void gain1(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 3;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void wave1(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 4;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob] + " (" + waveform[knobValue[knob]] + ")");
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)(knobValue[knob]*8));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void freq2(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 5;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + (int)(pow(2,(knobValue[knob]-69)/12.0)*440) + " Hz");
|
|
||||||
//(2^((p-69)/12))*440
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void semi2(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 6;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
int semi =(knobValue[knob]+24)*2+16;
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)semi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void detune2(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 7;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void gain2(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 8;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void wave2(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 9;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob] + " (" + waveform[knobValue[knob]] + ")");
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)(knobValue[knob]*8));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void freq3(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 10;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + (int)(pow(2,(knobValue[knob]-69)/12.0)*440) + " Hz");
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void semi3(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 11;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
int semi =(knobValue[knob]+24)*2+16;
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)semi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void detune3(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 12;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void gain3(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 13;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void wave3(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 14;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob] + " (" + waveform[knobValue[knob]] + ")");
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)(knobValue[knob]*8));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void attack(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 15;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void decay(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 16;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sustain(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 17;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void release(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 18;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,102 +0,0 @@
|
|||||||
import controlP5.*;
|
|
||||||
import processing.serial.*;
|
|
||||||
|
|
||||||
ControlP5 controlP5;
|
|
||||||
|
|
||||||
Serial port0;
|
|
||||||
|
|
||||||
boolean printChange = true;
|
|
||||||
|
|
||||||
int defaultMidiChannel = 9;
|
|
||||||
|
|
||||||
int backgroundColor = color(0,0,0);
|
|
||||||
int knobColor = color(235,103,295);
|
|
||||||
|
|
||||||
int numKnobs = 24;
|
|
||||||
int[] knobValue = new int[numKnobs];
|
|
||||||
|
|
||||||
int posX = 20;
|
|
||||||
int posY = 40;
|
|
||||||
int posW = 60;
|
|
||||||
int posH = 60;
|
|
||||||
int knobS = 40;
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
size(400,400);
|
|
||||||
smooth();
|
|
||||||
background(0);
|
|
||||||
|
|
||||||
controlP5 = new ControlP5(this);
|
|
||||||
PFont p = createFont("Georgia",12);
|
|
||||||
controlP5.setControlFont(p,12);
|
|
||||||
controlP5.setColorLabel(color(255,128));
|
|
||||||
|
|
||||||
Textlabel labelFreq = controlP5.addTextlabel("freqLabel","FREQ",posX+posW*0+3,posY-20);
|
|
||||||
Textlabel labelSemi = controlP5.addTextlabel("semiLabel","SEMI",posX+posW*1+4,posY-20);
|
|
||||||
Textlabel labelDetune = controlP5.addTextlabel("detuneLabel","DETUNE",posX+posW*2-6,posY-20);
|
|
||||||
Textlabel labelGain = controlP5.addTextlabel("gainLabel","GAIN",posX+posW*3+4,posY-20);
|
|
||||||
Textlabel labelWave = controlP5.addTextlabel("waveLabel","WAVE",posX+posW*4+2,posY-20);
|
|
||||||
|
|
||||||
Textlabel labelAttack = controlP5.addTextlabel("attackLabel","A",posX+16+posW*0,posY+posH*4-20);
|
|
||||||
Textlabel labelDecay = controlP5.addTextlabel("decayLabel","D",posX+16+posW*1,posY+posH*4-20);
|
|
||||||
Textlabel labelsustain = controlP5.addTextlabel("sustainLabel","S",posX+16+posW*2,posY+posH*4-20);
|
|
||||||
Textlabel labelReleasek = controlP5.addTextlabel("releaseLabel","R",posX+16+posW*3,posY+posH*4-20);
|
|
||||||
|
|
||||||
Knob freq1 = controlP5.addKnob("freq1", 0,127,64, posX+posW*0,posY+posH*0,knobS);
|
|
||||||
Knob semi1 = controlP5.addKnob("semi1", -24,24,0, posX+posW*1,posY+posH*0,knobS);
|
|
||||||
Knob detune1 = controlP5.addKnob("detune1",0,127,64, posX+posW*2,posY+posH*0,knobS);
|
|
||||||
Knob gain1 = controlP5.addKnob("gain1", 0,127,127, posX+posW*3,posY+posH*0,knobS);
|
|
||||||
Knob wave1 = controlP5.addKnob("wave1", 0,15,0, posX+posW*4,posY+posH*0,knobS);
|
|
||||||
|
|
||||||
Knob freq2 = controlP5.addKnob("freq2", 0,127,64, posX+posW*0,posY+posH*1,knobS);
|
|
||||||
Knob semi2 = controlP5.addKnob("semi2", -24,24,0, posX+posW*1,posY+posH*1,knobS);
|
|
||||||
Knob detune2 = controlP5.addKnob("detune2",0,127,64, posX+posW*2,posY+posH*1,knobS);
|
|
||||||
Knob gain2 = controlP5.addKnob("gain2", 0,127,127, posX+posW*3,posY+posH*1,knobS);
|
|
||||||
Knob wave2 = controlP5.addKnob("wave2", 0,15,0, posX+posW*4,posY+posH*1,knobS);
|
|
||||||
|
|
||||||
Knob freq3 = controlP5.addKnob("freq3", 0,127,64, posX+posW*0,posY+posH*2,knobS);
|
|
||||||
Knob semi3 = controlP5.addKnob("semi3", -24,24,0, posX+posW*1,posY+posH*2,knobS);
|
|
||||||
Knob detune3 = controlP5.addKnob("detune3",0,127,64, posX+posW*2,posY+posH*2,knobS);
|
|
||||||
Knob gain3 = controlP5.addKnob("gain3", 0,127,127, posX+posW*3,posY+posH*2,knobS);
|
|
||||||
Knob wave3 = controlP5.addKnob("wave3", 0,15,0, posX+posW*4,posY+posH*2,knobS);
|
|
||||||
|
|
||||||
Knob attack = controlP5.addKnob("attack", 0,127,0, posX+posW*0, posY+posH*4, knobS);
|
|
||||||
Knob decay = controlP5.addKnob("decay", 0,127,64, posX+posW*1, posY+posH*4, knobS);
|
|
||||||
Knob sustain = controlP5.addKnob("sustain",0,127,64, posX+posW*2, posY+posH*4, knobS);
|
|
||||||
Knob release = controlP5.addKnob("release",0,127,64, posX+posW*3, posY+posH*4, knobS);
|
|
||||||
|
|
||||||
println(Serial.list());
|
|
||||||
port0 = new Serial(this, Serial.list()[0], 9600);
|
|
||||||
|
|
||||||
for(int i=0; i<numKnobs; i++) {
|
|
||||||
knobValue[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void draw() {
|
|
||||||
background(backgroundColor);
|
|
||||||
|
|
||||||
|
|
||||||
if(port0.available() > 0) {
|
|
||||||
//int val = port0.read();
|
|
||||||
//float val = float(port0.read());
|
|
||||||
char val = char(port0.read());
|
|
||||||
println(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void sendControlChange(byte channel, byte CC, byte value) {
|
|
||||||
|
|
||||||
byte controlChange = byte(0xB0 | channel);
|
|
||||||
|
|
||||||
port0.write(controlChange);
|
|
||||||
port0.write(CC);
|
|
||||||
port0.write(value);
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,259 +0,0 @@
|
|||||||
String[] knobName = {"FREQ1",
|
|
||||||
"SEMI1",
|
|
||||||
"DETUNE1",
|
|
||||||
"GAIN1",
|
|
||||||
"WAVE1",
|
|
||||||
"FREQ2",
|
|
||||||
"SEMI2",
|
|
||||||
"DETUNE2",
|
|
||||||
"GAIN2",
|
|
||||||
"WAVE2",
|
|
||||||
"FREQ3",
|
|
||||||
"SEMI3",
|
|
||||||
"DETUNE3",
|
|
||||||
"GAIN3",
|
|
||||||
"WAVE3",
|
|
||||||
"ATTACK",
|
|
||||||
"DECAY",
|
|
||||||
"SUSTAIN",
|
|
||||||
"RELEASE",
|
|
||||||
"DETUNE_ALL",
|
|
||||||
"WAVE_ALL"
|
|
||||||
};
|
|
||||||
|
|
||||||
String[] waveform = {"SINE",
|
|
||||||
"SQUARE",
|
|
||||||
"PULSE",
|
|
||||||
"TRIANGLE",
|
|
||||||
"SAW",
|
|
||||||
"FUZZ",
|
|
||||||
"DIGI1",
|
|
||||||
"DIGI2",
|
|
||||||
"DIGI3",
|
|
||||||
"DIGI4",
|
|
||||||
"NOISE",
|
|
||||||
"DIGI6",
|
|
||||||
"TAN1",
|
|
||||||
"TAN2",
|
|
||||||
"TAN3",
|
|
||||||
"TAN4"
|
|
||||||
};
|
|
||||||
|
|
||||||
byte[] knobMidiCC = {10,11,12,13,14,20,21,22,23,24,30,31,32,33,34,114,115,116,117,4,5};
|
|
||||||
|
|
||||||
|
|
||||||
void freq1(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 0;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + (int)(pow(2,(knobValue[knob]-69)/12.0)*440) + " Hz");
|
|
||||||
//(2^((p-69)/12))*440
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void semi1(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 1;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
int semi =(knobValue[knob]+24)*2+16;
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)semi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void detune1(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 2;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void gain1(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 3;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void wave1(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 4;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob] + " (" + waveform[knobValue[knob]] + ")");
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)(knobValue[knob]*8));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void freq2(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 5;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + (int)(pow(2,(knobValue[knob]-69)/12.0)*440) + " Hz");
|
|
||||||
//(2^((p-69)/12))*440
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void semi2(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 6;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
int semi =(knobValue[knob]+24)*2+16;
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)semi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void detune2(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 7;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void gain2(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 8;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void wave2(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 9;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob] + " (" + waveform[knobValue[knob]] + ")");
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)(knobValue[knob]*8));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void freq3(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 10;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + (int)(pow(2,(knobValue[knob]-69)/12.0)*440) + " Hz");
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void semi3(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 11;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
int semi =(knobValue[knob]+24)*2+16;
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)semi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void detune3(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 12;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void gain3(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 13;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void wave3(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 14;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob] + " (" + waveform[knobValue[knob]] + ")");
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)(knobValue[knob]*8));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void attack(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 15;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void decay(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 16;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sustain(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 17;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void release(int val)
|
|
||||||
{
|
|
||||||
val = (int)val;
|
|
||||||
int knob = 18;
|
|
||||||
if(knobValue[knob] != val) {
|
|
||||||
knobValue[knob] = val;
|
|
||||||
if(printChange) println(knobName[knob] + " is: " + knobValue[knob]);
|
|
||||||
sendControlChange((byte)0, (byte)knobMidiCC[knob], (byte)knobValue[knob]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,166 +0,0 @@
|
|||||||
//import oscP5.*;
|
|
||||||
//import netP5.*;
|
|
||||||
import controlP5.*;
|
|
||||||
import rwmidi.*; // watch out for this
|
|
||||||
import processing.serial.*;
|
|
||||||
|
|
||||||
ControlP5 controlP5;
|
|
||||||
|
|
||||||
MidiInput input;
|
|
||||||
|
|
||||||
Serial port0;
|
|
||||||
|
|
||||||
boolean printChange = true;
|
|
||||||
|
|
||||||
int defaultMidiChannel = 9;
|
|
||||||
|
|
||||||
int backgroundColor = color(0,0,0);
|
|
||||||
int knobColor = color(235,103,295);
|
|
||||||
|
|
||||||
int numKnobs = 24;
|
|
||||||
int[] knobValue = new int[numKnobs];
|
|
||||||
|
|
||||||
int posX = 20;
|
|
||||||
int posY = 40;
|
|
||||||
int posW = 60;
|
|
||||||
int posH = 60;
|
|
||||||
int knobS = 40;
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
size(400,400);
|
|
||||||
smooth();
|
|
||||||
background(0);
|
|
||||||
|
|
||||||
controlP5 = new ControlP5(this);
|
|
||||||
PFont p = createFont("Georgia",12);
|
|
||||||
controlP5.setControlFont(p,12);
|
|
||||||
controlP5.setColorLabel(color(255,128));
|
|
||||||
|
|
||||||
Textlabel labelFreq = controlP5.addTextlabel("freqLabel","FREQ",posX+posW*0+3,posY-20);
|
|
||||||
Textlabel labelSemi = controlP5.addTextlabel("semiLabel","SEMI",posX+posW*1+4,posY-20);
|
|
||||||
Textlabel labelDetune = controlP5.addTextlabel("detuneLabel","DETUNE",posX+posW*2-6,posY-20);
|
|
||||||
Textlabel labelGain = controlP5.addTextlabel("gainLabel","GAIN",posX+posW*3+4,posY-20);
|
|
||||||
Textlabel labelWave = controlP5.addTextlabel("waveLabel","WAVE",posX+posW*4+2,posY-20);
|
|
||||||
|
|
||||||
Textlabel labelAttack = controlP5.addTextlabel("attackLabel","A",posX+16+posW*0,posY+posH*4-20);
|
|
||||||
Textlabel labelDecay = controlP5.addTextlabel("decayLabel","D",posX+16+posW*1,posY+posH*4-20);
|
|
||||||
Textlabel labelsustain = controlP5.addTextlabel("sustainLabel","S",posX+16+posW*2,posY+posH*4-20);
|
|
||||||
Textlabel labelReleasek = controlP5.addTextlabel("releaseLabel","R",posX+16+posW*3,posY+posH*4-20);
|
|
||||||
|
|
||||||
Knob freq1 = controlP5.addKnob("freq1", 0,127,64, posX+posW*0,posY+posH*0,knobS);
|
|
||||||
Knob semi1 = controlP5.addKnob("semi1", -24,24,0, posX+posW*1,posY+posH*0,knobS);
|
|
||||||
Knob detune1 = controlP5.addKnob("detune1",0,127,64, posX+posW*2,posY+posH*0,knobS);
|
|
||||||
Knob gain1 = controlP5.addKnob("gain1", 0,127,127, posX+posW*3,posY+posH*0,knobS);
|
|
||||||
Knob wave1 = controlP5.addKnob("wave1", 0,15,0, posX+posW*4,posY+posH*0,knobS);
|
|
||||||
|
|
||||||
Knob freq2 = controlP5.addKnob("freq2", 0,127,64, posX+posW*0,posY+posH*1,knobS);
|
|
||||||
Knob semi2 = controlP5.addKnob("semi2", -24,24,0, posX+posW*1,posY+posH*1,knobS);
|
|
||||||
Knob detune2 = controlP5.addKnob("detune2",0,127,64, posX+posW*2,posY+posH*1,knobS);
|
|
||||||
Knob gain2 = controlP5.addKnob("gain2", 0,127,127, posX+posW*3,posY+posH*1,knobS);
|
|
||||||
Knob wave2 = controlP5.addKnob("wave2", 0,15,0, posX+posW*4,posY+posH*1,knobS);
|
|
||||||
|
|
||||||
Knob freq3 = controlP5.addKnob("freq3", 0,127,64, posX+posW*0,posY+posH*2,knobS);
|
|
||||||
Knob semi3 = controlP5.addKnob("semi3", -24,24,0, posX+posW*1,posY+posH*2,knobS);
|
|
||||||
Knob detune3 = controlP5.addKnob("detune3",0,127,64, posX+posW*2,posY+posH*2,knobS);
|
|
||||||
Knob gain3 = controlP5.addKnob("gain3", 0,127,127, posX+posW*3,posY+posH*2,knobS);
|
|
||||||
Knob wave3 = controlP5.addKnob("wave3", 0,15,0, posX+posW*4,posY+posH*2,knobS);
|
|
||||||
|
|
||||||
Knob attack = controlP5.addKnob("attack", 0,127,0, posX+posW*0, posY+posH*4, knobS);
|
|
||||||
Knob decay = controlP5.addKnob("decay", 0,127,64, posX+posW*1, posY+posH*4, knobS);
|
|
||||||
Knob sustain = controlP5.addKnob("sustain",0,127,64, posX+posW*2, posY+posH*4, knobS);
|
|
||||||
Knob release = controlP5.addKnob("release",0,127,64, posX+posW*3, posY+posH*4, knobS);
|
|
||||||
|
|
||||||
|
|
||||||
println("print MIDI input devices:");
|
|
||||||
println(RWMidi.getInputDeviceNames());
|
|
||||||
input = RWMidi.getInputDevices()[0].createInput(this);
|
|
||||||
|
|
||||||
println(Serial.list());
|
|
||||||
port0 = new Serial(this, Serial.list()[0], 9600);
|
|
||||||
|
|
||||||
for(int i=0; i<numKnobs; i++) {
|
|
||||||
knobValue[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void draw() {
|
|
||||||
background(backgroundColor);
|
|
||||||
|
|
||||||
|
|
||||||
if(port0.available() > 0) {
|
|
||||||
//int val = port0.read();
|
|
||||||
//float val = float(port0.read());
|
|
||||||
char val = char(port0.read());
|
|
||||||
println(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void noteOnReceived(Note note) {
|
|
||||||
|
|
||||||
byte channel = byte(note.getChannel());
|
|
||||||
byte pitch = byte(note.getPitch());
|
|
||||||
byte velocity = byte(note.getVelocity());
|
|
||||||
|
|
||||||
sendNoteOn(channel, pitch, velocity);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void noteOffReceived(Note note) {
|
|
||||||
|
|
||||||
byte channel = byte(note.getChannel());
|
|
||||||
byte pitch = byte(note.getPitch());
|
|
||||||
byte velocity = byte(note.getVelocity());
|
|
||||||
|
|
||||||
sendNoteOff(channel, pitch, velocity);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void controllerChangeReceived(rwmidi.Controller controller) {
|
|
||||||
|
|
||||||
byte channel = byte(controller.getChannel());
|
|
||||||
byte CC = byte(controller.getCC());
|
|
||||||
byte value = byte(controller.getValue());
|
|
||||||
|
|
||||||
sendControlChange(channel, CC, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void sendNoteOn(byte channel, byte pitch, byte velocity) {
|
|
||||||
|
|
||||||
byte noteOn = byte(0x90 | channel);
|
|
||||||
|
|
||||||
port0.write(noteOn);
|
|
||||||
port0.write(pitch);
|
|
||||||
port0.write(velocity);
|
|
||||||
//println('\n' + hex(noteOn) + " " + hex(pitch) + " " + hex(velocity));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendNoteOff(byte channel, byte pitch, byte velocity) {
|
|
||||||
|
|
||||||
byte noteOff = byte(0x80 | channel);
|
|
||||||
|
|
||||||
port0.write(noteOff);
|
|
||||||
port0.write(pitch);
|
|
||||||
port0.write(velocity);
|
|
||||||
//println('\n' + hex(noteOff) + " " + hex(pitch) + " " + hex(velocity));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendControlChange(byte channel, byte CC, byte value) {
|
|
||||||
|
|
||||||
byte controlChange = byte(0xB0 | channel);
|
|
||||||
|
|
||||||
port0.clear();
|
|
||||||
port0.write(controlChange);
|
|
||||||
port0.write(CC);
|
|
||||||
port0.write(value);
|
|
||||||
//println('\n' + hex(controlChange) + " " + hex(CC) + " " + hex(value));
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
// You can set the number of oscillators (1 to 3) and the bit depth of the
|
|
||||||
// oscillators (8 or 12 bit). These settings must be defined before the
|
|
||||||
// inclusion of the MMM library files. They default to 1 osciallator
|
|
||||||
// and 8bit respectively.
|
|
||||||
|
|
||||||
#define NUM_OSCILLATORS 1
|
|
||||||
#define BIT_DEPTH 12
|
|
||||||
|
|
||||||
// The Music object is automatically instantiated when the header file is
|
|
||||||
// included. Make calls to the Music objects wit "Music.function(args)".
|
|
||||||
// You still need to call Music.init() in the setup() function below.
|
|
||||||
#include <Music.h>
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
// We initialise the sound engine by calling Music.init() which outputs a tone
|
|
||||||
Music.init();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,56 +0,0 @@
|
|||||||
// You can set the number of oscillators (1 to 3) and the bit depth of the
|
|
||||||
// oscillators (8 or 12 bit). These settings must be defined before the
|
|
||||||
// inclusion of the MMM library files. They default to 1 osciallator
|
|
||||||
// and 8bit respectively.
|
|
||||||
|
|
||||||
#define NUM_OSCILLATORS 1
|
|
||||||
#define BIT_DEPTH 8
|
|
||||||
|
|
||||||
// The Music object is automatically instantiated when the header file is
|
|
||||||
// included. Make calls to the Music objects with "Music.function(args)".
|
|
||||||
// You still need to call Music.init() in the setup() function below.
|
|
||||||
#include <Music.h>
|
|
||||||
|
|
||||||
int delayTime = 1000;
|
|
||||||
int cnt = 0;
|
|
||||||
long timeNow;
|
|
||||||
long lastTime = 0;
|
|
||||||
|
|
||||||
byte waveFormArray[] = { SINE,
|
|
||||||
SQUARE,
|
|
||||||
PULSE,
|
|
||||||
TRIANGLE,
|
|
||||||
SAW,
|
|
||||||
FUZZ,
|
|
||||||
DIGI1,
|
|
||||||
DIGI2,
|
|
||||||
DIGI3,
|
|
||||||
DIGI4,
|
|
||||||
NOISE,
|
|
||||||
DIGI6,
|
|
||||||
TAN1,
|
|
||||||
TAN2,
|
|
||||||
TAN3,
|
|
||||||
TAN4
|
|
||||||
};
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
// We initialise the sound engine by calling Music.init() which outputs a tone
|
|
||||||
Music.init();
|
|
||||||
Music.setFrequency(220);
|
|
||||||
Music.setWaveform(SINE);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
timeNow = millis();
|
|
||||||
if((timeNow-lastTime) > delayTime) {
|
|
||||||
cnt = cnt + 1;
|
|
||||||
if(cnt>15) cnt = 0;
|
|
||||||
Music.setWaveform(waveFormArray[cnt]);
|
|
||||||
lastTime = timeNow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,42 +0,0 @@
|
|||||||
// You can set the number of oscillators (1 to 3) and the bit depth of the
|
|
||||||
// oscillators (8 or 12 bit). These settings must be defined before the
|
|
||||||
// inclusion of the MMM library files. They default to 1 osciallator
|
|
||||||
// and 8bit respectively.
|
|
||||||
|
|
||||||
#define NUM_OSCILLATORS 3
|
|
||||||
#define BIT_DEPTH 8
|
|
||||||
|
|
||||||
// The Music object is automatically instantiated when the header file is
|
|
||||||
// included. Make calls to the Music objects with "Music.function(args)".
|
|
||||||
// You still need to call Music.init() in the setup() function below.
|
|
||||||
#include <Music.h>
|
|
||||||
|
|
||||||
int delayTime = 400;
|
|
||||||
int cnt = 0;
|
|
||||||
float baseFrequency = 110;
|
|
||||||
long timeNow;
|
|
||||||
long lastTime = 0;
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
// We initialise the sound engine by calling Music.init() which outputs a tone
|
|
||||||
Music.init();
|
|
||||||
Music.setFrequency(220);
|
|
||||||
Music.setDetune(0.001); // ranges from 0.00 - 0.02 are usually good
|
|
||||||
Music.setWaveform(SAW);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
timeNow = millis();
|
|
||||||
if((timeNow-lastTime) > delayTime) {
|
|
||||||
cnt = cnt + 1;
|
|
||||||
if(cnt>3) cnt = 0;
|
|
||||||
Music.setFrequency1(baseFrequency*1*cnt);
|
|
||||||
Music.setFrequency2(baseFrequency*1.3333*cnt);
|
|
||||||
Music.setFrequency3(baseFrequency*1.5*cnt);
|
|
||||||
lastTime = timeNow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
// You can set the number of oscillators (1 to 3) and the bit depth of the
|
|
||||||
// oscillators (8 or 12 bit). These settings must be defined before the
|
|
||||||
// inclusion of the MMM library files. They default to 1 osciallator
|
|
||||||
// and 8bit respectively.
|
|
||||||
|
|
||||||
#define NUM_OSCILLATORS 3
|
|
||||||
#define BIT_DEPTH 8
|
|
||||||
|
|
||||||
// The Music object is automatically instantiated when the header file is
|
|
||||||
// included. Make calls to the Music objects with "Music.function(args)".
|
|
||||||
// You still need to call Music.init() in the setup() function below.
|
|
||||||
#include <Music.h>
|
|
||||||
|
|
||||||
int delayTime = 100;
|
|
||||||
int cnt = 0;
|
|
||||||
float baseFrequency = 110;
|
|
||||||
long timeNow;
|
|
||||||
long lastTime = 0;
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
// We initialise the sound engine by calling Music.init() which outputs a tone
|
|
||||||
Music.init();
|
|
||||||
Music.setFrequency(220);
|
|
||||||
Music.setDetune(0.005); // ranges from 0.00 - 0.02 are usually good
|
|
||||||
Music.setWaveform(PULSE);
|
|
||||||
Music.setFrequency1(baseFrequency*1);
|
|
||||||
Music.setFrequency2(baseFrequency*1.3333);
|
|
||||||
Music.setFrequency3(baseFrequency*1.5);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
timeNow = millis();
|
|
||||||
if((timeNow-lastTime) > delayTime) {
|
|
||||||
cnt = cnt + 1;
|
|
||||||
if(cnt>16) cnt = 0;
|
|
||||||
float counter = float(cnt);
|
|
||||||
Music.setGain1(1.0/cnt);
|
|
||||||
Music.setGain2(1.0/cnt);
|
|
||||||
Music.setGain3(1.0/cnt);
|
|
||||||
lastTime = timeNow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
// You can set the number of oscillators (1 to 3) and the bit depth of the
|
|
||||||
// oscillators (8 or 12 bit). These settings must be defined before the
|
|
||||||
// inclusion of the MMM library files. They default to 1 osciallator
|
|
||||||
// and 8bit respectively.
|
|
||||||
|
|
||||||
#define NUM_OSCILLATORS 3
|
|
||||||
#define BIT_DEPTH 8
|
|
||||||
|
|
||||||
// The Music object is automatically instantiated when the header file is
|
|
||||||
// included. Make calls to the Music objects with "Music.function(args)".
|
|
||||||
// You still need to call Music.init() in the setup() function below.
|
|
||||||
#include <Music.h>
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
// We initialise the sound engine by calling Music.init() which outputs a tone
|
|
||||||
Music.init();
|
|
||||||
Music.setFrequency(110);
|
|
||||||
Music.setDetune(0.005); // ranges from 0.00 - 0.02 are usually good
|
|
||||||
Music.setWaveform(DIGI2);
|
|
||||||
Music.setSemitone1(0);
|
|
||||||
Music.setSemitone2(7);
|
|
||||||
Music.setSemitone3(-12);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,70 +0,0 @@
|
|||||||
// You can set the number of oscillators (1 to 3) and the bit depth of the
|
|
||||||
// oscillators (8 or 12 bit). These settings must be defined before the
|
|
||||||
// inclusion of the MMM library files. They default to 1 osciallator
|
|
||||||
// and 8bit respectively.
|
|
||||||
|
|
||||||
#define NUM_OSCILLATORS 3
|
|
||||||
#define BIT_DEPTH 8
|
|
||||||
|
|
||||||
// The Music object is automatically instantiated when the header file is
|
|
||||||
// included. Make calls to the Music objects with "Music.function(args)".
|
|
||||||
// You still need to call Music.init() in the setup() function below.
|
|
||||||
#include <Music.h>
|
|
||||||
|
|
||||||
boolean noteIsOn = false;
|
|
||||||
int n = 0;
|
|
||||||
int dir = 1;
|
|
||||||
int rootNote = 36;
|
|
||||||
int note[] = {0,2,3,5,7,9,10,12,14};
|
|
||||||
|
|
||||||
long time = 0;
|
|
||||||
long lastTime = 0;
|
|
||||||
long timeDelay = 80;
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
// We initialise the sound engine by calling Music.init() which outputs a tone
|
|
||||||
Music.init();
|
|
||||||
|
|
||||||
// Choosing the square wave oscillator.
|
|
||||||
Music.setWaveform(DIGI3);
|
|
||||||
|
|
||||||
// Detuning the three oscillators slightly to create movement in the sound.
|
|
||||||
Music.setDetune(0.008);
|
|
||||||
|
|
||||||
// enabling the envelope lets us define an gain envelope for the synth
|
|
||||||
// without having to specify it in our loop() or physics code.
|
|
||||||
Music.enableEnvelope();
|
|
||||||
Music.setAttack(8);
|
|
||||||
Music.setDecay(90);
|
|
||||||
Music.setSustain(48);
|
|
||||||
Music.setRelease(64);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
// This short routine loops note over and over again
|
|
||||||
time = millis();
|
|
||||||
if(time - lastTime > timeDelay) {
|
|
||||||
if(!noteIsOn) {
|
|
||||||
Music.noteOn(rootNote+note[n]);
|
|
||||||
noteIsOn = true;
|
|
||||||
n = n + dir;
|
|
||||||
if(n > 7)
|
|
||||||
{
|
|
||||||
dir = -1;
|
|
||||||
}
|
|
||||||
else if(n < 1)
|
|
||||||
{
|
|
||||||
dir = 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Music.noteOff();
|
|
||||||
noteIsOn = false;
|
|
||||||
}
|
|
||||||
lastTime = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,60 +0,0 @@
|
|||||||
// The Music and Midi objects are automatically instantiated when the header file is included.
|
|
||||||
// Make calls to the Music and Midi objects with "Music.function(args)" and "Midi.function(args)"
|
|
||||||
// You still need to call Music.init() and Midi.init() in the setup() function below.
|
|
||||||
#include <Music.h>
|
|
||||||
|
|
||||||
// variables for this sketch
|
|
||||||
float gain = 1.0;
|
|
||||||
float c = 220; // center frequency
|
|
||||||
float f1 = 1;
|
|
||||||
float f2 = 1;
|
|
||||||
float f3 = 1;
|
|
||||||
float m1 = 1.0011;
|
|
||||||
float m2 = 1.0012;
|
|
||||||
float m3 = 1.0013;
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
// We initialise the sound engine by calling Music.init() which outputs a tone
|
|
||||||
Music.init();
|
|
||||||
|
|
||||||
// Choosing the sine wave oscillator (optional since this is already the default).
|
|
||||||
Music.setWaveform(0);
|
|
||||||
|
|
||||||
// Setting the initial frequency for all three oscillators.
|
|
||||||
Music.setFrequency(c);
|
|
||||||
|
|
||||||
// Detuning the three oscillators slightly to create movement in the sound.
|
|
||||||
Music.setDetune(0.002);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
// This short routine creates a
|
|
||||||
|
|
||||||
Music.setFrequency1(c*f1);
|
|
||||||
Music.setFrequency2(c*f2);
|
|
||||||
Music.setFrequency3(c*f3);
|
|
||||||
|
|
||||||
f1 *= m1;
|
|
||||||
f2 *= m2;
|
|
||||||
f3 *= m3;
|
|
||||||
|
|
||||||
if(f1 > 4.0) m1 = 0.9745;
|
|
||||||
if(f2 > 4.0) m2 = 0.9852;
|
|
||||||
if(f3 > 4.0) m3 = 0.9975;
|
|
||||||
|
|
||||||
if(f1 < 0.25) m1 = 1.0754;
|
|
||||||
if(f2 < 0.25) m2 = 1.0573;
|
|
||||||
if(f3 < 0.25) m3 = 1.0386;
|
|
||||||
|
|
||||||
if(millis() > 10000) {
|
|
||||||
Music.setGain(gain);
|
|
||||||
gain *= 0.999;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
// You can set the number of oscillators (1 to 3) and the bit depth of the
|
|
||||||
// oscillators (8 or 12 bit). These settings must be defined before the
|
|
||||||
// inclusion of the MMM library files. They default to 1 osciallator
|
|
||||||
// and 8bit respectively.
|
|
||||||
|
|
||||||
#define NUM_OSCILLATORS 3
|
|
||||||
#define BIT_DEPTH 8
|
|
||||||
#define MIDI
|
|
||||||
|
|
||||||
// The Music object is automatically instantiated when the header file is
|
|
||||||
// included. Make calls to the Music objects with "Music.function(args)".
|
|
||||||
// You still need to call Music.init() in the setup() function below.
|
|
||||||
#include <Music.h>
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
// We initialise the sound engine by calling Music.init() which outputs a tone
|
|
||||||
Music.init();
|
|
||||||
Midi.init();
|
|
||||||
Music.enableEnvelope();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
// In order to send MIDI to the sketch, use the Music_Controls.pde Processing sketch
|
|
||||||
Midi.checkMidi();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -7,7 +7,7 @@
|
|||||||
#include <Music.h>
|
#include <Music.h>
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
MotorB.init();
|
MotorA.init();
|
||||||
Music.init();
|
Music.init();
|
||||||
|
|
||||||
Music.setWaveform(SINE);
|
Music.setWaveform(SINE);
|
||||||
@ -18,18 +18,15 @@ void setup(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
//for (int i; i < 512; i + 100){
|
MotorA.torque(200);
|
||||||
MotorB.torque(40);
|
|
||||||
Music.noteOn(map(analogRead(A3),0,1023,30,60));
|
Music.noteOn(map(analogRead(A3),0,1023,30,60));
|
||||||
delay (20);
|
delay (20);
|
||||||
Music.noteOff();
|
Music.noteOff();MotorA.torque(0);
|
||||||
MotorB.torque(0);
|
|
||||||
delay (150);
|
delay (150);
|
||||||
MotorB.torque(-70);
|
MotorA.torque(-200);
|
||||||
Music.noteOn(map(analogRead(A3),0,1023,35,65));
|
Music.noteOn(map(analogRead(A3),0,1023,35,65));
|
||||||
delay (40);
|
delay (40);
|
||||||
Music.noteOff();
|
Music.noteOff();MotorA.torque(0);
|
||||||
MotorB.torque(0);
|
MotorA.torque(0);
|
||||||
delay (750);
|
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 ?
|
||||||
|
|
||||||
|
}
|
||||||
@ -37,16 +37,5 @@ void loop(){
|
|||||||
MotorB.torque(foutB); // 1/4 or 1/2 ?
|
MotorB.torque(foutB); // 1/4 or 1/2 ?
|
||||||
|
|
||||||
Music.setGain(float(abs(xA-xB))/1024.0f);
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,7 +1,5 @@
|
|||||||
// Theremin
|
// Theremin
|
||||||
// A: pitch, B: volume
|
// A: pitch, B: volume
|
||||||
// or visa versa ??????????
|
|
||||||
|
|
||||||
|
|
||||||
#include <Music.h>
|
#include <Music.h>
|
||||||
int xA, xB; //10bit A/D gives 0-1023
|
int xA, xB; //10bit A/D gives 0-1023
|
||||||
@ -28,24 +26,11 @@ void loop(){
|
|||||||
//
|
//
|
||||||
frequency = pow(2,((p-69.)/12.))*440; //midi 69 -> 440hz
|
frequency = pow(2,((p-69.)/12.))*440; //midi 69 -> 440hz
|
||||||
Music.setFrequency(frequency);
|
Music.setFrequency(frequency);
|
||||||
//Music.setFrequency(xA);
|
|
||||||
|
|
||||||
xB = analogRead(A0);
|
xB = analogRead(A0);
|
||||||
volume = -float(xB)/256.; // B position
|
volume = -float(xB)/256.; // B position
|
||||||
volume = pow(10,volume);
|
volume = pow(10,volume);
|
||||||
Music.setGain(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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1,6 +1,4 @@
|
|||||||
//PluckOverlapHalf
|
//Pluck: one pluck at x=512
|
||||||
// BV 3 Feb 13
|
|
||||||
// one pluck at x=512
|
|
||||||
|
|
||||||
int x, fout, count;
|
int x, fout, count;
|
||||||
float f;
|
float f;
|
||||||
@ -19,7 +17,6 @@ void setup(){
|
|||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
x = analogRead(A0) - 512;
|
x = analogRead(A0) - 512;
|
||||||
//x = analogRead(A3) - 512;
|
|
||||||
if (forward){
|
if (forward){
|
||||||
if (x <= - w/2) f = 0;
|
if (x <= - w/2) f = 0;
|
||||||
if (x > -w/2 && x< w/2) f = - slope*(x + w/2);
|
if (x > -w/2 && x< w/2) f = - slope*(x + w/2);
|
||||||
@ -41,7 +38,7 @@ void loop(){
|
|||||||
}
|
}
|
||||||
fout = int(f);
|
fout = int(f);
|
||||||
MotorA.torque(fout);
|
MotorA.torque(fout);
|
||||||
//MotorB.torque(fout);
|
|
||||||
if(count++>=0){
|
if(count++>=0){
|
||||||
count=-1000; // wait 1000 loops before print
|
count=-1000; // wait 1000 loops before print
|
||||||
Serial.print(x,DEC);
|
Serial.print(x,DEC);
|
||||||
@ -1,7 +1,5 @@
|
|||||||
//plucks - four bumps
|
//Plucks - four bumps / three notes (400,500,600hz)
|
||||||
//three notes (400,500,600hz)
|
#define NUM_OSCILLATORS 3
|
||||||
//can't get Music.setGain1, etc to work only Music.setGain() starts all of them.
|
|
||||||
|
|
||||||
#include <Music.h>
|
#include <Music.h>
|
||||||
#include <Motor.h>
|
#include <Motor.h>
|
||||||
|
|
||||||
@ -13,8 +11,7 @@ void setup(){
|
|||||||
Music.init();
|
Music.init();
|
||||||
Music.setFrequency1(200);
|
Music.setFrequency1(200);
|
||||||
Music.setFrequency2(250);
|
Music.setFrequency2(250);
|
||||||
Music.setFrequency3(300);
|
Music.setFrequency3(300);
|
||||||
|
|
||||||
|
|
||||||
MotorA.init();
|
MotorA.init();
|
||||||
|
|
||||||
@ -23,31 +20,26 @@ void setup(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
|
|
||||||
xold = x;
|
xold = x;
|
||||||
x = analogRead(A0);
|
x = analogRead(A0);
|
||||||
|
|
||||||
// did xold - x include 125, 375, 625, 875? or x%250 = 125
|
|
||||||
|
|
||||||
if (((xold <= 125) && (x > 125)) || ((xold >= 125) && (x < 125))){
|
if (((xold <= 125) && (x > 125)) || ((xold >= 125) && (x < 125))){
|
||||||
Music.setGain1(1.0f);
|
Music.setGain1(1.0f);
|
||||||
//Music.setFrequency(200);
|
|
||||||
}
|
}
|
||||||
if (((xold <= 375) && (x > 375)) || ((xold >= 375) && (x < 375))){
|
if (((xold <= 375) && (x > 375)) || ((xold >= 375) && (x < 375))){
|
||||||
Music.setGain2(1.0f);
|
Music.setGain2(1.0f);
|
||||||
//Music.setFrequency(250);
|
|
||||||
}
|
}
|
||||||
if (((xold <= 625) && (x > 625)) || ((xold >= 625) && (x < 625))){
|
if (((xold <= 625) && (x > 625)) || ((xold >= 625) && (x < 625))){
|
||||||
Music.setGain3(1.0f);
|
Music.setGain3(1.0f);
|
||||||
//Music.setFrequency(300);
|
|
||||||
}
|
}
|
||||||
if (((xold <= 875) && (x > 875)) || ((xold >= 875) && (x < 875))){
|
if (((xold <= 875) && (x > 875)) || ((xold >= 875) && (x < 875))){
|
||||||
Music.setGain1(1.0f);
|
Music.setGain1(1.0f);
|
||||||
//Music.setFrequency(400);
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Music.setGain1(0.995f*Music.getGain1Float());
|
Music.setGain1(0.995f*Music.getGain1());
|
||||||
Music.setGain2(0.995f*Music.getGain2Float());
|
Music.setGain2(0.995f*Music.getGain2());
|
||||||
Music.setGain3(0.995f*Music.getGain3Float());
|
Music.setGain3(0.995f*Music.getGain3());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -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);
|
||||||
|
}
|
||||||
@ -1,6 +1,5 @@
|
|||||||
//FM synthes of a sort
|
//FM synthes of a sort
|
||||||
//hang on! it's unstable and wants to limit cycle
|
//hang on! (it's unstable and wants to limit cycle)
|
||||||
|
|
||||||
|
|
||||||
#include <Music.h>
|
#include <Music.h>
|
||||||
#define BIT_DEPTH 8 // gives us 16 Waveforms
|
#define BIT_DEPTH 8 // gives us 16 Waveforms
|
||||||
@ -9,7 +8,7 @@
|
|||||||
|
|
||||||
byte cnt;
|
byte cnt;
|
||||||
float xf, vf; //
|
float xf, vf; //
|
||||||
float k = 6.0; // increase FM frequency
|
float k = 10.0; // increase FM frequency
|
||||||
float b = 0.40; // increase
|
float b = 0.40; // increase
|
||||||
float Tf = .030 ; //integration time
|
float Tf = .030 ; //integration time
|
||||||
|
|
||||||
@ -26,6 +25,6 @@ void loop(){
|
|||||||
vf += (k * (analogRead(A0) - xf) - b*vf) * Tf;
|
vf += (k * (analogRead(A0) - xf) - b*vf) * Tf;
|
||||||
Music.setFrequency(100+vf);
|
Music.setFrequency(100+vf);
|
||||||
Music.setGain(.001*abs(vf));
|
Music.setGain(.001*abs(vf));
|
||||||
MotorA.torque(500-xf);
|
MotorA.torque(-500+xf);
|
||||||
//if(cnt++==0)Serial.println(.001*abs(vf));
|
//if(cnt++==0)Serial.println(.001*abs(vf));
|
||||||
}
|
}
|
||||||
@ -1,34 +0,0 @@
|
|||||||
//"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);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
12
software/lib/MMM/examples/Motor/_1_FlipFlop/_1_FlipFlop.ino
Normal file
12
software/lib/MMM/examples/Motor/_1_FlipFlop/_1_FlipFlop.ino
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include <Motor.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
MotorA.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
MotorA.torque(500);
|
||||||
|
delay(2000);
|
||||||
|
MotorA.torque(-500);
|
||||||
|
delay(2000);
|
||||||
|
}
|
||||||
@ -7,7 +7,10 @@
|
|||||||
#######################################
|
#######################################
|
||||||
|
|
||||||
Music KEYWORD1
|
Music KEYWORD1
|
||||||
Motor KEYWORD1
|
MotorA KEYWORD1
|
||||||
|
MotorB KEYWORD1
|
||||||
|
MotionA KEYWORD1
|
||||||
|
MotionB KEYWORD1
|
||||||
Midi KEYWORD1
|
Midi KEYWORD1
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
@ -49,6 +52,13 @@ setAttack KEYWORD2
|
|||||||
setDecay KEYWORD2
|
setDecay KEYWORD2
|
||||||
setSustain KEYWORD2
|
setSustain KEYWORD2
|
||||||
setRelease KEYWORD2
|
setRelease KEYWORD2
|
||||||
|
update_position KEYWORD2
|
||||||
|
update_mass_spring_damper KEYWORD2
|
||||||
|
torque KEYWORD2
|
||||||
|
direction KEYWORD2
|
||||||
|
stop KEYWORD2
|
||||||
|
start KEYWORD2
|
||||||
|
restart KEYWORD2
|
||||||
|
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user