HAHA!
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
//Center
|
||||
//uses a variable force (pwm duty)
|
||||
//If it feels like a mountain - pushing away from center, then
|
||||
//reverse the motor leads
|
||||
//or for a quick fix in the code: change if(f < 0) to if (f > 0)
|
||||
|
||||
#include <Motor.h>
|
||||
|
||||
int pos; // position from analogRead
|
||||
int force; // computed from pos and k
|
||||
int k = 2; // spring constant
|
||||
int duty; // pwm duty for Timer1 (range 0 - 1023) 10-bit resolution
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
MotorA.torque(100); //is this necessary?
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
pos = analogRead(A0);
|
||||
|
||||
force = k * (512 - pos);
|
||||
duty = abs(force);
|
||||
duty = min(1023, duty);
|
||||
|
||||
MotorA.torque(duty);
|
||||
|
||||
if(force < 0) MotorA.direction(FORWARD);
|
||||
else MotorA.direction(BACKWARD);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
// "Pendulum" - spring-mass oscillator
|
||||
//
|
||||
|
||||
#include <TimerOne.h>
|
||||
#include <Motor.h>
|
||||
float tf = 0.002; //time constant was .002
|
||||
float kf = 0.2; // spring constant was .15
|
||||
float xf,vf,ff; // floating point versions of pendulum x and v and force
|
||||
int x, f; //int versions of position (from a/d) and force (to Pwm)
|
||||
int duty; // abs(f)
|
||||
byte c=0; //counts up until 0 then prints
|
||||
|
||||
float m = 0.3;
|
||||
float k = 0.01;
|
||||
|
||||
float damp = 0.09;
|
||||
|
||||
byte incomingByte;
|
||||
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
//Timer1.initialize(64); //64 microsecond period
|
||||
MotorA.torque(100); //initializes Timer1, pinModes
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
x = analogRead(0); // position [0-1024]
|
||||
ff = kf*(x - xf); // spring
|
||||
f = max(ff,-1024);
|
||||
f = min(f,1024);
|
||||
// if(f>0)digitalWrite(DIRA,HIGH);
|
||||
// else digitalWrite(DIRA,LOW);
|
||||
duty = abs(f);
|
||||
// Timer1.pwm(9,duty);
|
||||
MotorA.torque(duty);
|
||||
if(f>0)MotorA.direction(FORWARD);
|
||||
else MotorA.direction(BACKWARD);
|
||||
|
||||
// update (integrate) floating versions of xf and vf
|
||||
//integrate twice tf is deltaT/mass;
|
||||
vf += ff*tf;
|
||||
xf += vf*tf;
|
||||
|
||||
if(c++==0) // when c gets to 255 it next == 0 and send data
|
||||
{
|
||||
Serial.print(x);
|
||||
Serial.print(" ");
|
||||
Serial.print(xf);
|
||||
Serial.print(" ");
|
||||
Serial.println(ff);
|
||||
}
|
||||
|
||||
if (c++ == 0)Serial.println(x); //
|
||||
if (Serial.available() > 0) {
|
||||
//Serial.print(v);
|
||||
//Serial.print(" ");
|
||||
//Serial.println(x);
|
||||
incomingByte = Serial.read();
|
||||
//Serial.write(incomingByte);
|
||||
if(incomingByte == '\''){
|
||||
m = m * 1.1;
|
||||
Serial.println(m);
|
||||
}
|
||||
if(incomingByte == ';'){
|
||||
m = m / 1.1;
|
||||
Serial.println(m);
|
||||
}
|
||||
if(incomingByte == '.'){
|
||||
k = k / 1.1;
|
||||
Serial.println(k);
|
||||
}
|
||||
if(incomingByte == '/'){
|
||||
k = k * 1.1;
|
||||
Serial.println(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//#include <TimerOne.h>
|
||||
|
||||
#include <Motor.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
MotorA.torque(500);
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static int j = 1;
|
||||
static long cnt = 0;
|
||||
|
||||
if(cnt == 50000) {
|
||||
j = -1;
|
||||
MotorA.direction(FORWARD);
|
||||
} else if(cnt == 0) {
|
||||
j = 1;
|
||||
MotorA.direction(BACKWARD);
|
||||
}
|
||||
cnt += j;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
// This needs to be in all sketches at the moment
|
||||
#include <stdint.h>
|
||||
|
||||
// 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>
|
||||
#include <Midi.h>
|
||||
|
||||
// variables for this sketch
|
||||
|
||||
void setup() {
|
||||
|
||||
// We initialise the sound engine by calling Music.init() which outputs a tone
|
||||
Music.init();
|
||||
|
||||
// We initialize the MIDI engine by calling Midi.init()
|
||||
Midi.init();
|
||||
|
||||
// Choosing the sine wave oscillator (optional since this is already the default).
|
||||
Music.setSaw();
|
||||
|
||||
// Detuning the three oscillators heavily to create more movement in the sound.
|
||||
Music.setDetune(0.01);
|
||||
|
||||
// Enabling envelope, otherwise the synth would just play constant tones.
|
||||
Music.enableEnvelope();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// The MIDI must be used with the external
|
||||
// "IAC2Serial.pde" Processing sketch.
|
||||
Midi.checkMidi();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
// This needs to be in all sketches at the moment
|
||||
#include <stdint.h>
|
||||
|
||||
// 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>
|
||||
|
||||
void setup() {
|
||||
// We initialise the sound engine by calling Music.init() which outputs a tone
|
||||
Music.init();
|
||||
|
||||
Music.setSquare();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
// This needs to be in all sketches at the moment
|
||||
#include <stdint.h>
|
||||
|
||||
// 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
|
||||
boolean noteIsOn = false;
|
||||
int note = 48;
|
||||
|
||||
long time = 0;
|
||||
long lastTime = 0;
|
||||
long beatTime = 1000;
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
// We initialise the sound engine by calling Music.init() which outputs a tone
|
||||
Music.init();
|
||||
|
||||
// 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(0x0FFF);
|
||||
Music.setDecay(0x0004);
|
||||
Music.setSustain(0x00FF);
|
||||
Music.setRelease(0x0008);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// This short routine loops note over and over again
|
||||
time = millis();
|
||||
if(time - lastTime > beatTime) {
|
||||
if(!noteIsOn) {
|
||||
Music.noteOn(note);
|
||||
noteIsOn = true;
|
||||
} else {
|
||||
Music.noteOff();
|
||||
noteIsOn = false;
|
||||
}
|
||||
lastTime = time;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
|
||||
// This needs to be in all sketches at the moment
|
||||
#include <stdint.h>
|
||||
|
||||
// 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.setSine();
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
|
||||
// This needs to be in all sketches at the moment
|
||||
#include <stdint.h>
|
||||
|
||||
// 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
|
||||
boolean noteIsOn = false;
|
||||
int n = 0;
|
||||
int dir = 1;
|
||||
int rootNote = 48;
|
||||
int note[] = {0,2,3,5,7,9,10,12,14};
|
||||
|
||||
long time = 0;
|
||||
long lastTime = 0;
|
||||
long beatTime = 100;
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
// We initialise the sound engine by calling Music.init() which outputs a tone
|
||||
Music.init();
|
||||
|
||||
// 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(0x00FF);
|
||||
Music.setDecay(0x0008);
|
||||
Music.setSustain(0x00FF);
|
||||
Music.setRelease(0x0008);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// This short routine loops note over and over again
|
||||
time = millis();
|
||||
if(time - lastTime > beatTime) {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
|
||||
// This needs to be in all sketches at the moment
|
||||
#include <stdint.h>
|
||||
|
||||
// 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
|
||||
boolean noteIsOn = false;
|
||||
int n = 0;
|
||||
int dir = 1;
|
||||
int rootNote = 48;
|
||||
int note[] = {0,2,3,5,7,9,10,12,14};
|
||||
|
||||
long time = 0;
|
||||
long lastTime = 0;
|
||||
long beatTime = 100;
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
// We initialise the sound engine by calling Music.init() which outputs a tone
|
||||
Music.init();
|
||||
|
||||
// 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(70);
|
||||
Music.setSustain(24);
|
||||
Music.setRelease(90);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// This short routine loops note over and over again
|
||||
time = millis();
|
||||
if(time - lastTime > beatTime) {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
|
||||
// This needs to be in all sketches at the moment
|
||||
#include <stdint.h>
|
||||
|
||||
// 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
|
||||
boolean noteIsOn = false;
|
||||
int n = 0;
|
||||
int dir = 1;
|
||||
int rootNote = 26;
|
||||
int note[] = {0,2,3,5,7,9,10,12,14};
|
||||
|
||||
long time = 0;
|
||||
long lastTime = 0;
|
||||
long beatTime = 100;
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
// We initialise the sound engine by calling Music.init() which outputs a tone
|
||||
Music.init();
|
||||
|
||||
// Choosing the square wave oscillator instead of the sine wave.
|
||||
Music.setSquare();
|
||||
|
||||
// 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 > beatTime) {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
// This needs to be in all sketches at the moment
|
||||
#include <stdint.h>
|
||||
|
||||
// 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>
|
||||
|
||||
void setup() {
|
||||
// We initialise the sound engine by calling Music.init() which outputs a tone
|
||||
Music.init();
|
||||
|
||||
Music.setSquare();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
void serialEvent() {
|
||||
while (Serial.available()) {
|
||||
// get the new byte:
|
||||
|
||||
|
||||
|
||||
int inChar = (int)Serial.read();
|
||||
if (inChar == '\n') {
|
||||
stringComplete = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user