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.
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
}
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
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.
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.
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.