#include // This is the library we will be using to allow the board to understand networking instructions. byte own_address = 2; // This is the address assigned to the board, it will be used to differentiate it from the other boards. int i = 0; int servo = 4; int led = 2; int angle; int pwm; void setup() { Serial.begin(115200); Wire.begin(own_address); // Declare that this is the board called by a certain address. Wire.onReceive(receiveEvent); // Instruct what to do when receiving information. pinMode(servo, OUTPUT); // pinMode(led, HIGH); digitalWrite(servo, LOW); // } void loop() { void receiveEvent(int howMany) // What to do when receiving information. { while (Wire.available()) // While it is being called. { char c = Wire.read(); // Read the character sent by the main board. if(c=='A') // { digitalWrite(led, HIGH); for (angle = 0; angle <= 140; angle += 5) { pwm = (angle*11) + 500; // Convert angle to microseconds digitalWrite(servo, HIGH); delayMicroseconds(pwm); digitalWrite(servo, LOW); delay(50); // Refresh cycle of servo } } if(c=='S') { digitalWrite(led, LOW); for (angle = 140; angle >= 0; angle -= 5) { pwm = (angle*11) + 500; // Convert angle to microseconds digitalWrite(servo, HIGH); delayMicroseconds(pwm); digitalWrite(servo, LOW); delay(50); } } } } }