arduino_main.cpp 564 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-02-22 ChuShicheng first version
  9. */
  10. #include <Arduino.h>
  11. int led = 37; /* LED pin */
  12. int brightness = 0;
  13. int fadeAmount = 5;
  14. void setup()
  15. {
  16. /* Do not invoke pinMode for the PWM IO! */
  17. }
  18. void loop()
  19. {
  20. analogWrite(led, brightness);
  21. brightness = brightness + fadeAmount;
  22. if (brightness <= 0 || brightness >= 255)
  23. {
  24. fadeAmount = -fadeAmount;
  25. }
  26. delay(100);
  27. }