of 5
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.

easy rainbows backups backup

Category:

Documents

Publish on:

Views: 70 | Pages: 5

Extension: PDF | Download: 0

Share
Description
const int RED_PIN = 6; const int GREEN_PIN = 7; const int BLUE_PIN = 8; // These are values that will never change. The integers above are the colors that are displayed on the LED in different shades. The numbers set equal to these integers are the //corresponding outlets on the Arduino board for the wires connected to the LED. (defines the pins). int DISPLAY_TIME = 100; // This controls how fast the colors change on the LED display. This is measured in milliseconds. #include
Transcript
   const int RED_PIN = 6; const int GREEN_PIN = 7; const int BLUE_PIN = 8; // These are values that will never change. The integers above are the colors that are displayed on the LED in different shades. The numbers set equal to these integers are the //corresponding outlets on the Arduino board for the wires connected to the LED. (defines the pins). 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 main Colors() { //Begins the main color function. digitalWrite(RED_PIN, LOW); // turn off LED (specific color) digitalWrite(GREEN_PIN, LOW); // turn off LED (specific color) digitalWrite(BLUE_PIN, LOW); // turn off LED (specific color) delay(1000); // Wait for one second. digitalWrite(RED_PIN, HIGH); // turn on LED (specific color) digitalWrite(GREEN_PIN, LOW);// turn off LED (specific color) digitalWrite(BLUE_PIN, LOW);// turn off LED (specific color) delay(1000); // Wait for one second. // Green (turn just the green LED on): digitalWrite(RED_PIN, LOW); // turn off LED (specific color) digitalWrite(GREEN_PIN, HIGH); // turn on LED (specific color) digitalWrite(BLUE_PIN, LOW); // turn off LED (specific color) delay(1000); // Wait for one second. // Blue (turn just the blue LED on): digitalWrite(RED_PIN, LOW); // turn off LED (specific color)   digitalWrite(GREEN_PIN, LOW); // turn off LED (specific color) digitalWrite(BLUE_PIN, HIGH); // turn on LED (specific color) delay(1000); // Wait for one second. // Yellow (turn red and green on): digitalWrite(RED_PIN, HIGH); // turn on LED (specific color) digitalWrite(GREEN_PIN, HIGH); // turn on LED (specific color) digitalWrite(BLUE_PIN, LOW); // turn off LED (specific color) delay(1000); // Wait for one second. // Cyan (turn green and blue on): digitalWrite(RED_PIN, LOW); // turn off LED (specific color) digitalWrite(GREEN_PIN, HIGH); // turn on LED (specific color) digitalWrite(BLUE_PIN, HIGH); // turn on LED (specific color) delay(1000); // Wait for one second. // Purple (turn red and blue on): digitalWrite(RED_PIN, HIGH); // turn on LED (specific color) digitalWrite(GREEN_PIN, LOW); // turn off LED (specific color) digitalWrite(BLUE_PIN, HIGH); // turn on LED (specific color) delay(1000); // Wait for one second. // White (turn all the LEDs on): digitalWrite(RED_PIN, HIGH); // turn on LED (specific color) digitalWrite(GREEN_PIN, HIGH); // turn on LED (specific color) digitalWrite(BLUE_PIN, HIGH); // turn on LED (specific color) delay(1000); // Wait for one second. } 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) } } void showRGB(int color) { // This command helps calculate the brightness for the LED's int red Intensity; // introduces red Intensity as a new variable. int greenIntensity; // introduces green Intensity as a new variable. int blue Intensity; // introduces blue Intensity as a new variable. 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 } analogWrite(RED_PIN, red Intensity);
Similar documents
View more...
Tags
Search Related
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks