//Original Code: Jordan Gowen https://fab.cba.mit.edu/classes/863.20/Architecture/people/JordanGowen/week12.html //Update José Manuel Díaz - Fab Academy 2022 //Control of an RGB LED //JOSAMD 1.0 //SAMD 11C14A int Red = 5; //Let's add a variable to each pin to identify it more easily int Gre = 8;//New name = Pin number according to Microprocessor data sheet int Blu = 4;// void setup() { Serial.begin(9600); //Start serial communication @9600 bps pinMode(Blu, OUTPUT); //Here the pins are declared as outputs pinMode(Red, OUTPUT); //Here the pins are declared as outputs pinMode(Gre, OUTPUT); //Here the pins are declared as outputs } void loop(){ if(Serial.available()){ // If data is available to read char val = Serial.read();//Read the characters that arrive from the serial port if(val == 'r'){ //If an "R" is received from processing, then... analogWrite(Red, 250);//Turn on the led with analog writing } if(val == 'b'){ //If an "B" is received from processing, then... analogWrite(Blu, 250);//Turn on the led with analog writing } if(val == 'g'){ //If an "G" is received from processing, then... analogWrite(Gre, 250);//Turn on the led with analog writing } if(val == 'f'){ //If an "R" is received from processing, then... analogWrite(Red, LOW); //Turn off all led analogWrite(Blu, LOW); analogWrite(Gre, LOW); } } }