I hooked up this program to two Arduino's. It works ok, but is there A faster way to send the serial data.
I have to hold down the switch, to make the led go on. I would like it more like Momentary Push Button switch (High when pushed, Low when off).
int LedPin = 13;
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()
{ // Down here where it belongs
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
Serial.print('1');
}
else
{
Serial.print('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!");
}
}