/ Adafruit_LED_Sequins / Adafruit_LED_Sequins.ino
Adafruit_LED_Sequins.ino
 1  // SPDX-FileCopyrightText: 2018 Mikey Sklar for Adafruit Industries
 2  //
 3  // SPDX-License-Identifier: MIT
 4  
 5  int brightness = 0;    // how bright the LED is
 6  int fadeAmount = 5;    // how many points to fade the LED by
 7  int counter = 0;       // counter to keep track of cycles
 8  
 9  // the setup routine runs once when you press reset:
10  void setup()  { 
11    // declare pins to be an outputs:
12    pinMode(0, OUTPUT);
13    pinMode(2, OUTPUT);
14  } 
15  
16  // the loop routine runs over and over again forever:
17  void loop()  { 
18    // set the brightness of the analog-connected LEDs:
19    analogWrite(0, brightness);
20    
21    // change the brightness for next time through the loop:
22    brightness = brightness + fadeAmount;
23  
24    // reverse the direction of the fading at the ends of the fade: 
25    if (brightness == 0 || brightness == 255) {
26      fadeAmount = -fadeAmount; 
27      counter++;
28    }     
29    // wait for 15 milliseconds to see the dimming effect    
30    delay(15); 
31  
32  // turns on the other LEDs every four times through the fade by 
33  // checking the modulo of the counter.
34  // the modulo function gives you the remainder of 
35  // the division of two numbers:
36    if (counter % 4 == 0) {
37      digitalWrite(2, HIGH);
38    } else {
39     digitalWrite(2, LOW);
40    }  
41  }