This tutorial will show you how to control the colour of an RGB LED using Sketch and a programming language called Streams.
Connect the RGB LED to the Galileo as shown in the following diagram:
The RGB LED combines of three LEDs: a red one, a green one and a blue one. Each of these LEDs is controlled by a PWM pin (indicated by a "~" on the board), so that it's brightness cna be controlled. As these are promary colours, by controling the "brightness" of each LED, the overall colour can be set.
The following sketch will cycle through Red, Green, and Blue:
#include <Arduino.h>
int redPin = 3;
int greenPin = 5;
int bluePin = 6;
void setColor(int red, int green, int blue)
{
analogWrite(redPin,255-red);
analogWrite(greenPin,255-green);
analogWrite(bluePin, 255-blue);
}
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
setColor(255, 0, 0); // red
delay(1000);
setColor(0, 255, 0); // green
delay(1000);
setColor(0, 0, 255); // blue
delay(1000);
setColor(255, 255, 0); // yellow
delay(1000);
setColor(80, 0, 80); // purple
delay(1000);
setColor(0, 255, 255); // aqua
delay(1000);
}
Push the code to your device. CHALLENGE: Change the code to include your own colours.
In this section we'll use a programming approach callled streams to control the RGB LED. Wyliodrin provides the ability to write Streams programs.
Create the following streams program by selecting and configuring the correct nodes:
Now create a Dashboard to supply the signals (i.e. red, green blue) for the program.
If all is well, you should now be able to delpoy the application to the Galileo and control it using the dashboard.
Programming with Streams lab, IoT Summer School 2015, Innovations lab Adafruit Arduino Lessons