tomasf1234

Something Awesome

Jun 8th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. #define NO_OF_PINS 4
  2. #define MAX_BRIGHTNESS 255
  3.  
  4. int ledArr[NO_OF_PINS] = {11,10,9,6};
  5. int brightnessArr[NO_OF_PINS] = {};
  6. int brightness = 0;
  7. int fade = 10;
  8. int i = 0;
  9. int flag = false;
  10.  
  11. void setup() {
  12.   //iterate over ledArr to initialse the led pins.
  13.   int x = 0;
  14.   while (x < NO_OF_PINS) {
  15.     pinMode(ledArr[x], OUTPUT);
  16.     brightnessArr[x] = brightness;
  17.     x++;
  18.   }
  19.  
  20. }
  21.  
  22. void loop() {
  23.  
  24.  
  25.   //checks to see if we reverse the order or not
  26.   int z = 0;
  27.   while ( z < 4) {
  28.     if ( brightnessArr[z] == MAX_BRIGHTNESS ) {
  29.       flag == true;
  30.     } else {
  31.       flag == false;
  32.     }
  33.     z++;
  34.   }
  35.  
  36.   //adds or subtracts brightness based on whether
  37.   //or not we are going up or down the scale
  38.   if ( flag == false ) {
  39.     brightnessArr[i] += fade;
  40.   } else if ( flag == true ) {
  41.     brightnessArr[i] -= fade;
  42.   }
  43.  
  44.  
  45.   //first we increment brightness one pin at a time.
  46.   if (brightnessArr[i] == MAX_BRIGHTNESS && flag == true) {
  47.     i++;
  48.   }else if(brightnessArr[i] == 0 && flag == false) {
  49.     i--;
  50.   }
  51.   analogWrite(ledArr[i], brightnessArr[i]);
  52.   delay(30);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment