// See: //http://www.instructables.com/id/Control-RGB-LED-with-arduino-and-Processing/?ALLSTEPS // Repaired (somewhat) : C. D'Arcy, 2015 10 31 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Output int redPin = 9; // Red LED, connected to digital pin 9 int greenPin = 10; // Green LED, connected to digital pin 10 int bluePin = 11; // Blue LED, connected to digital pin 11 int inByte; int wait = 10; //10ms void setup() { pinMode(redPin, OUTPUT); // sets the pins as output pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); Serial.begin(9600); } void outputColour(int red, int green, int blue) { analogWrite(redPin, red); analogWrite(bluePin, blue); analogWrite(greenPin, green); } // returns an array (bad form) // See: https://www.eskimo.com/~scs/cclass/int/sx5.html int* getColour() { int* colour; int i = 0; while (i < 3) { if (Serial.available() > 0) { colour[i] = Serial.read(); i++; } } return colour; } // Main program void loop() { if (Serial.available() > 0) { int* one; one = getColour(); outputColour(one[0], one[1], one[2]); } delay(wait); }