PD

Hello all

Im trying to set up an IR beam that when broken triggers a patch in PD

I think I have the circuit right but im not sure about my Code and also how to make it work with the PD example PD_inputs to PD in the help browser.

Can anyone help.

This is my code so far

int ledPin = 13; int IRpin = 7; int vald = 0; int writeChar = 65; void setup() { pinMode(ledPin, OUTPUT); pinMode(IRpin, INPUT); Serial.begin(9600); }

void loop() { vald = digitalRead(IRpin); writeChar = 65;

digitalWrite(ledPin, HIGH); Serial.println(); writeChar = writeChar + 1; } }

I have just being trying to work it out using other peoples examples for different things.

Im very new to this so its taking me ages trying to work it out.

Thanks

I have no idea what PD is but I can see that your program won’t compile because you have an extra } after writeChar = writeChar + 1;

Also, you are not sending writeChar to the serial port, did you want something like: Serial.println(writeChar);

Yeah thanks

I spotted the extra } and removed it which helped. I can upload my code to the arduino but i dont know if its not communicating with PureData (programming software similar to Max/MSP) because of my circuit or beacuse I have the code wrong.

Thanks for you help though.

Your code will send all characters in sequence regardless of the value of the IRpin, vald is not used by your program.

If your stuck, a brief explanation of what should happen when the pin is read would make it easier to provide guidance.

Thanks

When the beam is broken it is supposed to trigger a 'bang' in PD to set off a series of piano notes acording to the patch i designed.

Its part of an installation im designing.

Any help on the code is useful thanks.

The following may help you get started:

int ledPin = 13;                  
int IRpin = 7;        
char Patch[] = "whatever needs to be sent to PD"; 

void setup() 
{ 
  pinMode(ledPin, OUTPUT);   
  pinMode(IRpin, INPUT); 
  Serial.begin(9600);        
} 

void loop() 
{ 
  if(digitalRead(IRpin))
  { 
      // here if IRPin goes high
      digitalWrite(ledPin, HIGH);    
      Serial.println(Patch);          // send the patch to the serial port
  }
  else
     digitalWrite(ledPin, LOW); // turn the LED off when IRPin goes low 
     
  // you may want to add a delay here depending on how quickly IRpin turns on and off    
}

Thanks

This is helping.

When you say : "char Patch[] = "whatever needs to be sent to PD";" what is this refering to? a value from the IRpin or does it need to know what i want it to read. as in - I want an "on" signal when the beam is broken. If so, how would I put this.

Thanks a lot. IM a complete beginner and this is helping to work it out

Cheers tim

digitalRead(IRpin)) will be true (the code in the if statement will be executed) when the value on the IRPin gets close to 5 volts. This can be your 'on' signal.

I assume you want to send some serial data when this happens. If so, you can set the string variable Patch to what is appropriate.

If this is not clear then parhaps if you write out the logical steps or actions that you want your program to perform it would be easier to guide you.

OKay

I think Im getting there! Sorry for not getting it!

This is what I want to do. Im trying to set up an IR beam across a corridor so that when the beam is in place it is sending no signal to PD. however when the beam is broken it sends an on signal or triggers a 'bang' in PD to set the PD patch that I have designed off. The way the patch is designed it turns itself off after a time delay that I have set (currently at 10 seconds but this can be altered).

So what I need is someway of programming the arduino to simply trigger something that will continue playing for a set amount of time even though the beam re-connects. Almost in the same way as security lights or a trip sensor burglar alarm would work.

I hope this is clearer. I would really like to be able to work all this out for myself but i think its going to take some time to get to that level of understanding. Thanks for your help.

Tim

Hi Tim, it will help if you break the problem down into parts.

You can start off by modifying the posted code as necessary to send a serial message when the beam is broken. You can use the serial monitor in the Arduino IDE to see that a serial message has been sent. At this point, it doesn't matter what is sent, you just want to get the code to detect the beam breaking and then send something.

When you get that working, you can then move on to sending the correct serial message to play sounds. Someone here that knows something about PD may be able to provide further guidance when you get to that stage.