Thanks for the help! (Especially @Robin2)
I'm using two Arduino Unos, and the first one needs to send a range of about 5 different commands to the second one, but I don't need any data to come back the other way. The first board is receiving data from my phone via bluetooth (I'm using a JY-MCU hooked up to pins 0 and 1) - this is how I'm controlling the robot.
I only have space to use pin 2 on each board (all the other pins are being used). A mega would have been a good idea, but it's a bit too late now :/. If I'm not mistaken, softwareSerial needs two pins on each board, and in any case, I don't need to send information in that kind of detail.
I think I may have found a rudimentary solution: I am setting board 1 pin 2 HIGH for a certain length of time, then setting it LOW again. On board two, I have a bunch of "if"s within each other, which basically set a variable to a certain value, depending on how long pin 2 was HIGH for. I know that sounds like a roundabout way of doing it, but that's just to give you an idea of what sort of thing I am looking at. If that's a bit confusing I've included the code below.
If anyone knows a better or more efficient way, please let me know! Thanks again
Board 1 Code:
void setup() {
pinMode(2,OUTPUT);
}
void loop() {
digitalWrite(2, HIGH);
delay(10);
digitalWrite(2, LOW);
delay(2000);
digitalWrite(2, HIGH);
delay(20);
digitalWrite(2, LOW);
delay(2000);
digitalWrite(2, HIGH);
delay(30);
digitalWrite(2, LOW);
delay(2000);
}
Board 2 Code:
int val;
void setup() {
pinMode(2,INPUT);
Serial.begin(9600);
val = 0;
}
void loop() {
if(digitalRead(2) == 1){
val = (val+1);
delay(15);
if(digitalRead(2) == 1){
val = (val+1);
delay(10);
if(digitalRead(2) == 1){
val = (val+1);
delay(10);
}
}
}
if (val>0){
Serial.println(val);
val = 0;
}
}
Basically prints 1, then 2, then 3, every 2 seconds. Feedback?