OUR PROJECT
Theremin-like instrument that can play several different scales.
Desired structure.
Functions
Where we're at.
OUR MATERIALS
At the moment what we have on hand is cardboard and plastic. Cardboard is easier to cut so we're going with that. We're not too sure of the structure. Perhaps something more compact would be best.
OUR CIRCUIT
It didn't change much since last time. We haven't added the second sensor yet. It's taken us a while to figure out this one.
OUR CODE
//Sound project
#include <MIDIUSB.h>
#include <pitchToNote.h>
int baseNote = 60;
int trigPin1 = 4;
int echoPin1 = 3;
//int trigPin2 = 4;
//int echoPin2 = 3;
int lastDistance = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin (9600);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
// pinMode(trigPin2, OUTPUT);
// pinMode(echoPin2, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
byte note = baseNote;
long duration1, distance1;
digitalWrite(trigPin1, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
distance1 = (duration1) / 29.1;
Serial.print ( "Sensor1 ");
Serial.print ( distance1);
Serial.println("cm");
delay(2000);
if (distance1 != lastDistance) {
delay(5); // debounce delay
if (distance1 > 0 && distance1 <= 10) {
midiCommand(0x90, note, 127);
}
if (distance1 > 11 && distance1 <= 20) {
note = note +2;
midiCommand(0x90, note, 127);
}
if (distance1 > 21 && distance1 <= 30) {
note = note +4;
midiCommand(0x90, note, 127);
}
if (distance1 > 31 && distance1 <= 40) {
note = note +5;
midiCommand(0x90, note, 127);
}
if (distance1 > 41 && distance1 <= 50) {
note = note +7;
midiCommand(0x90, note, 127);
}
if (distance1 > 51 && distance1 <= 60) {
note = note +9;
midiCommand(0x90, note, 127);
}
if (distance1 > 61 && distance1 <= 70) {
note = note +11;
midiCommand(0x90, note, 127);
}
else {
midiCommand(0x80, note, 0);
}
}
}
void midiCommand(byte cmd, byte data1, byte data2) {
// First parameter is the event type (top 4 bits of the command byte).
// Second parameter is command byte combined with the channel.
// Third parameter is the first data byte
// Fourth parameter second data byte
midiEventPacket_t midiMsg = {cmd >> 4, cmd, data1, data2};
MidiUSB.sendMIDI(midiMsg);
}
OUR QUESTIONS
* How do we send a midiMessage that is able to play sounds in different scales in something other than piano?
* How do we add a byte to the message that indicates a change in the pitch?
* How do we sustain the note by just mapping the sensor?
* Is there a way to pre-configure all the scales, using the same logic?
* Will be necessary to add a smooth transition when mapping the sensor?
OUR TIPS:
-Do not use near Wi Fi signals the sensor just stops measuring correctly.
-The path to follow the sound needs to be constant. At the same height making a line. If you move up and down it stops reading.
Commentaires