Hello,
If I have an Arduino 1 with 2 switches, lets say D2 and D3, and Arduino 2 with 2 leds on D2 and D3, how could I get Arduino 1 to send data via Tx, and have Arduino 2 Rx the data, decipher it, and light the correct led?
This is what I know how to do. The one thing I don't know how to do is send a few variables, and receive a few variables.
Arduino 1 (Or something like this):
int button1;
int button2;
void setup(){
Serial.begin(9600);
pinMode(2,INPUT);
pinMode(3,INPUT);
}
void loop(){
button1=digitalRead(2);
button2=digitalRead(3);
Serial.write(?);
delay(16);
}
Arduino 2 (Or something like this):
int led1;
int led2;
void setup(){
Serial.begin(9600);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
}
void loop(){
if (Serial.avalaible()>0){
// read and set to variables
}
if (led1==1){
digitalWrite(2,HIGH);
}else{
digitalWrite(2,LOW);
}
if (led2==1){
digitalWrite(3,HIGH);
}else{
digitalWrite(3,LOW);
}
delay(16);
}