// Refer to the "Wire Master Writer" example for use with this // Created 29 March 2006 // This example code is in the public domain. #include #include //include libraries #define attiny_address 0x00 //attiny address variable Servo ESC; // create ESC object to control a servo void setup() { Wire.begin(attiny_address); // join i2c bus with address #4 Wire.onReceive(receiveEvent); // register event Serial.begin(9600); // start serial for output } void loop() { delay(100); } // function that executes whenever data is received from master // this function is registered as an event, see setup() void receiveEvent(int howMany) { while(1 < Wire.available()) // loop through all but the last { int x = Wire.read(); // receive byte as an integer Serial.print(x); // print the character if (x > 150) { ESC.write(1200); Serial.print("Accelerometer data recieved. Motor running at 1200rpm"); } else { Serial.print("Error. Accelerometer data NOT recieved. Motor not running."); } delay(1000); //waits } }