/* Button Turns on and off a light emitting diode(LED) connected to digital pin 13, when pressing a pushbutton attached to pin 2. The circuit: - LED attached from pin 13 to ground - pushbutton attached to pin 2 from +5V - 10K resistor attached to pin 2 from ground - Note: on most Arduinos there is already an LED on the board attached to pin 13. created 2005 by DojoDave modified 30 Aug 2011 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Button Modified by Salama for Fab Academy 2018, Network and communication week. Changed pins and add serial */ #include // the number of the pushbutton pin const int ledPin7 = 7; // the number of the GREEN LED const int ledPin2 = 2; // the number of the BLUE LED SoftwareSerial myserial(5,6); //Rx,Tx // variables will change: char addr1 = '1'; // defining the address of the master 1 char addr2 = '2'; // defining the address of the master 2 void setup() { pinMode(ledPin7, OUTPUT); // initialize the LED pin as an output: pinMode(ledPin2, OUTPUT); myserial.begin(9600); //Initialize serial communication at baud rate of 9600 } void loop() { char val= myserial.read(); // read the serial port if (val==addr1) // if the value from serial port equal to the address 1 { digitalWrite(ledPin7, HIGH); //Turn the LED delay(500); myserial.write('3'); // Send number 3 to master 1 delay(200); myserial.write('4'); // Send number 3 to master 2 } else { digitalWrite(ledPin7,LOW); // turn LED off: digitalWrite(ledPin2,LOW); } }