Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /* blink assignment written by Matthew Borkowski on Septermber 17, 2019
  3.  *  Fading code inspired from the Arduino Fading Example by David A. Mellis
  4.  */
  5.  
  6. int ledPin = 9;
  7.  
  8. void setup() {
  9.   // put your setup code here, to run once:
  10.   pinMode(13, OUTPUT);
  11.   pinMode(12, OUTPUT);
  12. }
  13.  
  14. void loop() {
  15.   // put your main code here, to run repeatedly:
  16.   digitalWrite(13, HIGH); //turns the LEDs on
  17.   digitalWrite(12, HIGH);
  18.   delay(350);             // pauses for 350 ms
  19.   digitalWrite(13, LOW);
  20.   delay(200);            // pauses for 200 ms
  21.   digitalWrite(12, LOW);
  22.   delay(350);
  23.  
  24. // fades in from a minimum of 0 to a maximum of 200 by incriments of 2 points:
  25.   for (int fadeValue = 0; fadeValue <= 200; fadeValue += 2) {
  26.     // sets the value (range from 0 to 200)
  27.     analogWrite(ledPin, fadeValue);
  28.     // wait for 20 milliseconds to see the dimming effect
  29.     delay(20);
  30.   }
  31.   // fades from max of 200 to min of 0 by increments of 2 points
  32.   for (int fadeValue = 200; fadeValue >= 0; fadeValue -= 2) {
  33.     analogWrite(ledPin, fadeValue);
  34.     // wait for 20 milliseconds to see the dimming effect
  35.     delay(20);
  36.   }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement