/* Sketch receives a byte and compares it with a hardcoded address. If the address matches the byte, an 'a' for ack is sent back and the LED is toggled. Makes use of software serial library as we need to tristate the Tx line between sends. */ #include const byte rxPin = 1; const byte txPin = 0; // Set up a new SoftwareSerial object SoftwareSerial mySerial (rxPin, txPin); const int ledPin = 3; const char address = '0'; char input; int ledState = LOW; void setup() { // Define pin modes for TX and RX pinMode(rxPin, INPUT); pinMode(txPin, INPUT); pinMode(ledPin, OUTPUT); // Set the baud rate for the SoftwareSerial object mySerial.begin(9600); mySerial.listen(); } void loop() { if (mySerial.available() > 0) { input = mySerial.read(); if (input == address) { // toggle on command ledState = !ledState; // send Ack pinMode(txPin, OUTPUT); mySerial.print('a'); pinMode(txPin, INPUT); } } digitalWrite(ledPin, ledState); }