//***********Protocol 12c*************** //PERIPHERAL BOARD //Original Code: Luis Alberto Hernández | Fab Lab Queretaro //Update Code: José Manuel Díaz | Fab Lab Anáhuac Puebla //Fab Academy 2022 //SAMD 11C14A #include //library for I2C byte own_address = 4; //set own adress. void setup() { Wire.begin(own_address); //enter the bus on specified address Wire.onReceive(receiveEvent);//set the board as reveicer and call a function called receiveEvent pinMode(2, OUTPUT);//set the pin of the led built in as an output pinMode(5,OUTPUT);//GREEN pinMode(8,OUTPUT);//RED pinMode(9,OUTPUT); //BLUE digitalWrite(2, LOW);//set the led builtin as low in the begining of the code digitalWrite(5, LOW);//GREEN digitalWrite(8, LOW);//RED digitalWrite(9, LOW);//BLUE }//close void setup void loop() { } void receiveEvent(int howMany) { while (Wire.available()) {//while the serial comunication is available using the wire library char c = Wire.read();//use character variable called "c" to store de value of the message sent from the host //------------------------------------------------ ALLOFF ---------------- if(c=='O') {//check the condition if the variable "c" equals the character "O" digitalWrite(2, LOW);//set the led builtin as low in the begining of the code digitalWrite(5, LOW);//GREEN digitalWrite(8, LOW);//RED digitalWrite(9, LOW);//BLUE digitalWrite(2,LOW);//Led PIN #2 LOW }//close first if //------------------------------------------------ GREEN ---------------- if(c=='G') {//check the condition if the variable "c" equals the character "G" digitalWrite(5, HIGH);//GREEN }//close if //------------------------------------------------ RED ---------------- if(c=='R') {//check the condition if the variable "c" equals the character "R" digitalWrite(8, HIGH);//RED }//close if //------------------------------------------------ BLUE ---------------- if(c=='B') {//check the condition if the variable "c" equals the character "B" digitalWrite(9, HIGH);//BLUE }//close if //-------------------------------------- LED PIN#2 HIGH ---------------- if(c=='H') {//check the condition if the variable "c" equals the character "H" digitalWrite(2,HIGH);//if this is thruth then turn LED on }//close if //--------------------------------------- LED PIN#2 LOW ---------------- else if(c=='L') // {other whise check if the value of the variable "c" is equal to the character "L" digitalWrite(2,LOW);// if this condition is true then turn LED off }//close if }//close while