/*I2C Master write code*/ /*List of the lubraries included in the project*************************************************/ #include //Arduino library that enables I2C functionality /*defining local variables that will be used in the program*************************************/ String readString; // defining the string /*List of the variables that will be sent via I2C***********************************************/ byte I2C_OnOff; //defining the variable that will be sent /*Setup loop************************************************************************************/ void setup() { Wire.begin(); // join I2C bus (address here is optional for master) Serial.begin(9600); Serial.println("Type Red On to turn on the Red LED and Red Off to shut it down!"); // Instruction text and check off what is loaded } /*Main loop**************************************************************************************/ void loop() { /*While that loops through input from the serialmonitor input and assembels them to the string***/ while (Serial.available()) { delay(2); // Delay that allows byte to arrive in input buffer char c = Serial.read(); // Reads the char form serial monitor readString += c; // Add the char to the readString string } /************************************************************************************************/ /*IF THEN ELSE that depending on the input text sets te value to I2C_OnOff***********************/ if(readString == "Red On" or readString == "Red ON" or readString == "Red on") { I2C_OnOff = 1; } else if(readString == "Red Off" or readString == "Red OFF" or readString == "Red off") { I2C_OnOff = 0; } /*IF for printing out the users input************************************************************/ /************************************************************************************************/ if (readString.length() >0) // while string lenght is not 0 { Serial.println(readString); // prints out the user inputed string readString=""; // deletes/empties the string } /*IF for printing out the users input************************************************************/ /************************************************************************************************/ Wire.beginTransmission(1); // Oening the transmition chanel to device with the name 1 Wire.write(I2C_OnOff); // Sending the desired information via I2C to the slave device Wire.endTransmission(); // Closeing the transmition chanel /************************************************************************************************/ }