Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int brightness = 0;
- //these two variables are used to store our brightness level during manipulations
- int brightnessRev = 255;
- int fadeUp = 5;
- //the values by which each 'step' of the fade is incremented.
- int fadeDown = 5;
- int myPins[] = {3, 5, 6, 9, 10, 11};
- /*here we are storing our output pins in an array, that allows us to
- access the 'next' pin without hard-coding in the program itself
- if we wanted to change the pin assignments, we could do it once,
- right here, and everything else in the code would stay the same.*/
- void setup() {
- //our setup is very simple, we just need to configure each pin as an output
- pinMode(3, OUTPUT);
- pinMode(5, OUTPUT);
- pinMode(6, OUTPUT);
- pinMode(9, OUTPUT);
- pinMode(10, OUTPUT);
- pinMode(11, OUTPUT);
- }
- void loop() {
- /*this program basically just increments through each LED, slowly fading it up,
- then moving on to the next and doing the same, until all LEDs are on, then
- starting from the first LED, fades them down. Then the process is repeated in
- reverse, creating a sort of bouncing effect. */
- for(int i=0; i < 6; i++) {
- brightness = 0;
- while(brightness < 255){
- analogWrite(myPins[i], brightness);
- brightness += fadeUp;
- delay(1);
- }
- }
- //basically the goal here is to iterate a 'fade up' routine
- //on each output pin, which is what this for loop does
- for(int i=0; i <6; i++) {
- brightnessRev = 255;
- while(brightnessRev >= 0){
- analogWrite(myPins[i], brightnessRev);
- brightnessRev -= fadeDown;
- delay(1);
- }
- }
- //this for loop does the same thing,
- //but fading the LEDs down.
- delay(125);
- //this delay gives us a slight pause before
- //starting the reverse course
- for(int i=5; i >= 0; i--) {
- brightness = 0;
- while(brightness < 255){
- analogWrite(myPins[i], brightness);
- brightness += fadeUp;
- delay(1);
- }
- }
- for(int i=5; i >= 0; i--) {
- brightnessRev = 255;
- while(brightnessRev >= 0){
- analogWrite(myPins[i], brightnessRev);
- brightnessRev -= fadeDown;
- delay(1);
- }
- }
- delay(125);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement