Go Down

Topic: ping ))) code help (Read 938 times) previous topic - next topic


hey, i have been following this thread, and have been trying about myself. but one ting doesnt work,..

i am trying to do this with vdmx and if i have the ard. enviroment running and uploaded the code vdmx doesnt find a incoming singnal.

are you running this trough a other programme before reading it in your video software?


hey - yeah, I am using a programme called MidiPipe http://www.macupdate.com/info.php/id/10541, although this is only necessary if there is some form of midi filtering needed. If its coming out of the ping sensor correctly then it should come up on vdmx. To make sure your computer is receiving MIDI data (correctly) I use a little app called MidiMonitorhttp://www.snoize.com/MIDIMonitor/ which shows what data is coming in on what channel etc. once you establish that there is something coming in correctly the next place to check is the IAC midi driver (applications/utility/audio midi setup) is turned on and online.  


mem: the map function seems like the perfect solution but I have been trying to implement it with little success:

Code: [Select]
/* New Variables */
int delay_time = 40; // delay for this amount each write cycle.
byte MIDI_channel = 1;
byte cc_number = 127;

byte printing_byte = 0;
int baud_rate = 31250;

/* Ultrasound Sensor
* Reads values (00014-01199) from an ultrasound sensor (3m sensor)
* and writes the values to the serialport.
* http://www.xlab.se | http://www.0j0.org
* copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp


int ultraSoundSignal = 11; // Ultrasound signal pin
int val = 0;
int ultrasoundValue = 0;
int timecount = 0;
int brightness = 0;// Echo counter
int ledPin = 13;
int redPin = 2;
int bluePin = 3;
int yellowPin = 4;
int whitePin = 10;// LED connected to digital pin 13

void setup() {
 pinMode(ledPin, OUTPUT);
 pinMode(redPin, OUTPUT);
 pinMode(bluePin, OUTPUT);
 pinMode(yellowPin, OUTPUT);
 pinMode(whitePin, OUTPUT);            // Sets the digital pin as output
 MIDI_channel = MIDI_channel - 1;

void loop() {
 timecount = 0;
 val = 0;
 pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output

 /* Send low-high-low pulse to activate the trigger pulse of the sensor
  * -------------------------------------------------------------------

 digitalWrite(ultraSoundSignal, LOW); // Send low pulse
 delayMicroseconds(2); // Wait for 2 microseconds
 digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
 delayMicroseconds(5); // Wait for 5 microseconds
 digitalWrite(ultraSoundSignal, LOW); // Holdoff

 /* Listening for echo pulse
  * -------------------------------------------------------------------

 pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
 val = digitalRead(ultraSoundSignal); // Append signal value to val
 while(val == LOW) { // Loop until pin reads a high value
   val = digitalRead(ultraSoundSignal);

 while(val == HIGH) { // Loop until pin reads a high value
   val = digitalRead(ultraSoundSignal);
   timecount = timecount +1;            // Count echo pulse time

 /* Writing out values to the serial port
  * -------------------------------------------------------------------

 ultrasoundValue = timecount;
ultrasoundValue = map(ultrasoundValue, 0, 127, 127, 0);

// Append echo pulse time to ultrasoundValue
 if((ultrasoundValue >= 110) && (ultrasoundValue < 127)){
   digitalWrite(redPin, HIGH);
   digitalWrite(redPin, LOW);
   digitalWrite(bluePin, HIGH);
   digitalWrite(bluePin, LOW);
   digitalWrite(redPin, HIGH);
   digitalWrite(redPin, LOW);
   digitalWrite(bluePin, HIGH);
   digitalWrite(bluePin, LOW);

 digitalWrite(redPin, LOW);
 digitalWrite(bluePin, LOW);  


 ultrasoundValue = ultrasoundValue - 14;
 ultrasoundValue = ultrasoundValue / 5;
 brightness = ultrasoundValue;
 analogWrite(whitePin, brightness);
 if(ultrasoundValue > 127) {
   printing_byte = 127;
 else {
 printing_byte = ultrasoundValue ;
 Serial.print(B10110000 + MIDI_channel,BYTE);


 /* Lite up LED if any value is passed by the echo pulse
  * -------------------------------------------------------------------

 if(timecount > 0){
   digitalWrite(ledPin, HIGH);

 /* Delay of program
  * -------------------------------------------------------------------


All I want is for the MIDI data to be inversed, so instead of going from 0 to 127 it went the opposite way.

On a slightly side note - I have now attached a length of LED's that get brighter when the person comes closer to the sensor, however the fade is a bit jerky (i.e. not like a smooth fade) - is that because the midi data is 0 - 127 and the LED wants to have the brightness controlled from 0 to 255? or is it just bound to be a bit jerky.


Jun 04, 2009, 11:06 pm Last Edit: Jun 05, 2009, 09:32 am by AWOL Reason: 1
All I want is for the MIDI data to be inversed, so instead of going from 0 to 127 it went the opposite way

As I said earlier...if you've got a value in, say "midiData" that runs from 0...127, then

inverseMidiData = 127 - midiData;

That's the handy "subtract" operation.

If the LED fade is a bit jerky, you could try a simple rolling average over, say eight samples.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.


I would like to use this sensor and part of this code to simply start and control volume from an MP3 track. I was going to buy the wav shield kit from adafruit to do it. Could anyone tell me how to modify the code to do that? (I'm pretty new to all of this)

Go Up