/* 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 const int ledPin = 7; // the number of the LED pin const int buttonPin = 3; // the number of the pushbutton pin SoftwareSerial myserial(6,5); //Rx,Tx int buttonState = 0; // variables will change: char value = 0; // variable for reading the pushbutton status char address = '4'; // defining the address of the slave void setup() { pinMode(ledPin, OUTPUT); // initialize the LED pin as an output: pinMode(buttonPin, INPUT_PULLUP); // initialize the pushbutton pin as an input: myserial.begin(9600); //Initialize serial communication at baud rate of 9600 } void loop() { digitalWrite(ledPin, HIGH); char value= myserial.read(); // Read serial port if (value == address) // check if received number 3 { digitalWrite(ledPin, HIGH); //Turn the LED on delay(500); } buttonState = digitalRead(buttonPin); // read the state of the pushbutton value: if ( buttonState== LOW) { // check if the pushbutton is pressed. If it is, the buttonState is LOW myserial.write('2'); // send 2 to slave delay(500); } else { delay(100); } }