Is the way to send tx and rx data, to one (Arduino) to the other (Arduino).
With Button input of High, to Arduino to tx to rx to Arduino to led. And The Other Way Around
Button input of High, to Arduino to tx to rx to Arduino to led.
Send and input data....
int LedPin = 13;
const int buttonPin = 10;
int TxPin = 0;
int RxPin = 1;
int buttonState = 0;
void setup ()
{
Serial.begin(9600);
pinMode (LedPin, OUTPUT);
pinMode (buttonPin, INPUT);
pinMode (TxPin, INPUT);
pinMode (RxPin, OUTPUT);
}
void loop(){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
Serial.println(TxPin == 1);
}
else {
Serial.println(TxPin == 0);
}
{
while(Serial.available() == 0);
int Rx = Serial.read() - '0';
if (Rx == 1)
{
Serial.println("Led is on");
digitalWrite(LedPin,HIGH);
}
else if (Rx == 0)
{
Serial.println("Led is off");
digitalWrite(LedPin,LOW);
}
else
{
Serial.println("Invalid!");
}
Serial.flush() ;
}
}