pwm.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * pwm.c:
  3. * This tests the hardware PWM channel.
  4. *
  5. * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
  6. ***********************************************************************
  7. * This file is part of wiringPi:
  8. * https://projects.drogon.net/raspberry-pi/wiringpi/
  9. *
  10. * wiringPi is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Lesser General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * wiringPi is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
  22. ***********************************************************************
  23. */
  24. #include <wiringPi.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <stdint.h>
  28. int main (void)
  29. {
  30. int bright ;
  31. printf ("Raspberry Pi wiringPi PWM test program\n") ;
  32. if (wiringPiSetup () == -1)
  33. exit (1) ;
  34. pinMode (1, PWM_OUTPUT) ;
  35. for (;;)
  36. {
  37. for (bright = 0 ; bright < 1024 ; ++bright)
  38. {
  39. pwmWrite (1, bright) ;
  40. delay (1) ;
  41. }
  42. for (bright = 1023 ; bright >= 0 ; --bright)
  43. {
  44. pwmWrite (1, bright) ;
  45. delay (1) ;
  46. }
  47. }
  48. return 0 ;
  49. }