#include #include #define IDLE 0 // Example uses only three scenes #define SCENE3 3 #define SCENE4 4 #define SCENE16 16 #define SERVO_PIN 12 #define I2C_ADDRESS 10 volatile int state = IDLE; Servo servo; void setup() { // Setup directions Wire.begin(I2C_ADDRESS); Wire.onReceive(receiveDirection); // Setup servo servo.attach(SERVO_PIN); servo.write(0); } void loop() { // This runs repeatedly if (state == IDLE) { // Do nothing } else if (state == SCENE3) { servo.write(90); state = IDLE; } else if (state == SCENE4) { servo.write(0); state = IDLE; } else if (state == SCENE16) { servo.write(90); delay(300); servo.write(30); delay(300); } } // This is run every time the director sends a command void receiveDirection(int numBytes) { // Read what value the director sends byte scene = Wire.read(); // Save the value into the state state = (int)scene; }