I have an array of four IR Break Beams that work perfectly in Arduino. I have the serial data going into a Max patch to trigger random audio samples. Currently in the Arduino serial monitor all of the IR Break Beams go down in one column instead of four. I have different numbers being output by each break beam to tell them apart. Does any one know how to split the different break beams into there own column? I tried doing this in max with the splice argument but it didnt work, I've been trying in arduino too but I cant figure it out either.
Any help would be great,
Thanks.
heres my code.
#define LEDPIN 13
#define SENSORPIN_A 4
#define SENSORPIN_B 5
#define SENSORPIN_C 6
#define SENSORPIN_D 7
// variables will change:
int sensorState_A = 0, lastState_A = 0;
int sensorState_B = 0, lastState_B = 0;
int sensorState_C = 0, lastState_C = 0;
int sensorState_D = 0, lastState_D = 0;
void setup()
{
// initialize the LED pin as an output:
pinMode(LEDPIN, OUTPUT);
// initialize the sensor pins as an input and enable internal pullup:
pinMode(SENSORPIN_A, INPUT_PULLUP);
pinMode(SENSORPIN_B, INPUT_PULLUP);
pinMode(SENSORPIN_C, INPUT_PULLUP);
pinMode(SENSORPIN_D, INPUT_PULLUP);
Serial.begin(9600);
}
void loop()
{
// read the state of the sensor:
sensorState_A = digitalRead(SENSORPIN_A);
sensorState_B = digitalRead(SENSORPIN_B);
sensorState_C = digitalRead(SENSORPIN_C);
sensorState_D = digitalRead(SENSORPIN_D);
// check if the sensor beam is broken
// if it is, the sensorState is LOW:
if (sensorState_A == LOW)
{
// turn LED on:
digitalWrite(LEDPIN, HIGH);
}
else
{
// turn LED off:
digitalWrite(LEDPIN, LOW);
}
if (sensorState_A && !lastState_A)
{
Serial.println("1");
}
if (!sensorState_A && lastState_A)
{
Serial.println("0");
}
lastState_A = sensorState_A;
if (sensorState_B == LOW)
{
// turn LED on:
digitalWrite(LEDPIN, HIGH);
}
else
{
// turn LED off:
digitalWrite(LEDPIN, LOW);
}
if (sensorState_B && !lastState_B)
{
Serial.println("3");
}
if (!sensorState_B && lastState_B)
{
Serial.println("2");
}
lastState_B = sensorState_B;
if (sensorState_C == LOW)
{
// turn LED on:
digitalWrite(LEDPIN, HIGH);
}
else
{
// turn LED off:
digitalWrite(LEDPIN, LOW);
}
if (sensorState_C && !lastState_C)
{
Serial.println("5");
}
if (!sensorState_C && lastState_C)
{
Serial.println("4");
}
lastState_C = sensorState_C;
if (sensorState_D == LOW)
{
// turn LED on:
digitalWrite(LEDPIN, HIGH);
}
else
{
// turn LED off:
digitalWrite(LEDPIN, LOW);
}
if (sensorState_D && !lastState_D)
{
Serial.println("7");
}
if (!sensorState_D && lastState_D)
{
Serial.println("6");
}
lastState_D = sensorState_D;
delay(250); // so we don't flood the serial port
}
Hey man, thanks for the code it works great in Arduino. However getting in to Max is alot harder, only the first IR sensor triggers signals. I think its just the comma in the serial window. Is there away that I can use the SEPARATOR argument with out the comma. Max can only really read numbers in the serial window, letters and special characters dont work. thanks again fro the code
I have just deleted the comma out of the code and have now just got numbers in the arduino serial window. However in Max all of the numbers still come out of the first inlet, the other 3 inlets now have numbers which is good but they dont change when I tirp the sensor i think i have 'assigned' to it. it only trips the first one, is that an issue in Max in need to resolve or is that again in Arduino?
I can upload the max patch if you want? I think the zl functions might work with the code you gave me, currently im using a floating number to get the serial data in to max.