_04_breathingLed.ino 1.0 KB

123456789101112131415161718192021222324252627282930
  1. /***********************************************************
  2. File name: 04_breathingLed.ino
  3. Description: PWM control the LED gradually from dark to
  4. brighter, then from brighter to dark
  5. Website: www.adeept.com
  6. E-mail: support@adeept.com
  7. Author: Tom
  8. Date: 2015/05/02
  9. ***********************************************************/
  10. int ledpin=11; //definition digital 11 pins as pin to control the LED
  11. void setup ()
  12. {
  13. pinMode(ledpin,OUTPUT); //Set digital 11 port mode, the OUTPUT for the output
  14. }
  15. void loop()
  16. {
  17. for (int a=0; a<=255;a++) //Loop, PWM control of LED brightness increase
  18. {
  19. analogWrite(ledpin,a); //PWM output value a (0~255)
  20. delay(15); //The duration of the current brightness level. 15ms
  21. }
  22. for (int a=255; a>=0;a--) //Loop, PWM control of LED brightness Reduced
  23. {
  24. analogWrite(ledpin,a); //PWM output value a (255~0)
  25. delay(15); //The duration of the current brightness level. 15ms
  26. }
  27. delay(100); //100ms delay
  28. }