Created
July 15, 2013 11:15
-
-
Save boxalljohn/5999227 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Example 1.2 | |
| int red = 11; // the pins for the LED | |
| int green = 9; | |
| int blue = 10; | |
| int i = 0; // for loops | |
| int j = 0; | |
| void setup() | |
| { | |
| pinMode(red, OUTPUT); // tell Arduino LED is an output | |
| pinMode(green, OUTPUT); | |
| pinMode(blue, OUTPUT); | |
| } | |
| void loop() | |
| { | |
| // first, cycle up each primary colour twice | |
| for (j = 1; j < 6; j++) | |
| { // loop 5 times | |
| for (i = 0; i < 255; i++) | |
| { // loop from 0 to 254 (fade in) | |
| analogWrite(red, i); // set the LED brightness | |
| delay(20); // Wait 10ms because analogWrite isn't instant | |
| } | |
| analogWrite(red,0); | |
| delay (20); | |
| for (i = 0; i < 255; i++) | |
| { // loop from 0 to 254 (fade in) | |
| analogWrite(green, i); // set the LED brightness | |
| delay(20); // Wait 10ms because analogWrite isn't instant | |
| } | |
| delay (20); | |
| analogWrite(green,0); | |
| for (i = 0; i < 255; i++) | |
| { // loop from 0 to 254 (fade in) | |
| analogWrite(blue, i); // set the LED brightness | |
| delay(20); // Wait 10ms because analogWrite isn't instant | |
| } | |
| delay (20); | |
| analogWrite(blue,0); | |
| } | |
| // psychadelic time | |
| for (j = 1; j < 10000; j++) | |
| { | |
| analogWrite(red,random(255)); // set red at random brightness between 0 and 254 | |
| delay (random(10,31)); // wait for a random duration between 10 and 30 milliseconds | |
| analogWrite(green,random(255)); | |
| delay (random(10,31)); | |
| analogWrite(blue,random(255)); | |
| delay (random(10,31)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment