Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define NO_OF_PINS 4
- #define MAX_BRIGHTNESS 255
- int ledArr[NO_OF_PINS] = {11,10,9,6};
- int brightnessArr[NO_OF_PINS] = {};
- int brightness = 0;
- int fade = 10;
- int i = 0;
- int flag = false;
- void setup() {
- //iterate over ledArr to initialse the led pins.
- int x = 0;
- while (x < NO_OF_PINS) {
- pinMode(ledArr[x], OUTPUT);
- brightnessArr[x] = brightness;
- x++;
- }
- }
- void loop() {
- //checks to see if we reverse the order or not
- int z = 0;
- while ( z < 4) {
- if ( brightnessArr[z] == MAX_BRIGHTNESS ) {
- flag == true;
- } else {
- flag == false;
- }
- z++;
- }
- //adds or subtracts brightness based on whether
- //or not we are going up or down the scale
- if ( flag == false ) {
- brightnessArr[i] += fade;
- } else if ( flag == true ) {
- brightnessArr[i] -= fade;
- }
- //first we increment brightness one pin at a time.
- if (brightnessArr[i] == MAX_BRIGHTNESS && flag == true) {
- i++;
- }else if(brightnessArr[i] == 0 && flag == false) {
- i--;
- }
- analogWrite(ledArr[i], brightnessArr[i]);
- delay(30);
- }
Advertisement
Add Comment
Please, Sign In to add comment