Professional Documents
Culture Documents
Easy Rainbow Robot Art Show
Easy Rainbow Robot Art Show
int DISPLAY_TIME = 100; // This controls how fast the colors change on the LED display. This
is measured in milliseconds.
#include <LiquidCrystal.h>
// This downloads the liquid crystal library which allows us to use commands on the LCD
LiquidCrystal lcd(12,11,5,4,3,2);
// This command lets the computer know which pin numbers correspond with the LCD.
void setup()
{
// The setup function runs when the sketch starts.
lcd.begin(16, 2);
// This informs the LiquidCrystal library that we are using an LCD that has 2 lines and 16
characters available to use.
lcd.clear();
// This command clears the LCD
lcd.print("Rainbow! :)");
// This is the command from the LiquidCrystal library that allows us to display a printed
message on the LCD. For our purposes the message printed
// is " Rainbow :)" . There is an invisible cursor that starts in the top row and the first column.
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}
//This command tells the pins to send out information.
void loop()
{
// The loop runs forever, unless interrupted or disconnected.
lcd.setCursor(0,1);
// This command sets the invisible cursor to the first column which is column 0, of the second
line which is line 1.
main Colors();
//A function that steps through all of the eight colors.
showSpectrum();
}
// The show spectrum smoothly steps through all the colors (red,green,and blue) projecting
different shades, and displaying a rainbow.
void showSpectrum()
{
// void show spectrum is only in function declarations. It does not return any information from
the function it was called from.
int x;
// Introduces x as a variable.
for (x = 0; x < 768; x++)
// This command gets numbers to count up or down. It will run using '{' or '}'.
{
showRGB(x); // Displays a single color on the LED
delay(10); // Delay for 10 ms (1/100th of a second)
}
}
if (color <= 255) // Checks for a condition and proceeds if the condition is "true"
{
red Intensity = 255 - color; // red turns on to off
green Intensity = color; // green turns off to on
blue Intensity = 0; // blue is always off
}
else if (color <= 511) // If the "if" statement results as false then you continue.
{
red Intensity = 0; // red is always off
green Intensity = 255 - (color - 256); // green turns on to off
blue Intensity = (color - 256); // blue turns off to on
}
else // color >= 512 // for everything do what it says under "else"
{
red Intensity = (color - 512); // red turns off to on
green Intensity = 0; // green is always turned off
blue Intensity = 255 - (color - 512); // blue turns on to off
}