Arduino Workshop 5 - Communication

We will use the same circuit as exercise 1, but this time we are speaking from the computer to the Arduino. We will still be using serial communication which the Arduino is going to read it in one character at a time over each loop.

Exercise 2 - Speaking to the Arduino from the computer

We will use Max MSP again, but this time we are going to send data from Max to control the RGB LED plugged into the Arduino. 

  • Paste the following code into the Arduino IDE and upload it. Then download this Max patch, open it and follow the instructions inside.
This sketch will allow us to receive a list of RGB 
values from our MaxMSP patch and parse (seperate) 
them to control an RGB LED. Follow the instructions
in the Max patch

Luke Woodbury 16 January 2016


//variables to store RGB values
int redVal = 0;
int greenVal = 0;
int blueVal = 0;

//constants (i.e. they won't change) to store LED 
//RGB pins
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;

void setup() {
//start serial to listen for Max data

//set the pins as PWM output to fade LEDs
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(redPin, OUTPUT);

void loop() {
  //parse (split) the incoming list of 3 values
  //and store them in the variables
  redVal = Serial.parseInt();
  greenVal = Serial.parseInt();
  blueVal = Serial.parseInt();
  //write out the values to the LED pins
  analogWrite(greenPin, greenVal);
  analogWrite(bluePin, blueVal);    
  analogWrite(redPin, redVal);